English C stack overflow

13 replies
Goto Page
To the start Previous 1 Next To the start
11.10.13 05:23:54 am
Up
pbeloto
User
Offline Off
Help me , remove the error "C stack overflow" , i shot the npc (id = 1) = "Zumbie" , there appears this error

Plz help, Thanks you


Script :

Code:
1
2
3
4
5
6
7
8
9
10
11
addhook("objectdamage","_objectdamage")
function _objectdamage(id_o,dmg,id_pl)
     if id_o > 0 then
          if object(id_o,"type") == 30 then
               if object(id_o,"player") == 1 then     
               parse("damageobject "..id_o.." 1 "..id_pl)
               return 1
               end
          end
     end
end
11.10.13 05:31:00 am
Up
KimKat
GAME BANNED
Offline Off
I believe it might be due to this part...
Code:
if id_o > 0 then -- = If <player ID> is greater than (>) zero perform following action.
That might include the NPC/dynamic object's ID perhaps causing a somewhat strange error. Because it might check for both yours and other types ID and perform action based on the ID's found. That's just my assumption I don't know if it's correct though.

Maybe it's also due to line 5, 6. That's the possible problems I can spot out anyhow.
11.10.13 05:53:24 am
Up
Starkkz
Moderator
Offline Off
@user KimKat: It isn't quite hard to discover the error.

Your hook is called when an object gets damaged, however on the sixth line you are using a command that damages objects. As you added that command on the hook, the game will start to call that function an infinite amount of times (Stack overflow) and it will not let the game continue processing correctly if you don't add conditionals for that.
lol
11.10.13 06:35:19 am
Up
MikuAuahDark
User
Offline Off
And also you can't check a NPC Type(like zombie,headcrab,etc.)

So, on line 6, that operation only return true if that object is spawned by player with ID 1.
Hello? Are you there, Tae Hanazono?
11.10.13 11:46:40 am
Up
DC
Admin
Offline Off
@user MikuAuahDark: This is not well documented but user pbeloto is actually doing it right. For NPCs the "player" field is used to store the subtype of the NPCs. This field is used for the subtype by the game because NPCs don't belong to players like buildings. So that part of the code is correct.

The overflow is caused by an infinite loop like user Starkkz already explained. Calling a function in a hook which triggers the same hook again is always critical. Make sure to add proper conditions in such cases to avoid infinite loops.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
11.10.13 01:01:37 pm
Up
KimKat
GAME BANNED
Offline Off
It's kind of recursion due to the parsing of cs2d cmd damageobject which is interconnected to the hooked function _objectdamage (cs2d lua hook objectdamage). To fix this would be to revise line 6 in a way, so that it doesn't happen. But I currently have no solution since I personally have never really touched that hook.

As a on the fly solution try by not hooking the function and simply calling it when needed and with proper parameters. In theory it might work much better for you. Also thanks to everyone for clarifying this.
11.10.13 02:06:27 pm
Up
Infinite Rain
Reviewer
Offline Off
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
allowPass = true
addhook("objectdamage","_objectdamage")
function _objectdamage(id_o,dmg,id_pl)
     if allowPass then
          if id_o > 0 then
               if object(id_o,"type") == 30 then
                    if object(id_o,"player") == 1 then     
                         allowPass = false
                         parse("damageobject "..id_o.." 1 "..id_pl)
                         allowPass = true
                         return 1
                    end
               end
          end
     end
end


Should work now, I used the most basic method.
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
11.10.13 02:39:52 pm
Up
Starkkz
Moderator
Offline Off
@user Infinite Rain: It's useful, but I'd temporally disable the hook using cs2d lua cmd sethookstate, it won't be necessary to create a variable for that. Both methods are fine anyway.
lol
11.10.13 03:04:55 pm
Up
Infinite Rain
Reviewer
Offline Off
@user Starkkz:
Wow, I didn't even know that this command has ever existed.
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
11.10.13 05:45:35 pm
Up
pbeloto
User
Offline Off
and if I call this command only once in the game?

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
npc_force = true

addhook("objectdamage","_objectdamage")
function _objectdamage(id_o,dmg,id_pl)
     if npc_force ==  true then
          if id_o > 0 then
               if object(id_o,"type") == 30 then
                    if object(id_o,"player") == 1 then     
                         parse("damageobject "..id_o.." 1 "..id_pl)
                         npc_force == false
                    return 1
                    end
               end
          end
     end
end


Error: active and desactive for command '-' , 1 shot = cmd 1 , 2 shot = shot weapon
edited 1×, last 11.10.13 05:54:20 pm
11.10.13 05:47:59 pm
Up
Infinite Rain
Reviewer
Offline Off
Use my script, your version is wrong. My version will work perfectly.
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
11.10.13 05:57:21 pm
Up
pbeloto
User
Offline Off
user Infinite Rain has written:
Use my script, your version is wrong. My version will work perfectly.



OMG , thanks ... , go test script me server ??

Name : Rp server (BETA)
IP :189.54.117.71:36963

passworld : 157 or none passworld

'-'
11.10.13 07:06:22 pm
Up
Infinite Rain
Reviewer
Offline Off
@user pbeloto:
No, sorry, I have no time.
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
12.10.13 02:14:09 am
Up
omg
User
Offline Off
im not sure what else u implemented but the simplest solution would be to put parse("damageobject "..id_o.." 1 0") or something similar
will code for food
To the start Previous 1 Next To the start