SA-MP Forums Archive
Valid Dynamic Object - 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: Valid Dynamic Object (/showthread.php?tid=596111)



Valid Dynamic Object - TwinkiDaBoss - 12.12.2015

Alright so I got a simple loop to check for valid objects from the 2d array. Now the problem is quite simple, it will detect objects that have been previously destroyed as valid.


PHP код:
new testobject[3];
CMD:test(playerid,params[]) {
    new 
Float:XFloat:YFloat:Z;
    for(new 
0sizeof(TestObject); i++) {
        if(
IsValidDynamicObject(TestObject[i])) {
            
GetDynamicObjectPos(TestObject[i], XYZ);
            if(
IsPlayerInRangeOfPoint(playerid5XYZ)) {
                
printf("in range of the object");
            }
        }
    }
    return 
true;

Testobject are 3 objects created under GameModeInit


Re: Valid Dynamic Object - Patrick - 12.12.2015

How is the object destroyed?


Re: Valid Dynamic Object - TwinkiDaBoss - 12.12.2015

Quote:
Originally Posted by Patrick
Посмотреть сообщение
How is the object destroyed?
Its later on destroyed simply
PHP код:
for(new 0sizeof(TestObject); i++) {
        
GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
        if(
IsPlayerInRangeOfPoint(playerid5XYZ)) {
            
DestroyDynamicObject(TestObject[i]);
        }
    } 



Re: Valid Dynamic Object - Patrick - 12.12.2015

Quote:
Originally Posted by TwinkiDaBoss
Посмотреть сообщение
Its later on destroyed simply
PHP код:
for(new 0sizeof(TestObject); i++) {
        
GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
        if(
IsPlayerInRangeOfPoint(playerid5XYZ)) {
            
DestroyDynamicObject(TestObject[i]);
        }
    } 
I knew it. You have to reset the value of TestObject and you should be good to go, also add a detection if TestObject = invalid_object_id then cancel the process.


Re: Valid Dynamic Object - Jefff - 12.12.2015

pawn Код:
new testobject[3] = {INVALID_OBJECT_ID, ...};

CMD:test(playerid, params[])
{
    new Float:X, Float:Y, Float:Z;
    for(new i = 0; i < sizeof(TestObject); i++)
    {
        if(TestObject[i] != INVALID_OBJECT_ID)
        {
            GetDynamicObjectPos(TestObject[i], X, Y, Z);
            if(IsPlayerInRangeOfPoint(playerid, 5, X, Y, Z))
            {
                print("in range of the object");
            }
        }
    }
    return true;
}

for(new i = 0; i < sizeof(TestObject); i++)
{
    GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
    if(IsPlayerInRangeOfPoint(playerid, 5.0, X, Y, Z) && TestObject[i] != INVALID_OBJECT_ID)
    {
        DestroyDynamicObject(TestObject[i]);
        TestObject[i] = INVALID_OBJECT_ID;
    }
}



Re: Valid Dynamic Object - TwinkiDaBoss - 12.12.2015

Quote:
Originally Posted by Patrick
Посмотреть сообщение
I knew it. You have to reset the value of TestObject and you should be good to go, also add a detection if TestObject = invalid_object_id then cancel the process.
Thanks