English Hit hook error

7 replies
Goto Page
To the start Previous 1 Next To the start
23.09.19 12:19:09 pm
Up
Quattro
User
Offline Off
Code:
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
23.09.19 12:37:37 pm
Up
Joni And Friends
User
Offline Off
Try this
Code:
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
Web | file File does not exist (15501) | file File does not exist (15463) | file cs2d [JAF] Adventure (19) | file File does not exist (15919)
23.09.19 01:49:32 pm
Up
Quattro
User
Offline Off
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
23.09.19 02:24:14 pm
Up
Grand Master
User
Offline Off
user Quattro: If sometimes it happens, then somewhere you changed damage variable to nil.

Code:
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
23.09.19 04:26:33 pm
Up
Quattro
User
Offline Off
@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
24.09.19 04:51:23 am
Up
Joni And Friends
User
Offline Off
Try this
Code:
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
Web | file File does not exist (15501) | file File does not exist (15463) | file cs2d [JAF] Adventure (19) | file File does not exist (15919)
24.09.19 09:13:15 pm
Up
DC
Admin
Offline Off
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.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
24.09.19 11:45:30 pm
Up
Quattro
User
Offline Off
Thanks!
To the start Previous 1 Next To the start