how should i use Destroy object here?
#1

hello guys, i've made a Bomb script, which when a player types /bomb, it puts the bomb(with object ID 1252) on the ground, then 5 secs after (with SetTimerEx) destroy it. so i use an other callback for the bomb to explode, and destroy the object... But it doesn't work :S

with what should i replace objectid in :
DestroyObject(objectid)

in the Custom Callback?

here's some of my code:
Код:
//somewhere in OnPlayerCommandText:
	if(strcmp(cmdtext, "/bomb", true) == 0)
	{
                //my stuff
	SetTimerEx("BombDetonate",5000,false,"",0,"");
               CreateObject(1252,X,Y,Z,14.283400,0.0,0.0,100.0);
               return 1;
	}
Код:
//my custom callback
public BombDetonate(playerid)
{
             //my stuff
	DestroyObject(objectid);

}
thanks for help
Reply
#2

Anywhere before the two functions:
pawn Код:
new BombObjectID;
and inside the /bomb command:
pawn Код:
BombObjectID = CreateObject(1252,X,Y,Z,14.283400,0.0,0.0,100.0);
And in BombDetonate(playerid):
pawn Код:
DeleteObject(BombObjectID);
Edit:
Just remember that this will only work with one bomb at a time, if you want to be able to use more you need to use an array or PVar to store the BombObjectID value in.
Reply
#3

Use a variable to store the objectid when creating the object.
Reply
#4

This method would be better:
pawn Код:
if(strcmp(cmdtext, "/bomb", true) == 0)
{
   // Some stuff
   new object = CreateObject(...);
   SetTimerEx("BombDetonate", 5000, false, "ii", playerid, object);
   return 1;
}

public BombDetonate(playerid, object)
{
   // Your stuff
   CreateExplosion(...); // X Y  Z of the bomb's location
   DestroyObject(object);
}
Also your current SetTimerEx functions is incorrectly formatted.
Reply
#5

Nvm everyone just beat me to posting, 2nd time today
Reply
#6

i can send you my fire works script it simmilar you jut got to change it to 1 bomb
Reply
#7

Quote:
Originally Posted by Grim_
Посмотреть сообщение
This method would be better:
pawn Код:
if(strcmp(cmdtext, "/bomb", true) == 0)
{
   // Some stuff
   new object = CreateObject(...);
   SetTimerEx("BombDetonate", 5000, false, "ii", playerid, object);
   return 1;
}

public BombDetonate(playerid, object)
{
   // Your stuff
   CreateExplosion(...); // X Y  Z of the bomb's location
   DestroyObject(object);
}
Also your current SetTimerEx functions is incorrectly formatted.
yea i've tried new object = CreateObject(...);

but it says when i compile that the thing is never used...

and i don't know how i could use it, because if i only do CreateObject it won't store in a variable, so i will not be able to delete it after?

and then in my callback it says undefined symbol "object"

i should have precised this in my first post but nvm xD so anyone knows?
Reply
#8

You need to use the code I gave you for it to work correctly (Editing the callback arguments, adjusting the SetTimerEx line, etc)
Reply
#9

No, the problem is that you create the variable inside the function - it has to be available for the timer too, meaning it needs to be global - look at my post.

Also, the SA-MP timers are inefficient, read my post here
Reply
#10

no nvm, Lenny the cop got it right, it just worked. It is just frustrating to know it was that simple -_- thanks lenny :P
Reply
#11

No, it doesn't need to be global because you only use it inside that command (using it with the SetTimerEx function). And if you re-evaluate my code, you will see the argument of the new callback is "object", which is why I use it in that callback as well.
Reply
#12

All solutions are simple and frustrating xD Glad I could help

Edit: Grim_ is right, his solution is more efficient

But I still think you shouldn't use SAMP timers.
Reply
#13

yea i just saw that it works in his way, and it is better :P thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)