Advertisement
Larceny

mLibrary INC v2

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