Help with an script!

// NPC made by unknown if (compus[i].mode == 5) { lay2 goldrupee,compus[i].x,compus[i].y; } timeout = 0.05;

Its abit buggy how do i make it so, that it drop only 1 goldrupee?
timeout = 1.5; is abit buggy…

Don’t loop

Having the timeout outside of a conditional statement means it’s setting the timeout value any time ANY event occurs. There is no event for a single baddy dying, but there is for all baddies being dead. Your only option would be to keep a timeout going from the point the player enters the level and constantly check to see if that particular baddy has died yet.

Also… “AN script”… ugh.

That’s not obvious, because the compus are dynamic.
The i from previous timeout might very well not be the same.
That said, with hours of hard thinking and experimenting, here is my solution:

// NPC modified by Zartox // NPC modified by Zartox if (playerenters){ timeout=1; oldcompuscount=compuscount; this.dying=0; } if (timeout) { if (compuscount<=(oldcompuscount-this.dying)){ dying=0; for (i=0; i<compuscount; i++){ if (compus[i].mode==5){ lay2 goldrupee,compus[i].x,compus[i].y; this.dying++; } } } timeout=0.05; } It does feel like my first script by the way.
So, it can be summarize as: If all baddies that were dying have finished to die, you can then give rupees again when baddies are dying. It seems like non perfect logic, so don’t expect perfect results.

Strangely for me, if I was setting the timeout under 1, like 0.5 or 0.05, it was not looping anymore. Eh… maybe thats’s because under Windows 10, I use the editor in Graal_222.exe because Graal_editor.exe does not launched. Need to verify.

Edit1: Previous code was not really working because dying was a local variable, rather than a “flag”?. I changed “dying” to “this.dying” and now it seems to really works much better. Well, I don’t really understand. npcprogramming.doc suggest that “this” variables, are different because they are local to the current NPC rather than shared with all NPCs. So I would expect normal (non this) variables to survive multiple invocations of the scripts for the timeout event.

Edit2: Ok. I think I begin to get it. If the variable is name, it is local and will not survive after a script invocation (on an event like timeout). If it is this.name, it will be local, but survive after a script invocation. If it is client.name then it is a player stored flag, that will be shared amongs NPC, and even survive after closing the client. If it is server.name it will be stored on the server (so will be available to others players even after you log out), shared with all the NPCs, and survive until the server is reset.

Edit3: It’s strange that it seems to work… because oldcompuscount=compuscount; is done in if (playerenters) so I would thought that it is done only once. Also this is not this.oldcompuscount. So I would expect that it should be destroyed after any invocation of the script.