object is destroyed but still valid?? -
ax1 - 08.05.2016
Код:
CMD:obj(playerid)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x,y,z);
if(!IsValidDynamicObject(Object[playerid]))
{
Object[playerid]=CreateObject(866, x, y, z, 0, 0,0, 50);
SetTimerEx("Destroy", 2000, false, "i", playerid);
}
return 1;
}
forward Destroy(playerid);
public Destroy(playerid)
{
DestroyObject(Object[playerid]);
}
So it creates object and destroys it after 2 seconds. But when I try to create object again it won't let me even though it should since I destroyed Object[playerid] so it is not valid
Re: object is destroyed but still valid?? -
paul988 - 08.05.2016
You are checking if the object is valid/invalid using a fuction from Incognito's streamer plugin but you are creating and destroying the objects using the default sa:mp natives.
To fix this problem you must either check if the object is valid/invalid using the sa:mp native function or use Incognito's streamer plugin to create and destroy the object.
Re: object is destroyed but still valid?? -
ikey07 - 08.05.2016
at top of the script add
new Object[MAX_PLAYERS] = {-1,...};
Then when you destroy an object, set object handle to -1 and dont use IsValid... object, but just check if Object[playerid] is -1, and if it is, object is destroyed. otherwise destroy and set it to -1, this is how you MUST do to keep it in order, cuz IsValidDynamicObject doesnt actually check if its right object, it just check if object with such a handle is created at all.
Re: object is destroyed but still valid?? -
jlalt - 08.05.2016
change this
PHP код:
forward Destroy(playerid);
public Destroy(playerid)
{
DestroyObject(Object[playerid]);
}
to
PHP код:
forward Destroy(playerid);
public Destroy(playerid)
{
DestroyObject(Object[playerid]);
Object[playerid] = INVALID_OBJECT_ID;
}
Re: object is destroyed but still valid?? -
AbyssMorgan - 09.05.2016
you need glasses :P
Код:
CMD:obj(playerid)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x,y,z);
if(!IsValidDynamicObject(Object[playerid]))
{
Object[playerid]=CreateObject(866, x, y, z, 0, 0,0, 50);
SetTimerEx("Destroy", 2000, false, "i", playerid);
}
return 1;
}
forward Destroy(playerid);
public Destroy(playerid)
{
DestroyObject(Object[playerid]);
}