Destroy Object -
Blackazur - 22.02.2014
Hello, i have a command to add a object before my feet, that works, i have made then a command to destroy this object with
Код:
DestroyObject(trap[playerid]);
The Object is so defined:
Код:
new trap[MAX_PLAYERS];
but it won't destroy if i use the add object command 2 or 3 times, then the other 2 objects from this object won't destroy. Can you say me why?
Re : Destroy Object -
S4t3K - 22.02.2014
When you create your object, do you do like that ?
PHP код:
trap[playerid] = CreateObject();
// OR
trap[playerid] = SetPlayerAttachedObject();
And if, add these lines below the object creating
PHP код:
if(IsValidObject(trap[playerid]))
{
print("Trap object successfuly created");
}
Also add these lines below the object destroy
PHP код:
if(!IsValidObject(trap[playerid]))
{
print("Trap object successfuly destroyed !");
}
If the strings print in the console, it means that this is a display bug, not a scripting bug.
AW: Destroy Object -
Blackazur - 22.02.2014
Like that:
Код:
trap[playerid] = CreateObject
If i add this object before my feet it works if i destroy it but if i add this object 2 times before my feet the 2 object won't destroy. Can you help me with that?
Re : Destroy Object -
S4t3K - 22.02.2014
I don't really understand.
You want to place your object at your feet. But when you create the object twice before your feet ?
What do you mean by twice ?
Re: Destroy Object -
BigGroter - 22.02.2014
It's because you only have one variable for more than one object.
AW: Destroy Object -
Blackazur - 22.02.2014
And how can i change it? If i create the object twice before my feet and i try to delete it with the command for deleting the object, it only delete the 1 object not the object that i created twice. But i want that it delete all the objects that i created.
Re : Destroy Object -
S4t3K - 22.02.2014
If you want to delete the object you've created for all players, use a for
PHP код:
for(new p = 0; p < MAX_PLAYERS; p++)
{
DestroyObject(trap[p]);
if(!IsValidObject(trap[p])) return print("All traps destroyed !");
else return DestroyObject(trap[p]);
}
Re: AW: Destroy Object -
Vince - 22.02.2014
Quote:
Originally Posted by Blackazur
And how can i change it? If i create the object twice before my feet and i try to delete it with the command for deleting the object, it only delete the 1 object not the object that i created twice. But i want that it delete all the objects that i created.
|
What you're doing is similar to this:
pawn Код:
new a;
a = 1;
a = 2;
a = 3;
printf("a = %d", a); // prints: "a = 3";
You're overwriting the variable. I hope you understand that?
Re : Destroy Object -
S4t3K - 22.02.2014
I think BigGroter has made him understand it over his explaination ^^
If you want to create an object linked to a var, you need to create a var for each object. Either, if you use the same var twice for two objects differents, the var will be linked to the last object created. The first one won't be destroyable through DestroyObject(objectid);
To take an example
PHP код:
new object;
object = CreateObject(model, x, y, z, 0.0, 0.0, 0.0);
object = CreateObject(othermodel, x, y, z, 0.0, 0.0, 0.0);
DestroyObject(object); // Will destroy the "othermodel", not "model".
AW: Re: AW: Destroy Object -
Blackazur - 22.02.2014
Quote:
Originally Posted by Vince
What you're doing is similar to this:
pawn Код:
new a;
a = 1; a = 2; a = 3;
printf("a = %d", a); // prints: "a = 3";
You're overwriting the variable. I hope you understand that?
|
And how can i change it that it deletes all this objects if i used this command twice?