Forum

> > CS2D > Scripts > 2 nil value errors
Forums overviewCS2D overview Scripts overviewLog in to reply

English 2 nil value errors

13 replies
To the start Previous 1 Next To the start

old 2 nil value errors

Mami Tomoe
User Off Offline

Quote
hello, i have a few scripts that im trying to repair in order to setup a server without any crashes

here's my problems:
script-1
Spoiler >

script-2
Spoiler >

old Re: 2 nil value errors

Dousea
User Off Offline

Quote
In script 1, I'm guessing cs_exp[vid] is the nil value. It's because you didn't define its value or vid must be 0 or more than 32. In script 2, I can't really tell but since you already defined sd.damage from index 1 to 32 with initArray function, src must be 0 or more than 32.

old Re: 2 nil value errors

Mami Tomoe
User Off Offline

Quote
i cant understand because my lua skills are quite low (very low, super very very very low)

can you suggest me how to fix it?

old Re: 2 nil value errors

Dousea
User Off Offline

Quote
These codes may fix your problem.

Script 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
addhook("die", "dieded")

function dieded(id, vid, wep, x, y)
	-- Changed nil values with 0 since CS2D doesn't send nil values
	if vid ~= 0 and id ~= 0 and id ~= vid then
		cs_exp[vid]=cs_exp[vid]-10
		cs_exp[id]=cs_exp[id]+5
--		msg(player(id, "name").." killed "..player(vid, "name").."!")
		msg2(vid,"\169255255000[Server]: \169255000000You got killed by "..player(id, "name").." and lost 10 EXP + 1000$!")
		msg2(id,"\169255255000[Server]: \169000255000You killed "..player(vid, "name").." and gained 5 EXP + 500$!")
		rp_killer[id]=true
		rp_money[id]=rp_money[id]+200
		updatehud(id)
		
		if rp_money[vid]>=1000 then
			rp_money[vid]=rp_money[vid]-1000
			updatehud(vid)
		end
		if rp_criminal[id]==true then
			rp_money[id]=rp_money[id]+2000
			cs_exp[id]=cs_exp[id]+5
			msg2(id,"\169255255000[Server]: \169000255000Criminal bonus 2000$ and 10 EXP!")
		end
		if rp_criminal[vid]==true and rp_police[id]== true then
			rp_money[id]=rp_money[id]+5000
			cs_exp[id]=cs_exp[id]+20
			msg2(id,"\169255255000[Server]: \169000255000You've killed a criminal, you won 5000$ and 20 EXP!")
		end
		if rp_criminal[vid]==true then
			cs_exp[vid]=cs_exp[vid]-40
			msg2(vid,"\169255255000[Server]: \169255000000You've been killed and lost 10,000$ and 40 EXP!")
			if rp_money[vid]>=10000 then
				rp_money[vid]=rp_money[vid]-10000
				updatehud(vid)
			end
		end
	end
end

Script 2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
--------------------------------------------
-- Show Damage Script by FastLine Advance
--------------------------------------------

sd = {}

function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]=0
	end
	return array
end

sd.damage = initArray(32)
sd.showtimer = initArray(32)

addhook('hit','sd.hit')
function sd.hit(id,src,wpn,hp)
	-- Checks if src is not 0
	if src ~= 0 and hp > 0 then
		sd.damage[src] = sd.damage[src] + hp
		sd.show(src)
		sd.showtimer[src] = 10
	end
end

function sd.show(id)
	parse('hudtxt2 '..id..' 0 "©255255255-'..sd.damage[id]..' HP" 300 200 -1')
end

addhook('ms100','sd.check')
function sd.check()
	for i = 1,32 do
		if player(i,'exists') then
			if sd.showtimer[i] > 0 then
				sd.showtimer[i] = sd.showtimer[i] - 1
			else
				sd.damage[i] = 0
				parse('hudtxt2 '..i..' 0 "" 320 240 0')
			end
		end
	end
end

old Re: 2 nil value errors

Mami Tomoe
User Off Offline

Quote
aaa new error xd pls help, i tried to add if usgn is bigger than 0 but it didnt work

error:
1
2
3
4
LUA ERROR: sys/lua/autorun/exp.lua:33: attempt to concatenate local 'UsgnID' (a boolean value)
 -> sys/lua/autorun/exp.lua:33: in function 'SaveUser'
 -> sys/lua/autorun/exp.lua:93: in function <sys/lua/autorun/exp.lua:91>
 -> in Lua hook 'leave', params: 1, 4

script:
the function below is on line 30

1
2
3
4
5
6
7
8
9
10
11
function SaveUser(id,UsgnID)
	for id = 1,32 do
     local UsgnID = player(id,"usgn")
     file = io.open("sys/lua/save/"..UsgnID..".txt","w") or io.tmpfile()
     local text = ""
     text = tostring(cs_exp[id])
     text = text.." "..cs_level[id]
     file:write(text)
     file:close()
	 end
end

pls
edited 1×, last 27.12.15 01:39:21 pm

old Re: 2 nil value errors

Cure Pikachu
User Off Offline

Quote
@user Mami Tomoe: Give this a try.
1
2
3
4
5
6
7
8
9
10
function SaveUser(id)
	if player(id,"usgn") > 0 then
		file = io.open("sys/lua/save/"..player(id,"usgn")..".txt","w") or io.tmpfile()
		local text = ""
		text = tostring(cs_exp[id])
		text = text.." "..cs_level[id]
		file:write(text)
		file:close()
	end
end

old Re: 2 nil value errors

Mami Tomoe
User Off Offline

Quote
@user Cure Pikachu:
when someone leave:

1
2
3
4
LUA ERROR: sys/lua/autorun/exp.lua:32: attempt to compare number with boolean
 -> sys/lua/autorun/exp.lua:32: in function 'SaveUser'
 -> sys/lua/autorun/exp.lua:94: in function <sys/lua/autorun/exp.lua:92>
 -> in Lua hook 'leave', params: 1, 4

the whole script:
http://pastebin.com/3zK2Piht

old Re: 2 nil value errors

GeoB99
Moderator Off Offline

Quote
Replace "> 0" part with this below. Should work.
1
if player(id,"usgn") == true then

old Re: 2 nil value errors

Dousea
User Off Offline

Quote
Value of "usgn" in cs2d lua cmd player is not U.S.G.N. ID anymore? Maybe a bug, or you replace it with yours. Well if you use user GeoB99's code there will be another error because player(id, "usgn") returns boolean value and you can't concatenate a boolean value while in user Cure Pikachu's code at line 3, it's attempting to concatenate a boolean value.

old Re: 2 nil value errors

Mami Tomoe
User Off Offline

Quote
user GeoB99 has written
Replace "> 0" part with this below. Should work.
1
if player(id,"usgn") == true then


iz work

why usgn is balloon thingy and not a number

old Re: 2 nil value errors

EngiN33R
Moderator Off Offline

Quote
The usgn property of a player should be a number in all cases except when a player doesn't exist, in which case it returns false. Fixing it to user GeoB99's suggestion is just duct tape on a sinking ship - it might not return errors that way, but it will likely result in unexpected behaviour.

Your problem is that even though you supply an id parameter to the SaveUser function, you still have a for id = 1, 32 do loop surrounding your actual saving code. Get rid of it and it should work all right.

In all honestly, the whole script could do with a rework, with lines of code like if player == exist then.

old Re: 2 nil value errors

Mami Tomoe
User Off Offline

Quote
yeah that exp script suck, couldn't find any better script all over unreal-software
and what i did found didn't fit or i couldn't make it fit for my server...
also with this script i have a error that will erase everyone's data
just delete all of it and when u join u start from 0

oh well i might solve it one day

(#not hinting i need help or something because i'm shy and don't want to ask for too much pls no kill )
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview