how should i use Destroy object here? -
pmk1 - 07.10.2010
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
Re: how should i use Destroy object here? -
Lenny the Cup - 07.10.2010
Anywhere before the two functions:
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.
Re: how should i use Destroy object here? -
Retardedwolf - 07.10.2010
Use a variable to store the objectid when creating the object.
Re: how should i use Destroy object here? -
Grim_ - 07.10.2010
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.
Re: how should i use Destroy object here? -
Steven82 - 07.10.2010
Nvm everyone just beat me to posting, 2nd time today
Re: how should i use Destroy object here? -
Tommie1331 - 07.10.2010
i can send you my fire works script it simmilar you jut got to change it to 1 bomb
Re: how should i use Destroy object here? -
pmk1 - 07.10.2010
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?
Re: how should i use Destroy object here? -
Grim_ - 07.10.2010
You need to use the code I gave you for it to work correctly (Editing the callback arguments, adjusting the SetTimerEx line, etc)
Re: how should i use Destroy object here? -
Lenny the Cup - 07.10.2010
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
Re: how should i use Destroy object here? -
pmk1 - 07.10.2010
no nvm, Lenny the cop got it right, it just worked. It is just frustrating to know it was that simple -_- thanks lenny :P
Re: how should i use Destroy object here? -
Grim_ - 07.10.2010
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.
Re: how should i use Destroy object here? -
Lenny the Cup - 07.10.2010
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.
Re: how should i use Destroy object here? -
pmk1 - 09.10.2010
yea i just saw that it works in his way, and it is better :P thanks