SA-MP Forums Archive
object is destroyed but still valid?? - 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: object is destroyed but still valid?? (/showthread.php?tid=606755)



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]);
}