Advertisement
System32

S32_AutoGates

Feb 9th, 2012
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.16 KB | None | 0 0
  1. /*
  2.      ••••    •     •      ••••    •••••     •••••     ••     ••   •••••     •••••
  3.     •         •   •      •          •     •       • •   • •       •   •  •
  4.      ••••      • •        ••••      •     •••     •  • •  •   •••••     •
  5.          •      •             •     •     •       •   •   •       •    •
  6.      ••••        •          ••••      •     •••••   •       •   •••••   •••••
  7.  
  8.  * S32_AutoGates - Create automatic gates with just one line!
  9.  * Copyright(c)System32
  10.  * This file is provided as is (no warranties)
  11.  
  12.  * Functions: 11
  13.  * Credits:
  14.      * System32 - Almost everything!
  15.      * Y_Less - y_timers & foreach!
  16.  * That is basically it, have fun with this include and easy scripting!
  17.  */
  18.  
  19.  
  20. #include <a_samp>
  21. #include <foreach>
  22. #include <YSI\y_timers>
  23.  
  24. #define MAX_AUTOGATES 100
  25.  
  26. new Iterator: AutoGates<MAX_AUTOGATES>, agID;
  27.  
  28. enum agInfo
  29. {
  30.     agModelID,
  31.     Float: agX,
  32.     Float: agY,
  33.     Float: agZ,
  34.     Float: agrX,
  35.     Float: agrY,
  36.     Float: agrZ,
  37.     Float: agNewX,
  38.     Float: agNewY,
  39.     Float: agNewZ,
  40.     Float: agSpeed,
  41.     agStatus,
  42.     bool: agCreated,
  43.     agObject
  44. };
  45. new AutoGateInfo[MAX_AUTOGATES][agInfo];
  46.  
  47. /*
  48.  
  49.  • Function: CreateAutoGate(modelid, Float: X, Float: Y, Float: Z, Float: rX, Float: rY, Float: rZ, Float: NewX, Float: NewY, Float: NewZ, Float: Speed)
  50.  • Usage: Creating automatic gate!
  51.  • Parameters:
  52.         modelid: ID of object
  53.         X, Y, Z, rX, rY, rZ: position and rotation of object
  54.         NewX, NewY, NewZ: New poistion of object
  55.         Speed: Speed of object when he moves
  56.  • Example: CreateAutoGate(969, 1019.00000000,-1846.69995117,12.30000019,0.00000000,0.00000000,280.00000000, 1019.00000000,-1846.69995117,9.60000038, 3.0);
  57.  
  58. */
  59.  
  60. stock CreateAutoGate(modelid, Float: X, Float: Y, Float: Z, Float: rX, Float: rY, Float: rZ, Float: NewX, Float: NewY, Float: NewZ, Float: Speed)
  61. {
  62.     AutoGateInfo[agID][agModelID] = modelid;
  63.     AutoGateInfo[agID][agX] = X;
  64.     AutoGateInfo[agID][agY] = Y;
  65.     AutoGateInfo[agID][agZ] = Z;
  66.     AutoGateInfo[agID][agrX] = rX;
  67.     AutoGateInfo[agID][agrY] = rY;
  68.     AutoGateInfo[agID][agrZ] = rZ;
  69.     AutoGateInfo[agID][agNewX] = NewX;
  70.     AutoGateInfo[agID][agNewY] = NewY;
  71.     AutoGateInfo[agID][agNewZ] = NewZ;
  72.     AutoGateInfo[agID][agSpeed] = Speed;
  73.     AutoGateInfo[agID][agObject] = CreateObject(AutoGateInfo[agID][agModelID], AutoGateInfo[agID][agX], AutoGateInfo[agID][agY], AutoGateInfo[agID][agZ], AutoGateInfo[agID][agrX], AutoGateInfo[agID][agrY], AutoGateInfo[agID][agrZ], 300.0);
  74.     AutoGateInfo[agID][agCreated] = true;
  75.     Iter_Add(AutoGates, agID);
  76.     agID ++;
  77. }
  78.  
  79. /*
  80.  
  81.  • Function: DestroyAutoGate(gateid)
  82.  • Usage: Destroying automatic gate!
  83.  • Parameters:
  84.         gateid: ID of specific gate
  85.  • Example: DestroyAutoGate(1);
  86.  
  87. */
  88.  
  89. stock DestroyAutoGate(gateid)
  90. {
  91.     AutoGateInfo[gateid][agModelID] = 0;
  92.     AutoGateInfo[gateid][agX] = 0.0;
  93.     AutoGateInfo[gateid][agY] = 0.0;
  94.     AutoGateInfo[gateid][agZ] = 0.0;
  95.     AutoGateInfo[gateid][agrX] = 0.0;
  96.     AutoGateInfo[gateid][agrY] = 0.0;
  97.     AutoGateInfo[gateid][agrZ] = 0.0;
  98.     AutoGateInfo[gateid][agNewX] = 0.0;
  99.     AutoGateInfo[gateid][agNewY] = 0.0;
  100.     AutoGateInfo[gateid][agNewZ] = 0.0;
  101.     AutoGateInfo[gateid][agSpeed] = 0.0;
  102.     AutoGateInfo[gateid][agObject] = DestroyObject(AutoGateInfo[gateid][agObject]);
  103.     AutoGateInfo[agID][agCreated] = false;
  104.     Iter_Remove(AutoGates, gateid);
  105. }
  106.  
  107. /*
  108.  
  109.  • Function: GetTotalAutoGates()
  110.  • Usage: Getting all created gates!
  111.  • Parameters:
  112.         no parameteres
  113.  • Example: printf("Total auto gates: %d", GetTotalAutoGates());
  114.  
  115. */
  116.  
  117. stock GetTotalAutoGates() return Iter_Count(AutoGates);
  118.  
  119. /*
  120.  
  121.  • Function: GetAutoGatePos(gateid, &Float: x, &Float: y, &Float: z)
  122.  • Usage: Getting position of gate!
  123.  • Parameters:
  124.         X, Y, Z: Parameters in which will be stored position
  125.  • Example:
  126.  new Float: Pos[3];
  127.  GetAutoGatePos(2, Pos[0], Pos[1], Pos[2]);
  128.  printf("Gate X: %f, Gate Y: %f, Gate Z: %f", Pos[0], Pos[1], Pos[2]);
  129.  
  130. */
  131.  
  132. stock GetAutoGatePos(gateid, &Float: X, &Float: Y, &Float: Z)
  133. {
  134.     X = AutoGateInfo[gateid][agX];
  135.     Y = AutoGateInfo[gateid][agY];
  136.     Z = AutoGateInfo[gateid][agZ];
  137. }
  138.  
  139. /*
  140.  
  141.  • Function: GetAutoGateNewPos(gateid, &Float: x, &Float: y, &Float: z)
  142.  • Usage: Getting new position of autogate!
  143.  • Parameters:
  144.         X, Y, Z: Parameters in which will be stored new position
  145.  • Example:
  146.  new Float: Pos[3];
  147.  GetAutoGateNewPos(2, Pos[0], Pos[1], Pos[2]);
  148.  printf("Gate New X: %f, Gate New Y: %f, Gate New Z: %f", Pos[0], Pos[1], Pos[2]);
  149.  
  150. */
  151.  
  152. stock GetAutoGateNewPos(gateid, &Float: X, &Float: Y, &Float: Z)
  153. {
  154.     X = AutoGateInfo[gateid][agNewX];
  155.     Y = AutoGateInfo[gateid][agNewY];
  156.     Z = AutoGateInfo[gateid][agNewZ];
  157. }
  158.  
  159. /*
  160.  
  161.  • Function: GetAutoGateRot(gateid, &Float: x, &Float: y, &Float: z)
  162.  • Usage: Getting rotation of gate!
  163.  • Parameters:
  164.         X, Y, Z: Parameters in which will be stored rotation
  165.  • Example:
  166.  new Float: Pos[3];
  167.  GetAutoGateRot(2, Pos[0], Pos[1], Pos[2]);
  168.  printf("Gate rot X: %f, Gate rot Y: %f, Gate rot Z: %f", Pos[0], Pos[1], Pos[2]);
  169.  
  170. */
  171.  
  172. stock GetAutoGateRot(gateid, &Float: X, &Float: Y, &Float: Z)
  173. {
  174.     X = AutoGateInfo[gateid][agrX];
  175.     Y = AutoGateInfo[gateid][agrY];
  176.     Z = AutoGateInfo[gateid][agrZ];
  177. }
  178.  
  179. /*
  180.  
  181.  • Function: IsPlayerInRangeOfAutoGate(playerid, gateid, Float: Range)
  182.  • Usage: Checking is player in range of specific gate!
  183.  • Parameters:
  184.         playerid: ID of player
  185.         gateid: ID of gate
  186.         Range: range in which can player be
  187.  • Example:
  188.  if(IsPlayerInRangeOfAutoGate(playerid, 4, 10.0) SendClientMessage(playerid, -1, "You are in range of auto gate 4");
  189.  
  190. */
  191.  
  192. stock IsPlayerInRangeOfAutoGate(playerid, gateid, Float: Range)
  193. {
  194.     if(IsPlayerInRangeOfPoint(playerid, Range, AutoGateInfo[gateid][agX], AutoGateInfo[gateid][agY], AutoGateInfo[gateid][agZ])) return 1;
  195.     return 0;
  196. }
  197.  
  198. /*
  199.  
  200.  • Function: IsPlayerInRangeOfAnyAutoGate(playerid, Float: Range)
  201.  • Usage: Checking is player in range of any gate!
  202.  • Parameters:
  203.         playerid: ID of player
  204.         Range: range in which can player be
  205.  • Example:
  206.  if(IsPlayerInRangeOfAnyAutoGate(playerid, 10.0) SendClientMessage(playerid, -1, "You are in range of some auto gate");
  207.  
  208. */
  209.  
  210. stock IsPlayerInRangeOfAnyAutoGate(playerid, Float: Range)
  211. {
  212.     foreach(AutoGates, ag)
  213.     {
  214.         if(IsPlayerInRangeOfPoint(playerid, Range, AutoGateInfo[ag][agX], AutoGateInfo[ag][agY], AutoGateInfo[ag][agZ])) return 1;
  215.     }
  216.     return 0;
  217. }
  218.  
  219. /*
  220.  
  221.  • Function: GetAutoGateModelID(gateid)
  222.  • Usage: Getting the model of gate!
  223.  • Parameters:
  224.         gateid: ID of gate
  225.  • Example:
  226.  printf("Model ID of gate 2 is: %d", GetAutoGateModelID(2));
  227.  
  228. */
  229.  
  230. stock GetAutoGateModelID(gateid) return AutoGateInfo[gateid][agModelID];
  231.  
  232. /*
  233.  
  234.  • Function: GetAutoGateSpeed(gateid, &Float: Speed)
  235.  • Usage: Getting the speed of gate!
  236.  • Parameters:
  237.         gateid: ID of gate
  238.         Speed: Parametere in which will be stored speed
  239.  • Example:
  240.  new Float: Speed;
  241.  GetAutoGateSpeed(12, Speed);
  242.  printf("Speed of gate 12 is: %f", Speed);
  243.  
  244. */
  245.  
  246. stock GetAutoGateSpeed(gateid, &Float: Speed)
  247. {
  248.     Speed = AutoGateInfo[gateid][agSpeed];
  249. }
  250.  
  251. /*
  252.  
  253.  • Function: IsValidAutoGate(gateid)
  254.  • Usage: Checking is specific gate valid gate!
  255.  • Parameters:
  256.         gateid: ID of gate
  257.  • Example:
  258.  if(IsValidAutoGate(2)) printf("Gate 2 is valid!");
  259.  
  260. */
  261.  
  262. stock IsValidAutoGate(gateid)
  263. {
  264.     if(AutoGateInfo[gateid][agCreated] == true) return 1;
  265.     return 0;
  266. }
  267.  
  268. task CheckAutoGates[500]()
  269. {
  270.     foreach(AutoGates, ag)
  271.     {
  272.         foreach(Player, i)
  273.         {
  274.             if(IsPlayerInRangeOfPoint(i, 10.0, AutoGateInfo[ag][agX], AutoGateInfo[ag][agY], AutoGateInfo[ag][agZ])) AutoGateInfo[ag][agStatus] = 1;
  275.             else AutoGateInfo[ag][agStatus] = 0;
  276.         }
  277.        
  278.         if(AutoGateInfo[ag][agStatus] == 1) MoveObject(AutoGateInfo[ag][agObject], AutoGateInfo[ag][agNewX], AutoGateInfo[ag][agNewY], AutoGateInfo[ag][agNewZ], AutoGateInfo[ag][agSpeed]);
  279.         else MoveObject(AutoGateInfo[ag][agObject], AutoGateInfo[ag][agX], AutoGateInfo[ag][agY], AutoGateInfo[ag][agZ], AutoGateInfo[ag][agSpeed]);
  280.     }
  281.     return 1;
  282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement