Why it doesnt remove the object? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Why it doesnt remove the object? (
/showthread.php?tid=600416)
Why it doesnt remove the object? -
Lirbo - 07.02.2016
Код:
if (HOLDING(KEY_NO) && IsPlayerInAnyVehicle(playerid) && DB[playerid][Neon] != 0){
new vehicleid = GetPlayerVehicleID(playerid);
new NeonObject;
DestroyObject(NeonObject);
NeonObject = CreateObject(DB[playerid][Neon], 0,0,-30, 0.0, 0.0, 96.0, 300.0);
AttachObjectToVehicle(NeonObject, vehicleid, 0.0, 0.0, -0.5, 0.0, 0.0, 0.0);}
the previous object doesnt destroy once the player press on the key again, I just want to avoid spam
btw how can i do it with createdynamicobject?
Re: Why it doesnt remove the object? -
Gammix - 07.02.2016
pawn Код:
new NeonObject;
DestroyObject(NeonObject);
You are creating a new variable and passing it through DestroyObject which will remove the objectid 0 (if any).
This is called local variable but in your case, you need global variable and per player/vehicle in order to store the neon object.
So this would be: (declare this independently, not in any callback or function)
pawn Код:
new pNeonObject[MAX_PLAYERS];
pawn Код:
if (HOLDING(KEY_NO) && IsPlayerInAnyVehicle(playerid) && DB[playerid][Neon] != 0){
new vehicleid = GetPlayerVehicleID(playerid);
if (IsValidObject(pNeonObject[playerid])
DestroyObject(pNeonObject[playerid]);
pNeonObject[playerid]= CreateObject(DB[playerid][Neon], 0,0,-30, 0.0, 0.0, 96.0, 300.0);
AttachObjectToVehicle(pNeonObject[playerid], vehicleid, 0.0, 0.0, -0.5, 0.0, 0.0, 0.0);}
Re: Why it doesnt remove the object? -
Lirbo - 07.02.2016
Quote:
Originally Posted by Gammix
pawn Код:
new NeonObject; DestroyObject(NeonObject);
You are creating a new variable and passing it through DestroyObject which will remove the objectid 0 (if any).
This is called local variable but in your case, you need global variable and per player/vehicle in order to store the neon object.
So this would be: (declare this independently, not in any callback or function)
pawn Код:
new pNeonObject[MAX_PLAYERS];
pawn Код:
if (HOLDING(KEY_NO) && IsPlayerInAnyVehicle(playerid) && DB[playerid][Neon] != 0){ new vehicleid = GetPlayerVehicleID(playerid); if (IsValidObject(pNeonObject[playerid]) DestroyObject(pNeonObject[playerid]); pNeonObject[playerid]= CreateObject(DB[playerid][Neon], 0,0,-30, 0.0, 0.0, 96.0, 300.0); AttachObjectToVehicle(pNeonObject[playerid], vehicleid, 0.0, 0.0, -0.5, 0.0, 0.0, 0.0);}
|
oh thx mate +REP