object is destroyed but still valid??
#1

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

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.
Reply
#3

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.
Reply
#4

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;

Reply
#5

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


Forum Jump:


Users browsing this thread: 2 Guest(s)