Forum

> > CS2D > Scripts > Hit hook error
Forums overviewCS2D overview Scripts overviewLog in to reply

English Hit hook error

7 replies
To the start Previous 1 Next To the start

old Hit hook error

Quattro
GAME BANNED Off Offline

Quote
1
2
3
4
5
6
function hit(victim_id, attacker_id, weapon, hpdmg)
	if player(attacker_id, 'team') == player(victim_id, 'team') then
		return 1
	end
	damage[attacker_id][victim_id] = damage[attacker_id][victim_id] + hpdmg
end

Sometimes this happens, how to fix?

[18:40:21] LUA ERROR: sys/lua/server.lua:4531: attempt to index field '?' (a nil value)
[18:40:21] -> sys/lua/server.lua:4531: in function <sys/lua/server.lua:4527>
[18:40:21] -> in Lua hook 'hit', params: 8, 0, 0, 78, 0, 127, 0

[18:47:40] LUA ERROR: sys/lua/server.lua:4531: attempt to index field '?' (a nil value)
[18:47:40] -> sys/lua/server.lua:4531: in function <sys/lua/server.lua:4527>
[18:47:40] -> in Lua hook 'hit', params: 8, 0, 0, 80, 0, 80, 0

[18:58:08] LUA ERROR: sys/lua/server.lua:4531: attempt to index field '?' (a nil value)
[18:58:08] -> sys/lua/server.lua:4531: in function <sys/lua/server.lua:4527>
[18:58:08] -> in Lua hook 'hit', params: 4, 0, 0, 100, 100, 323, 0

old Re: Hit hook error

Joni And Friends
User Off Offline

Quote
Try this
1
2
3
4
5
6
7
8
function hit(victim_id, attacker_id, weapon, hpdmg)
	if victim_id~=nil and victim_id>0 and attacker_id~=nil and attacker_id>0 then
		if player(attacker_id, 'team') == player(victim_id, 'team') then
			return 1
		end
		damage[attacker_id][victim_id] = damage[attacker_id][victim_id] + hpdmg
	end
end

old Re: Hit hook error

Quattro
GAME BANNED Off Offline

Quote
So your guess is that each time this error pops up, a player gets hit by an HE that was thrown by a player who left the game in that second?

edit:
the error is marked on this line:
damage[attacker_id][victim_id] = damage[attacker_id][victim_id] + hpdmg

So it means hithook can throw a nil for id or damage dealt

old Re: Hit hook error

Grand Master
User Off Offline

Quote
user Quattro: If sometimes it happens, then somewhere you changed damage variable to nil.

1
2
3
4
5
6
7
function hit(victim_id, attacker_id, weapon, hpdmg)
     if victim_id==nil or attacker_id==nil then return print("Attacker Id or victim Id is nil") end
          if player(attacker_id, 'team') == player(victim_id, 'team') then
               return 1
          end
    damage[attacker_id][victim_id] = damage[attacker_id][victim_id] + hpdmg
end
edited 4×, last 23.09.19 02:59:05 pm

old Re: Hit hook error

Quattro
GAME BANNED Off Offline

Quote
@user Grand Master:

That was the first thing I checked just in case (it is not the case).

I think the nil is hpdmg from hit hook.

Btw I like your idea about catching this error, I'll try it and figure out which one is the nil

old Re: Hit hook error

Joni And Friends
User Off Offline

Quote
Try this
1
2
3
4
5
6
7
8
9
10
function hit(victim_id, attacker_id, weapon, hpdmg)
     if victim_id~=nil and victim_id>0 and attacker_id~=nil and attacker_id>0 then
          if player(attacker_id, 'team') == player(victim_id, 'team') then
               return 1
          end
		if damage[attacker_id]~=nil and damage[attacker_id][victim_id]~=nil then
          		damage[attacker_id][victim_id] = damage[attacker_id][victim_id] + hpdmg
		end
     end
end
You know, the turret damage also triggered this cs2d lua hook hit and turret has no id or 0

old Re: Hit hook error

DC
Admin Off Offline

Quote
Yep, like the cs2d lua hook hit documentation says, the player id can be 0 as well. E.g. when the player left (in case of delayed damage via a projectile) or when the damage was caused by an NPC or building.

Assuming that it always contains a valid player ID is wrong. You have to check the value before using it.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview