DestroyObject doesn't work when attached to vehicle?
#1

Hi all,

I think i found a bug.
I have tried to destroy an attachedvehicle object but it doesn't work.
Example:
pawn Код:
if(!strcmp(cmdtext, "/test", true))
    {  
        new objectid;
        new vehicleid;
        vehicleid=GetPlayerVehicleID(playerid);
        if(Variable == 0)
        {
            AttachObjectToVehicle(objectid,vehicleid, -0.034999, 1.749998, 0.329999, 0.000000, 0.000000, 0.000000); //Object Model: 18646 |
            Variable = 1;
            return 1;
        }
        else if(Variable == 1)
        {
            DestroyObject(objectid);
            Variable = 0;
            return 1;
        }
        return 1;
    }
Is this a bug or my code is wrong?

Admigo
Reply
#2

Your code is wrong.
I just did a test and successfully deleted an object attached to a vehicle. So the function is working as it should.
Reply
#3

You are never creating the object, so it's using object ID 0.
Reply
#4

The right code would be:
pawn Код:
new objectid;//outside the command

if(!strcmp(cmdtext, "/test", true))
    {  
       
        new vehicleid;
        vehicleid=GetPlayerVehicleID(playerid);
        if(Variable == 0)
        {
            objectid = CreateObject(18646,0,0,0,0,0,0);
            AttachObjectToVehicle(objectid ,vehicleid, -0.034999, 1.749998, 0.329999, 0.000000, 0.000000, 0.000000); //Object Model: 18646 |
            Variable = 1;
            return 1;
        }
        else if(Variable == 1)
        {
            DestroyObject(objectid);
            Variable = 0;
            return 1;
        }
        return 1;
    }
This should work the way it's supposed to work..
EDIT: edited the code with RealCop's change and edited with FufLa's change, now it should work
Reply
#5

Quote:
Originally Posted by Jari_Johnson*
Посмотреть сообщение
The right code would be:
pawn Код:
if(!strcmp(cmdtext, "/test", true))
    {  
        new objectid;
        new vehicleid;
        vehicleid=GetPlayerVehicleID(playerid);
        if(Variable == 0)
        {
            objectid = AttachObjectToVehicle(18646 ,vehicleid, -0.034999, 1.749998, 0.329999, 0.000000, 0.000000, 0.000000); //Object Model: 18646 |
            Variable = 1;
            return 1;
        }
        else if(Variable == 1)
        {
            DestroyObject(objectid);
            Variable = 0;
            return 1;
        }
        return 1;
    }
This should work the way it's supposed to work..
No. You're still not creating the object in this code. "objectid" is going to equal 0 here. You need to do something like this:

pawn Код:
new objectid = CreateObject(model, 0, 0, 0, 0, 0, 0);
AttachObjectToVehicle(objectid, ...);
Reply
#6

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
No. You're still not creating the object in this code. "objectid" is going to equal 0 here. You need to do something like this:

pawn Код:
new objectid = CreateObject(model, 0, 0, 0, 0, 0, 0);
AttachObjectToVehicle(objectid, ...);
Ups, my bad, sorry!
I will edit it in my post, thanks RealCop
Reply
#7

The code is still wrong, the variable objectid will be 0 again when you do /test for the second time since you use local variables.
Reply
#8

Quote:
Originally Posted by FufLa
Посмотреть сообщение
The code is still wrong, the variable objectid will be 0 again when you do /test for the second time since you use local variables.
Yes, of course. You will need to store the object's ID into a global variable.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)