How to destroy only 1 closest object?
#1

I dont know how to make a script where by pressing a specially key and when player standing in distance of 1.5 an one object will be destroyed. I created a script where any object which is detected in distance 1.5 will disappear, but I need to destroy only 1 object from 2 which are near.

It would be fine also when 1 random object from 2 other in mentioned distance will be destroyed.

pawn Код:
//--------------------------------------------------------------------------------------------------------------
new PastaCans[6];

public OnFilterScriptInit()
{
    PastaCans[0] = CreateObject(1455, -1335.14, 2524.24, 86.12,   0.00, 0.00, 0.00);
    PastaCans[1] = CreateObject(1455, -1335.47, 2524.37, 86.12,   0.00, 0.00, 171.00);
    PastaCans[2] = CreateObject(1455, -1335.38, 2524.28, 86.12,   0.00, 0.00, 18.00);
    PastaCans[3] = CreateObject(1455, -1313.31, 2541.69, 86.81,   0.00, 0.00, 0.00);
    PastaCans[4] = CreateObject(1455, -1316.28, 2540.80, 86.81,   0.00, 0.00, 171.00);
    PastaCans[5] = CreateObject(1455, -1316.69, 2540.90, 86.81,   0.00, 0.00, 84.00);
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{

    if (newkeys & KEY_SECONDARY_ATTACK)
    {
    new Float:PastaCanX, Float:PastaCanY, Float:PastaCanZ;

        for(new PastaCansID=0; PastaCansID < sizeof(PastaCans); PastaCansID++)
        {
        GetObjectPos(PastaCans[PastaCansID], PastaCanX, PastaCanY, PastaCanZ);

            if(IsPlayerInRangeOfPoint(playerid, 1.5, PastaCanX, PastaCanY, PastaCanZ))
            {
            DestroyObject(PastaCans[PastaCansID]); // PROBLEM WITH AMOUNT OF DESTROYED OBJECTS
            }

        }

    }
    return 1;
}
//--------------------------------------------------------------------------------------------------------------
Help me, please...
Reply


Messages In This Thread
How to destroy only 1 closest object? - by Stalker177 - 21.05.2013, 21:26
Re: How to destroy only 1 closest object? - by Hawky133 - 22.05.2013, 02:33
Re: How to destroy only 1 closest object? - by Stalker177 - 23.05.2013, 15:48

Forum Jump:


Users browsing this thread: 1 Guest(s)