Detect if user achieved pickup:
#1

I'm building an achievement system, yet I'm having trouble to detect if the player obtained an horseshoe. There are about 10 horseshoes around San Andreas, but I'm unsure on how to detect if the player has found and got a horseshoe. They can pick a horseshoe once (if a player found horseshoe #1, they won't be able to obtain it again).
Reply
#2

Something like this?

pawn Код:
new pickup_Horseshoe[10];
new bool: pHorseshoePicked[10];

public OnPlayerPickUpPickup(playerid, pickupid)
{
    for(new i; i < 10; i ++)
    {
        if(pickupid == pickup_Horseshoe[i])
        {
            if(!pHorseshoePicked[i])
            {
                DestroyPickup(pickup_Horseshoe[i]);
                pHorseshoePicked[i] = true;
            }
           
            else return false;
        }
    }

    return true;
}
EDIT: Make sure to properly define "pickup_Horseshoe[val]" though.
Reply
#3

Try this out!
pawn Код:
#define MAX_HORSE_SHOES 10

new pHorseShoeID            [MAX_PLAYERS][MAX_HORSE_SHOES],
    bool:pHorseShoeTaken    [MAX_PLAYERS][MAX_HORSE_SHOES];

new const Float:HorseShoeCoords[MAX_HORSE_SHOES][3] =
{
    {x, y, z},
    {x, y, z},
    {x, y, z},
    {x, y, z},
    {x, y, z},
    {x, y, z},
    {x, y, z},
    {x, y, z},
    {x, y, z},
    {x, y, z}
}; // Replace x, y, z with coordinates

stock GetPlayerHorseshoes(playerid)
{
    new shoes;
    for(new i; i < MAX_HORSE_SHOES; i ++)
    {
        if(pHorseShoeTaken[playerid][i])
            shoes ++;
    }
    return shoes;
}

public OnPlayerConnect(playerid)
{
    for(new i; i < MAX_HORSE_SHOES; i ++)
    {
        new Float:x, Float:y, Float:z;
        x = HorseShoeCoords[i][0];
        y = HorseShoeCoords[i][1];
        z = HorseShoeCoords[i][2];
        pHorseShoeID[playerid][i] = CreateDynamicPickup(954, 1, x, y, z, -1, -1, playerid);
        pHorseShoeTaken[playerid][i] = false;
    }
}

public OnPlayerDisconnect(playerid, reason)
{
    for(new i; i < MAX_HORSE_SHOES; i ++)
    {
        if(!pHorseShoeTaken[playerid][i])
        {
            DestroyDynamicPickup(pHorseShoeID[playerid][i]);
            pHorseShoeTaken[playerid][i] = false;
        }
    }
}

public OnPlayerPickupDynamicPickup(playerid, pickupid)
{
    for(new i; i < MAX_HORSE_SHOES; i ++)
    {
        if(pickupid == pHorseShoeID[playerid][i])
        {
            DestroyDynamicPickup(pHorseShoeID[playerid][i]);
            pHorseShoeTaken[playerid][i] = true;

            new string[47];
            format(string, sizeof(string), "~g~You have picked up %i out of %i horseshoes!", GetPlayerHorseshoes(playerid), MAX_HORSE_SHOES);
            GameTextForPlayer(playerid, string, 2000, 6);
            PlayerPlaySound(playerid, 1150, 0.0, 0.0, 0.0);
        }
    }
}
Reply
#4

Pickups can't currently be created for one player; if a pickup is shown, all will see it. So what you're asking is impossible.
Reply
#5

Thanks for the support, everyone. I'm having a look what you'se said.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)