Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create a pickup that can be picked-up on-foot and in-vehicle
#1
 
his 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

Code:

Quote:#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

Code:

Quote:enum e_Pickups
{
   g_P_ID,
g_P_Invisible_ID
};

Thirdly we create the variables for the iterator and to manipulate the enum

Code:

Quote: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?)

Code:

Quote: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

Code:

Quote: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

Code:

Quote: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

Code:

Quote:#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


Messages In This Thread
How to create a pickup that can be picked-up on-foot and in-vehicle - by alimaroco - 04-13-2017, 11:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a Timer alimaroco 1 7,120 04-27-2017, 11:08 AM
Last Post: Lance

Forum Jump:


Users browsing this thread: 1 Guest(s)