DestroyObject doesn't work when attached to vehicle? -
Admigo - 17.02.2013
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
Re: DestroyObject doesn't work when attached to vehicle? -
1dllb - 26.02.2013
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.
Re: DestroyObject doesn't work when attached to vehicle? -
SuperViper - 26.02.2013
You are never creating the object, so it's using object ID 0.
Re: DestroyObject doesn't work when attached to vehicle? -
Jstylezzz - 26.02.2013
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
Re: DestroyObject doesn't work when attached to vehicle? -
Scenario - 26.02.2013
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, ...);
Re: DestroyObject doesn't work when attached to vehicle? -
Jstylezzz - 26.02.2013
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
Re: DestroyObject doesn't work when attached to vehicle? -
FufLa - 26.02.2013
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.
Re: DestroyObject doesn't work when attached to vehicle? -
Scenario - 26.02.2013
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.