Forum

> > CS2D > Scripts > When kill has error[Solved]
Forums overviewCS2D overview Scripts overviewLog in to reply

English When kill has error[Solved]

2 replies
To the start Previous 1 Next To the start

old When kill has error[Solved]

Mora
User Off Offline

Quote
Hi all, here is my code and it's work, but when do i kill someone with any weapon, i got error:
1
LUA ERROR: attempt to call a nil value
The code is
1
2
3
4
5
6
7
8
9
10
11
12
function at_kill(id)
local wwp = player(id,"weapontype")
				for _,id in pairs (player(0, "table")) do
	if wwp==4 then
glockZ[id] = glockZ[id] >= 5 and 5 or glockZ[id] + 1
if glockZ[id] > 5 then glockZ[id] = 5 end
	elseif wwp==2 then
uspZ[id] = uspZ[id] >= 10 and 10 or uspZ[id] + 1
if uspZ[id] > 10 then uspZ[id] = 10 end
	end
				end
end
Also, i tried so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function at_kill(id)
local wwp = player(id,"weapontype")
	if wwp==4 then
			for _,id in pairs (player(0, "table")) do
glockZ[id] = glockZ[id] >= 5 and 5 or glockZ[id] + 1
if glockZ[id] > 5 then glockZ[id] = 5 end
			end
	elseif wwp==2 then
			for _,id in pairs (player(0, "table")) do
uspZ[id] = uspZ[id] >= 10 and 10 or uspZ[id] + 1
if uspZ[id] > 10 then uspZ[id] = 10 end
			end
	end
end
All things with that code is working, just i don't need that s**t error message -.- and don't know why it happened.
Thank you so much :3, helpers
edited 1×, last 10.12.14 05:04:49 am

old Re: When kill has error[Solved]

Rainoth
Moderator Off Offline

Quote
I don't see anything particularly screwed up apart from tabbing. Also your conditional is a bit weird because you're checking if a variable is "greater or equal" and then set it to X. If say in one case, X was 5 and you used that conditional, you'd be setting it up needlessly so I'd change it to be only "greater". Not a big mistake but that's the only thing I noticed.

Your error is usually given when a function is called but it doesn't exist. Make sure you don't call a nonexistent function in your code and/or have any hooks with nonexistent functions attached.

old Re: When kill has error[Solved]

Mora
User Off Offline

Quote
@user Rainoth: ok, thanks, i'll try.
/thank you @user Rainoth: , you're good guy, you do always help me <3.
Wich i got error:
needless(empty hook) exp_kill.
1
2
3
4
5
6
7
8
addhook ("join", "val_join")
addhook ("leave", "val_leave")
addhook("kill","exp_kill")
addhook("serveraction","vizov_menu")
addhook("say","premium_say")
addhook("menu","at_menu")
addhook("kill","at_kill")
addhook("walkover","at_walkover")
edited 1×, last 10.12.14 05:01:09 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview