Valid Dynamic Object
#1

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
Reply
#2

How is the object destroyed?
Reply
#3

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

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

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;
    }
}
Reply
#6

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)