Why it doesnt remove the object?
#1

Код:
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?
Reply
#2

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);}
Reply
#3

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)