Advertisement
Larceny

mLibrary INC

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