Advertisement
Mi5kas

!PP! - Player Pickups

Sep 25th, 2014
698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.57 KB | None | 0 0
  1. /*
  2. !PP! - Player pickups by iWhite/!LukniS!
  3.  
  4. Functions:
  5.  
  6. native CreatePlayerPickup(playerid, modelid, Float:x, Float:y, Float:z, Float:range=1.0);
  7. playerid - playerid to show pickup
  8. modelid - object model id to show as player pickup
  9. x, y, z - coordinates
  10. range - range of pickup, from where pickup can be picked up(default 1.0)
  11. returns pickupid or -1, if pickup creation failed
  12.  
  13. native DestroyPlayerPickup(playerid, pickupid);
  14. playerid - playerid for whom destroy pickup
  15. pickupid - pickupid to destroy
  16. returns 1 on success, 0 on failure(there is no pickup on that id)
  17.  
  18. native IsPlayerPickupCreated(playerid, pickupid);
  19. playerid - playerid to check if pickup has been created for him
  20. pickupid - to check if that pickup exists
  21. returns 1 on success, 0 on failure
  22.  
  23. Callbacks:
  24.  
  25. public OnPlayerPickUpPlayerPickup(playerid, pickupid)
  26. playerid - playerid, who picked up pickup
  27. pickupid - pickupid, which was picked up
  28. */
  29.  
  30.  
  31. #define MAX_PLAYER_PICKUPS 128 //Set max amount of player pickups for one player
  32.  
  33. enum ppick
  34. {
  35.    Objectid,
  36.    bool:Moveup,
  37.    #if !defined _inc_streamer
  38.       Float:pickrange,
  39.       Float:ppx,
  40.       Float:ppy,
  41.       Float:ppy
  42.    #else
  43.       Areaid
  44.    #endif
  45. };
  46. new PPickupData[MAX_PLAYERS][MAX_PLAYER_PICKUPS][ppick];
  47. forward OnPlayerPickUpPlayerPickup(playerid, pickupid);
  48.  
  49. stock CreatePlayerPickup(playerid, modelid, Float:x, Float:y, Float:z, Float:range=1.0)
  50. {
  51.    for(new o; o<MAX_PLAYER_PICKUPS; o++)
  52.    {
  53.       if(IsValidPlayerObject(playerid, PPickupData[playerid][o][Objectid]))
  54.       {
  55.          continue;
  56.       }
  57.       PPickupData[playerid][o][Objectid] = CreatePlayerObject(playerid, modelid, x, y, z, 0.0, 0.0, 0.0);
  58.       #if !defined _inc_streamer
  59.          PPickupData[playerid][o][ppx] = x;
  60.          PPickupData[playerid][o][ppy] = y;
  61.          PPickupData[playerid][o][ppz] = z;
  62.          PPickupData[playerid][o][pickrange] = range;
  63.       #else
  64.          PPickupData[playerid][o][Areaid] = CreateDynamicCircle(x, y, range, -1, -1, playerid);
  65.       #endif
  66.       MovePlayerObject(playerid, PPickupData[playerid][o][Objectid], x, y, z-0.01, 0.01, 0.0, 0.0, 90.0);
  67.       PPickupData[playerid][o][Moveup] = true;
  68.       return o;
  69.    }
  70.    return -1;
  71. }
  72. stock DestroyPlayerPickup(playerid, pickupid)
  73. {
  74.    if(!IsValidPlayerObject(playerid, PPickupData[playerid][pickupid][Objectid]))
  75.    {
  76.       return 0;
  77.    }
  78.    DestroyPlayerObject(playerid, PPickupData[playerid][pickupid][Objectid]);
  79.    #if defined _inc_streamer
  80.       DestroyDynamicArea(PPickupData[playerid][pickupid][Areaid]);
  81.       PPickupData[playerid][pickupid][Areaid]=-1;
  82.    #else
  83.       PPickupData[playerid][pickupid][ppx]=-1.0;
  84.       PPickupData[playerid][pickupid][ppy]=-1.0;
  85.       PPickupData[playerid][pickupid][ppz]=-1.0;
  86.       PPickupData[playerid][pickupid][pickrange]=-1.0;
  87.    #endif
  88.    PPickupData[playerid][pickupid][Objectid]=-1;
  89.    return 1;
  90. }
  91. stock IsPlayerPickupCreated(playerid, pickupid)
  92. {
  93.    return IsValidPlayerObject(playerid, PPickupData[playerid][pickupid][Objectid];
  94. }
  95. public OnPlayerObjectMoved(playerid, objectid)
  96. {
  97.     for(new p; p<MAX_PLAYER_PICKUPS; p++)
  98.     {
  99.           if(objectid == PPickupData[playerid][p][Objectid])
  100.           {
  101.              new Float:x, Float:y, Float:z, Float:rot;
  102.              GetPlayerObjectPos(playerid, PPickupData[playerid][p][Objectid], x, y, z);
  103.              GetPlayerObjectRot(playerid, PPickupData[playerid][p][Objectid], rot, rot, rot);
  104.              if(z >= 360.0)
  105.              {
  106.                 z=0.0;
  107.              }
  108.              if(PPickupData[playerid][p][Moveup])
  109.              {
  110.                 MovePlayerObject(playerid, PPickupData[playerid][p][Objectid], x, y, z+0.01, 0.01, 0.0, 0.0, rot+90.0);
  111.                 PPickupData[playerid][p][Moveup]=false;
  112.              }
  113.              else
  114.              {
  115.                 MovePlayerObject(playerid, PPickupData[playerid][p][Objectid], x, y, z-0.01, 0.01, 0.0, 0.0, rot+90.0);
  116.                 PPickupData[playerid][p][Moveup]=true;
  117.              }
  118.           }
  119.     }
  120. }
  121. #if defined _ALS_OnPlayerObjectMoved
  122.           #undef OnPlayerObjectMoved
  123.        #else
  124.           #define _ALS_OnPlayerObjectMoved
  125.        #endif
  126.        #define OnPlayerObjectMoved PP_OnPlayerObjectMoved
  127.        #if defined PP_OnPlayerObjectMoved
  128.           forward PP_OnPlayerObjectMoved(playerid,objectid);
  129. #endif
  130. public OnPlayerDisconnect(playerid, reason)
  131. {
  132.     for(new p; p<MAX_PLAYER_PICKUPS; p++)
  133.     {
  134.           if(IsValidPlayerObject(playerid, PPickupData[playerid][p][Objectid]))
  135.           {
  136.              DestroyPlayerPickup(playerid, p);
  137.           }
  138.     }
  139. }
  140. #if defined _ALS_OnPlayerDisconnect
  141.           #undef OnPlayerDisconnect
  142.        #else
  143.           #define _ALS_OnPlayerDisconnect
  144.        #endif
  145.        #define OnPlayerDisconnect PP_OnPlayerDisconnect
  146.        #if defined PP_OnPlayerDisconnect
  147.           forward PP_OnPlayerDisconnect(playerid,reason);
  148. #endif
  149. #if defined _inc_streamer
  150.            
  151.    public OnPlayerEnterDynamicArea(playerid, areaid)
  152.    {
  153.       for(new p = 0; p < MAX_PLAYER_PICKUPS; p++)
  154.       {
  155.          if(!IsValidPlayerObject(playerid, PPickupData[playerid][p][Objectid]))
  156.          {
  157.             continue;
  158.          }
  159.          if(PPickupData[playerid][p][Areaid] != areaid)
  160.          {
  161.             continue;
  162.          }
  163.          CallLocalFunction("OnPlayerPickUpPlayerPickup", "ii", playerid, p);
  164.          DestroyPlayerPickup(playerid, p);
  165.       }
  166.    }
  167.    #if defined _ALS_OnPlayerEnterDynamicArea
  168.       #undef OnPlayerEnterDynamicArea
  169.    #else
  170.       #define _ALS_OnPlayerEnterDynamicArea
  171.    #endif
  172.    #define OnPlayerEnterDynamicArea PP_OnPlayerEnterDynamicArea
  173.    #if defined PP_OnPlayerEnterDynamicArea
  174.       forward PP_OnPlayerEnterDynamicArea(playerid,areaid);
  175.    #endif
  176. #else
  177.    public OnPlayerUpdate(playerid)
  178.    {
  179.       for(new p = 0; p < MAX_PLAYER_PICKUPS; p++)
  180.       {
  181.          if(!IsValidPlayerObject(playerid, PPickupData[playerid][p][Objectid]))
  182.          {
  183.             continue;
  184.          }
  185.          if(!IsPlayerInRangeOfPoint(playerid, PPickupData[playerid][p][pickrange], PPickupData[playerid][p][ppx], PPickupData[playerid][p][ppy], PPickupData[playerid][p][ppz]))
  186.          {
  187.             continue;
  188.          }
  189.          CallLocalFunction("OnPlayerPickUpPlayerPickup", "ii", playerid, p);
  190.          DestroyPlayerObject(playerid, PPickupData[playerid][p][Objectid]);
  191.       }
  192.    }
  193.    #if defined _ALS_OnPlayerUpdate
  194.       #undef OnPlayerUpdate
  195.    #else
  196.       #define _ALS_OnPlayerUpdate
  197.    #endif
  198.    #define OnPlayerUpdate PP_OnPlayerUpdate
  199.    #if defined PP_OnPlayerUpdate
  200.       forward PP_OnPlayerUpdate(playerid);
  201.    #endif  
  202. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement