Advertisement
Larceny

mLibrary INC v2.5

Oct 14th, 2011
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.80 KB | None | 0 0
  1. /*------------------------------------------------------------------------------
  2.                     *********************************************
  3.                             mLibrary - Machine Library.
  4.                     *********************************************
  5. Description:
  6.     A library that allows you to add machines sprunks (running) the map.
  7. Version:
  8.     2.5
  9. Developer:
  10.     Synchr0.
  11. ChangeLOG:
  12.     14/10/2011(2.5):
  13.         callback OnPlayerUseMachine.
  14.     14/10/2011(2.1):
  15.         Fixed radius of all machines.
  16.     14/10/2011(2.0):
  17.         Added two new machines.
  18.         Machines are now toggleable between active and desactive.
  19.         Machines recover life can be configurated.
  20.     13/10/2011(1.0):
  21.         First release.
  22. Thanks to:
  23.     Y_Less                                  - Easy way to hook callbacks
  24.     Equipe SA-MP(past\present\future)       - SAMP.
  25. ------------------------------------------------------------------------------*/
  26.  
  27. #if defined _mLibrary_included
  28.     #endinput
  29. #endif
  30.  
  31. #define _mLibrary_included
  32. #define MAX_MACHINES    128
  33. #define MACHINE_CANDY   956
  34. #define MACHINE_SPRUNK  955
  35. #define MACHINE_SODA    1302
  36.  
  37. #define SODA_RADIUS 1.2
  38. #define SPRUNK_RADIUS 1.05
  39. #define CANDY_RADIUS 1.05
  40.  
  41. /*Natives
  42. native CreateMachine(machineid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:life = 35.0, bool:active = true);
  43. native OnPlayerUseMachine(playerid, machineid, Float:oldhealth, Float:newhealth);
  44. native GetXYInFrontOfMachine(machineid, &Float:x, &Float:y, Float:distance);
  45. native GetMachineRotation(machineid, &Float:rx, &Float:ry, &Float:rz);
  46. native SetMachineRotation(machineid, Float:rx, Float:ry, Float:rz);
  47. native GetMachinePos(machineid, &Float:x, &Float:y, &Float:z);
  48. native SetMachinePos(machineid, Float:x, Float:y, Float:z);
  49. native SetMachineRecover(machineid, Float:life);
  50. native SetMachineActive(machineid, bool:active);
  51. native GetMachineRecover(machineid);
  52. native GetMachineActive(machineid);
  53. native DeleteMachine(machineid);
  54. native mexist(machineid);*/
  55.  
  56. enum mlbdef
  57. {
  58.     Float:M_X,
  59.     Float:M_Y,
  60.     Float:M_Z,
  61.     Float:M_RX,
  62.     Float:M_RY,
  63.     Float:M_RZ,
  64.     bool:M_ACTIVE,
  65.     Float:M_LIFE,
  66.     Float:M_RADIUS,
  67.     M_ID,
  68. };
  69.  
  70. static
  71.         gMTotal,
  72.         MACHINES[MAX_MACHINES][mlbdef];
  73.  
  74. stock
  75.     CreateMachine(machineid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:life = 35.0, bool:active = true)
  76. {
  77.     new MID = SearchMachines();
  78.     if(MID == -1){ print("SCRIPT_ERROR 487: Limite de maquinas foi ultrapassado! (mLibrary.inc)"); return 0;}
  79.     switch(machineid)
  80.     {
  81.         case MACHINE_SPRUNK:{MACHINES[MID][M_RADIUS] = SPRUNK_RADIUS;}
  82.         case MACHINE_CANDY:{MACHINES[MID][M_RADIUS] = CANDY_RADIUS;}
  83.         case MACHINE_SODA:{MACHINES[MID][M_RADIUS] = SODA_RADIUS;}
  84.         default:{printf("SCRIPT_ERROR 374: ID da Maquina invalido! (mLibrary.inc) (ID usado: %i - ID valido: 955, 956 ou 1302)", machineid); return 0;}
  85.     }
  86.     MACHINES[MID][M_ID] = CreateObject(machineid, x, y, z, rx, ry, rz, 300.0);
  87.     MACHINES[MID][M_X] = x;
  88.     MACHINES[MID][M_Y] = y;
  89.     MACHINES[MID][M_Z] = z;
  90.     MACHINES[MID][M_RX] = rx;
  91.     MACHINES[MID][M_RY] = ry;
  92.     MACHINES[MID][M_RZ] = rz;
  93.     MACHINES[MID][M_RZ] = rz;
  94.     MACHINES[MID][M_LIFE] = life;
  95.     MACHINES[MID][M_ACTIVE] = active;
  96.     gMTotal++;
  97.     return MID;
  98. }
  99.  
  100. stock
  101.     DeleteMachine(machineid)
  102. {
  103.     if(!MACHINES[machineid][M_ID]) return 0;
  104.     gMTotal--;
  105.     DestroyObject(MACHINES[machineid][M_ID]);
  106.     MACHINES[machineid][M_ID] = 0;
  107.     return 1;
  108. }
  109.  
  110. stock
  111.     mexist(machineid) return (!MACHINES[machineid][M_ID]) ? 0 : 1;
  112.  
  113. stock
  114.     SearchMachines()
  115. {
  116.     for(new m = 1; m < MAX_MACHINES; m++) if(!MACHINES[m][M_ID]) return m;
  117.     return -1;
  118. }
  119.  
  120. stock
  121.     SetMachinePos(machineid, Float:x, Float:y, Float:z)
  122. {
  123.     if(!MACHINES[machineid][M_ID]) return 0;
  124.     MACHINES[machineid][PBP_X] = x;
  125.     MACHINES[machineid][PBP_Y] = y;
  126.     MACHINES[machineid][PBP_Z] = z;
  127.     return SetObjectPos(MACHINES[machineid][M_ID], x, y, z);
  128. }
  129.  
  130. stock
  131.     SetMachineRotation(machineid, Float:rx, Float:ry, Float:rz)
  132. {
  133.     if(!MACHINES[machineid][M_ID]) return 0;
  134.     MACHINES[machineid][M_RX] = rx;
  135.     MACHINES[machineid][M_RY] = ry;
  136.     MACHINES[machineid][M_RZ] = rz;
  137.     return SetObjectRot(MACHINES[machineid][M_ID], rx, ry, rz);
  138. }
  139.  
  140. stock
  141.     GetMachinePos(machineid, &Float:x, &Float:y, &Float:z)
  142. {
  143.     if(!MACHINES[machineid][M_ID])
  144.     {
  145.         x = 0.0;
  146.         y = 0.0;
  147.         z = 0.0;
  148.     }
  149.     x = MACHINES[machineid][M_X];
  150.     y = MACHINES[machineid][M_Y];
  151.     z = MACHINES[machineid][M_Z];
  152. }
  153.  
  154. stock
  155.     GetMachineRotation(machineid, &Float:rx, &Float:ry, &Float:rz)
  156. {
  157.     if(!MACHINES[machineid][M_ID]){
  158.         rx = 0.0;
  159.         ry = 0.0;
  160.         rz = 0.0;}
  161.     rx = MACHINES[machineid][M_RX];
  162.     ry = MACHINES[machineid][M_RY];
  163.     rz = MACHINES[machineid][M_RZ];
  164. }
  165.  
  166. stock
  167.     GetXYInFrontOfMachine(machineid, &Float:x, &Float:y, Float:distance)
  168. {
  169.     new
  170.         Float:rotz,
  171.         Float:xs,
  172.         Float:ys,
  173.         Float:zs;
  174.     GetObjectPos(machineid, x, y, zs);
  175.     GetObjectRot(machineid, xs, ys, rotz);
  176.     x += (distance * floatsin(-rotz, degrees));
  177.     y += (distance * floatcos(-rotz, degrees));
  178. }
  179.  
  180. stock
  181.     SetMachineActive(machineid, bool:active)
  182. {
  183.     if(!MACHINES[machineid][M_ID]) return 0;
  184.     MACHINES[machineid][M_ACTIVE] = active;
  185. }
  186.  
  187. stock
  188.     GetMachineActive(machineid)
  189. {
  190.     if(!MACHINES[machineid][M_ID]) return 0;
  191.     return MACHINES[machineid][M_ACTIVE];
  192. }
  193.  
  194. stock
  195.     SetMachineRecover(machineid, Float:life)
  196. {
  197.     if(!MACHINES[machineid][M_ID]) return 0;
  198.     MACHINES[machineid][M_LIFE] = life;
  199. }
  200.  
  201. stock
  202.     GetMachineRecover(machineid)
  203. {
  204.     if(!MACHINES[machineid][M_ID]) return 0;
  205.     return floatround(MACHINES[machineid][M_LIFE]);
  206. }
  207.  
  208. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  209. {
  210.     if(newkeys == 16)
  211.     {
  212.         new
  213.             Float:machpos[2];
  214.         for(new m = 1; m <= gMTotal; m++)
  215.         {
  216.             if(MACHINES[m][M_ID])
  217.             {
  218.                 if(IsPlayerInRangeOfPoint(playerid, MACHINES[m][M_RADIUS], MACHINES[m][M_X], MACHINES[m][M_Y], MACHINES[m][M_Z]))
  219.                 {
  220.                     if(!MACHINES[m][M_ACTIVE]){OnPlayerUseMachine(playerid, m, 0.0, 0.0); return 0;}
  221.                     SetPlayerFacingAngle(playerid, GetXYInFrontOfMachine(m, machpos[0], machpos[1], 1.0));
  222.                     ApplyAnimation(playerid, "VENDING", "VEND_USE", 10.0, 0, 0, 0, 0, 0, 1);
  223.                     new Float:MyHealth;
  224.                     GetPlayerHealth(playerid, MyHealth);
  225.                     if (MyHealth+MACHINES[m][M_LIFE] < 100)
  226.                     {
  227.                         if(OnPlayerUseMachine(playerid, m, MyHealth, MyHealth+MACHINES[m][M_LIFE]) == 0) return 0;
  228.                         SetPlayerHealth(playerid, MyHealth+MACHINES[m][M_LIFE]);
  229.                     }
  230.                     else
  231.                     {
  232.                         if(OnPlayerUseMachine(playerid, m, MyHealth, 100) == 0) return 0;
  233.                         SetPlayerHealth(playerid, 100);
  234.                     }
  235.                 }
  236.             }
  237.         }
  238.     }
  239.     return CallLocalFunction("mLibrary_OnPlayerKeyStateChange", "iii", playerid, newkeys, oldkeys);
  240. }
  241.  
  242. #if defined _ALS_OnPlayerKeyStateChange
  243.     #undef OnPlayerKeyStateChange
  244. #else
  245.     #define _ALS_OnPlayerKeyStateChange
  246. #endif
  247. #define OnPlayerKeyStateChange mLibrary_OnPlayerKeyStateChange
  248. forward mLibrary_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  249. forward OnPlayerUseMachine(playerid, machineid, Float:oldhealth, Float:newhealth);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement