SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 08/05/2016, 03:37 PM   #1
ax1
Big Clucker
 
Join Date: Jul 2015
Posts: 161
Reputation: 2
Default object is destroyed but still valid??

Code:
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
ax1 is offline   Reply With Quote
Old 08/05/2016, 03:56 PM   #2
paul988
Little Clucker
 
Join Date: Oct 2012
Posts: 29
Reputation: 10
Default Re: object is destroyed but still valid??

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.
paul988 is offline   Reply With Quote
Old 08/05/2016, 04:01 PM   #3
ikey07
High-roller
 
ikey07's Avatar
 
Join Date: Jul 2010
Location: Latvia,Riga
Posts: 1,364
Reputation: 180
Default Re: object is destroyed but still valid??

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.
__________________
ikey07 is offline   Reply With Quote
Old 08/05/2016, 04:04 PM   #4
jlalt
High-roller
 
Join Date: Oct 2014
Location: Iran
Posts: 1,415
Reputation: 352
Default Re: object is destroyed but still valid??

change this
PHP Code:
forward Destroy(playerid);
public 
Destroy(playerid)
{
DestroyObject(Object[playerid]);

to
PHP Code:
forward Destroy(playerid);
public 
Destroy(playerid)
{
DestroyObject(Object[playerid]);
Object[playerid] = INVALID_OBJECT_ID;

jlalt is offline   Reply With Quote
Old 09/05/2016, 03:43 PM   #5
AbyssMorgan
Banned
 
Join Date: Apr 2015
Location: Poland
Posts: 1,260
Reputation: 326
Default Re: object is destroyed but still valid??

you need glasses :P
Code:
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]);
}
AbyssMorgan is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Valid Dynamic Object TwinkiDaBoss Scripting Help 5 12/12/2015 04:10 PM
Object not being destroyed and weapon are not been given Gaurav_Rawat Scripting Help 1 04/04/2014 10:50 AM
If player near an object the object will be destroyed ToiletDuck Scripting Help 10 30/07/2013 03:59 PM
detect if destroyed object? jamesbond007 Scripting Help 7 05/12/2011 07:36 AM
[?] valid object list? BombaNick Help Archive 1 03/09/2010 01:06 PM


All times are GMT. The time now is 08:31 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.