Destroy Object
#1

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?
Reply
#2

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.
Reply
#3

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?
Reply
#4

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 ?
Reply
#5

It's because you only have one variable for more than one object.
Reply
#6

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.
Reply
#7

If you want to delete the object you've created for all players, use a for

PHP код:
for(new 0MAX_PLAYERSp++)
{
    
DestroyObject(trap[p]);
    if(!
IsValidObject(trap[p])) return print("All traps destroyed !");
    else return 
DestroyObject(trap[p]);

Reply
#8

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?
Reply
#9

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(modelxyz0.00.00.0);
object CreateObject(othermodelxyz0.00.00.0);
DestroyObject(object); // Will destroy the "othermodel", not "model". 
Reply
#10

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?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)