Advertisement
Mihaitza97

GiftBoxes System

Dec 24th, 2014
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.49 KB | None | 0 0
  1. #define INVALID_PICKUP_ID 9999
  2.  
  3. forward InitiateGifts(); //This function creates giftboxes and resets variables to default.
  4. forward DestroyGifts(); //This function destroys every giftbox and resets variables to default.
  5. forward CheckGift(playerid,pickupid); //You must insert this function in your OnPlayerPickUpPickup public from your gamemode.
  6. forward PlayerGiftReward(playerid,pickupid); //You must use this public in your gamemode in order to set a bonus for the player to receive when he picks up a giftbox.
  7. //---------- This array contains the positions of the giftboxes {x,y,z} ----------
  8. new Float:GiftPos[][] = {
  9.     {2044.6616, 1339.3722, 10.6719},
  10.     {2051.0129,1346.4264,10.6719},
  11.     {2046.7195,1352.7656,10.6719},
  12.     {2051.8047,1359.9277,10.6719},
  13.     {2047.4851,1365.3621,10.6719}
  14. };
  15. //------------------------------------
  16. new GiftPickup[sizeof(GiftPos)]; //Contains the id of the pickup
  17. new bool:GiftPickupStatus[sizeof(GiftPos)]; //Pickup status: used/unused.
  18. //------------------------------------
  19. public InitiateGifts()
  20. {
  21.     for(new i; i < sizeof(GiftPos); i++)
  22.     {
  23.         if(GiftPickup[i] != INVALID_PICKUP_ID && GiftPickupStatus[i] != false) DestroyPickup(GiftPickup[i]);
  24.         GiftPickup[i] = INVALID_PICKUP_ID;
  25.         GiftPickupStatus[i] = false;
  26.     }
  27.     new MaxRandom = 0;
  28.     new RandomNumber = 0;
  29.     for(new i; MaxRandom <= sizeof(GiftPos)/2; i++) //When this public is called, on your map will be spawned just a half(random) from the total coordonates that you set in GiftPos array.
  30.     {
  31.         RandomNumber = random(sizeof(GiftPos));
  32.         if(GiftPickupStatus[RandomNumber] != true)
  33.         {
  34.             GiftPickup[RandomNumber] = CreatePickup(19054, 19, GiftPos[RandomNumber][0], GiftPos[RandomNumber][1], GiftPos[RandomNumber][2], -1);
  35.             GiftPickupStatus[RandomNumber] = true;
  36.             MaxRandom++;
  37.         }
  38.     }
  39.     printf("** GIFTS: %d giftboxes has been created with successfully!",MaxRandom);
  40.     return 1;
  41. }
  42. public DestroyGifts()
  43. {
  44.     for(new i; i < sizeof(GiftPos); i++) { if(GiftPickup[i] != INVALID_PICKUP_ID && GiftPickupStatus[i] != false) DestroyPickup(GiftPickup[i]), GiftPickup[i] = INVALID_PICKUP_ID, GiftPickupStatus[i] = false; }
  45.     print("** GIFTS: The gift boxes has been destroyed!");
  46.     return 1;
  47. }
  48. public CheckGift(playerid,pickupid)
  49. {
  50.     for(new i; i < sizeof(GiftPos); i++) { if(GiftPickup[i] == pickupid && IsPlayerInRangeOfPoint(playerid, 2.0, GiftPos[i][0], GiftPos[i][1], GiftPos[i][2])) DestroyPickup(pickupid), PlayerGiftReward(playerid,pickupid), printf("[**] GIFTS: PlayerID %d pick up GiftID %d!",playerid,pickupid); }
  51.     return 1;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement