[Tutorial] How to create a pickup that can be picked-up on-foot and in-vehicle
#1

This allows pickups to be picked up on foot and in vehicle. This is not much of a tutorial.

Requirements
The Script

First we make a limit for pickups, since we're gonna use 2 pickups per 1 pickup in this tutorial, we're gonna cut the limit in half

pawn Код:
#define MAX_PICKUPS_EX (MAX_PICKUPS / 2) // which is 2048, Limit has been cut in half
Secondly, create the enum data structure for the ID storing

g_P_ID repesents the real pickup model that can only be picked up on - foot, and g_P_Invisible_ID represents the invisible model that can only be picked up in vehicle

pawn Код:
enum e_Pickups
{
    g_P_ID,
    g_P_Invisible_ID
};
Thirdly we create the variables for the iterator and to manipulate the enum

pawn Код:
new gPickupData[MAX_PICKUPS_EX][e_Pickups],
    Iterator:gPickups[MAX_PICKUPS_EX];
Fourthly we make the pickup creation function

This function creates the model and an invisible pickup (19300) SA-MP 0.3c+ (Is it?)

pawn Код:
stock CreateStaticPickup(model, Float:x, Float:y, Float:z, virtualworld = 0)
{
    new id = Iter_Free(gPickups);
    gPickups[id][g_P_ID] = CreatePickup(model, 14, x, y, z, virtualworld);
    gPickups[id][g_P_Invisible_ID] = CreatePickup(19300, 14, x, y, z, virtualworld);
    return id;
}
Fifthly we create a way to SAFELY destroy the pickups

pawn Код:
stock DestroyStaticPickup(id, &next)
{
    if(Iter_Contains(gPickups, id)) return -1;
    DestroyPickup(gPickups[id][g_P_ID]);
    DestroyPickup(gPickups[id][g_P_Invisible_ID]);
    Iter_SafeRemove(gPickups, id, next);
    return next;
}
Lastly, we need someway to detect if either ONE of the pickups were entered, right? Don't worry we only need this ONCE, because your not gonna enter the pickup while your in both states, the callback only gets called in either state

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    foreach(gPickups, p)
    {
        if(gPickups[p][g_P_ID] != pickupid && gPickups[p][g_P_Invisible_ID] != pickupid) continue;
        // do shit here
        new next; // I don't even think that this is needed, but for safety, let's leave it.
        p = DestroyStaticPickup(p, next); // Let's SAFELY destroy the pickup without breaking the loop
        break;
    }
    return 1;
}
The Full Code

pawn Код:
#define MAX_PICKUPS_EX (MAX_PICKUPS / 2) // which is 2048, Limit has been cut in half

enum e_Pickups
{
    g_P_ID,
    g_P_Invisible_ID
};

new gPickupData[MAX_PICKUPS_EX][e_Pickups],
    Iterator:gPickups[MAX_PICKUPS_EX];

stock CreateStaticPickup(model, Float:x, Float:y, Float:z, virtualworld = 0)
{
    new id = Iter_Free(gPickups);
    gPickups[id][g_P_ID] = CreatePickup(model, 14, x, y, z, virtualworld);
    gPickups[id][g_P_Invisible_ID] = CreatePickup(19300, 14, x, y, z, virtualworld);
    return id;
}

stock DestroyStaticPickup(id, &next)
{
    if(Iter_Contains(gPickups, id)) return -1;
    DestroyPickup(gPickups[id][g_P_ID]);
    DestroyPickup(gPickups[id][g_P_Invisible_ID]);
    Iter_SafeRemove(gPickups, id, next);
    return next;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    foreach(gPickups, p)
    {
        if(gPickups[p][g_P_ID] != pickupid && gPickups[p][g_P_Invisible_ID] != pickupid) continue;
        // do shit here
        new next; // I don't even think that this is needed, but for safety, let's leave it.
        p = DestroyStaticPickup(p, next); // Let's SAFELY destroy the pickup without breaking the loop
        break;
    }
    return 1;
}
- Enjoy

Credits
  • Kalcor & The SA-MP Team (For SA-MP and the Invisible Object)
Reply
#2

Thanks for the invisible pickup id and vehicle type.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)