Forum

> > CS2D > Scripts > C stack overflow
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch C stack overflow

13 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt C stack overflow

pbeloto
User Off Offline

Zitieren
Help me , remove the error "C stack overflow" , i shot the npc (id = 1) = "Zumbie" , there appears this error

Plz help, Thanks you


Script :

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

alt Re: C stack overflow

KimKat
GAME BANNED Off Offline

Zitieren
I believe it might be due to this part...
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.

alt Re: C stack overflow

Starkkz
Moderator Off Offline

Zitieren
@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.

alt Re: C stack overflow

MikuAuahDark
User Off Offline

Zitieren
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.

alt Re: C stack overflow

DC
Admin Off Offline

Zitieren
@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.

alt Re: C stack overflow

KimKat
GAME BANNED Off Offline

Zitieren
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.

alt Re: C stack overflow

Infinite Rain
Reviewer Off Offline

Zitieren
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.

alt Re: C stack overflow

pbeloto
User Off Offline

Zitieren
and if I call this command only once in the game?

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
1× editiert, zuletzt 11.10.13 17:54:20

alt Re: C stack overflow

pbeloto
User Off Offline

Zitieren
user Infinite Rain hat geschrieben
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

'-'

alt Re: C stack overflow

omg
User Off Offline

Zitieren
im not sure what else u implemented but the simplest solution would be to put parse("damageobject "..id_o.." 1 0") or something similar
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht