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
#2
levitra ohne rezept apotheke levitra 20mg kaufen ohne rezept vardenafil kaufen schweiz
sildenafil generika kaufen sildenafil schweiz rezeptfrei kaufen sildenafil rezeptfrei online
meloxicam kaufen ohne rezept meloxicam kaufen rezeptfrei meloxicam kaufen schweiz
levitra kaufen in holland levitra tabletten kaufen levitra 20mg kaufen ohne rezept
bupropion online rezept bupropion rezeptfrei kaufen bupropion 300 mg kaufen
baclofen online kaufen baclofen ohne rezept bestellen baclofen bestellen ohne rezept
stromectol tabletten kaufen rezeptfrei stromectol 3mg tabletten kaufen stromectol 12mg kaufen
sildenafil online kaufen österreich sildenafil bestellen zonder recept sildenafil 50 mg preis ohne rezept
cytotec bestellen ohne rezept cytotec ohne rezept kaufen cytotec online kaufen ohne rezept
levitra rezeptfrei schweiz levitra kaufen preisvergleich vardenafil online kaufen
propranolol 40 mg kaufen propranolol 10 mg kaufen ohne rezept propranolol creme kaufen
orlistat günstig bestellen xenical orlistat 120 mg kaufen xenical rezeptfrei schweiz
seroquel kaufen apotheke seroquel kaufen seroquel kaufen ohne rezept
orlistat rezeptfrei xenical orlistat 120 mg kaufen orlistat online kaufen
sildenafil 100mg kaufen österreich sildenafil bestellen zonder recept sildenafil kaufen preis
Reply


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

Forum Jump:


Users browsing this thread: 1 Guest(s)