Advertisement
Guest User

Teargas System

a guest
Apr 2nd, 2013
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 5.71 KB | None | 0 0
  1. //==========================[Information]=============================
  2. /*
  3.     @title Teargas - V.2
  4.     @author Carlton
  5.     @copyright (c) 2010
  6.    
  7.     @information
  8.         The old Teargas system, i've made in March was clearly bugged,
  9.         I had some freetime on my shoulders and decided to remake it.
  10.        
  11.         The old Teargas bugs included:
  12.             - Only the first teargas thrown will work.
  13.             - Teargas Objects wouldn't disappear.
  14.             - (Not really a bug) You would do a crack animation.
  15.            
  16.         I decided to use the object instead of the usless functions I did
  17.         in the past version.
  18.  
  19.         This version was building for accuracy, unlike the old version, when
  20.         the objects would float into the air, thanks to Kye and his Map Andreas
  21.         plugin, this is no longer in effect (http://forum.sa-mp.com/index.php?topic=145196.0)
  22.         Now when you're near the teargases, any of them, you will cough.
  23.  
  24.     www.epic-missions.co.cc
  25. */
  26. //==========================[End]=============================
  27. //==========================[Includes]=============================
  28. #include <a_samp> // www.sa-mp.com
  29. #include <mapandreas> // http://forum.sa-mp.com/index.php?topic=145196.0
  30. //==========================[Configuration]=============================
  31. #define TOTAL_ALLOWED_TEARGAS 50 // The max amount of teargas allowed to be used.
  32. //#define HOLD_GAS_ENABLED // This feature is bugged, it's not suggested to enable this.
  33. //#define DEBUG_MODE // If enabled, this FS's debug mode will be enabled.
  34. //=========================[OnPlayerKeyStateChange defines]===============================
  35. #define PRESSED(%0) \
  36.     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  37. #define HOLDING(%0) \
  38.     ((newkeys & (%0)) == (%0))
  39. //==========================[Enums & Variables]=============================
  40. enum TGData {
  41.     Float:Pos[3],
  42. }
  43. new
  44.     TearGasData[TOTAL_ALLOWED_TEARGAS][TGData],
  45.     GasUsed,
  46.     TearGasTimer,
  47.     bool:TimerStarted,
  48.     Float:pPos[3];
  49. //==========================[Functions]=============================
  50. stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
  51. {
  52.     new Float:a;
  53.     GetPlayerPos(playerid, x, y, a);
  54.     GetPlayerFacingAngle(playerid, a);
  55.     if (GetPlayerVehicleID(playerid))
  56.     {
  57.         GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
  58.     }
  59.     x += (distance * floatsin(-a, degrees));
  60.     y += (distance * floatcos(-a, degrees));
  61. }
  62. //==========================[Timer functions]=============================
  63. forward StopTheEffect(gasid);
  64. public StopTheEffect(gasid) {
  65.     GasUsed --;
  66.     return 1;
  67. }
  68. forward EffectOfGas();
  69. public EffectOfGas() {
  70.     if(GasUsed == 0) {
  71.         KillTimer(TearGasTimer);
  72.     }
  73.     for(new i = 0; i < MAX_PLAYERS; i ++ ) {
  74.         if(IsPlayerConnected(i)) {
  75.             for(new g = 0; g < GasUsed; g ++ ){
  76.                 if(IsPlayerInRangeOfPoint(i, 10.0, TearGasData[g][Pos][0], TearGasData[g][Pos][1], TearGasData[g][Pos][2])) {
  77.                     if(GetPVarInt(i, "InAnim") == 0) {
  78.                         ApplyAnimation(i,"ped","gas_cwr",4.1,0,1,1,0,0);
  79.                         SetPVarInt(i, "InAnim", 1);
  80.                         #if defined DEBUG_MODE
  81.                             printf("Yes: %d|%d", GetPVarInt(i, "InAnim"), g);
  82.                         #endif
  83.                     }
  84.                     else {
  85.                         ApplyAnimation(i,"ped","gas_cwr",4.1,0,1,1,0,0);
  86.                     }
  87.                 }
  88.                 else {
  89.                     if(GetPVarInt(i, "InAnim") == 1) {
  90.                         SetPVarInt(i, "InAnim", 0);
  91.                         #if defined DEBUG_MODE
  92.                             printf("No: %d|%d", GetPVarInt(i, "InAnim"), g);
  93.                         #endif
  94.                     }
  95.                 }
  96.             }
  97.         }
  98.     }
  99.     return 1;
  100. }
  101. //==========================[Public functions]=============================
  102. public OnFilterScriptInit() {
  103.     MapAndreas_Init(MAP_ANDREAS_MODE_FULL);
  104.     GasUsed = 0;
  105.     return 1;
  106. }
  107. public OnPlayerConnect(playerid) {
  108.     ApplyAnimation(playerid,"ped","null",0.0,0,0,0,0,0);
  109.     SetPVarInt(playerid, "InAnim", 0);
  110.     #if defined HOLD_GAS_ENABLED
  111.         SetPVarInt(playerid, "Holding", 0);
  112.     #endif
  113.     return 1;
  114. }
  115. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
  116.     if (PRESSED(KEY_FIRE)) {
  117.         if(GetPlayerWeapon(playerid) == 17) {
  118.             GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
  119.             GetXYInFrontOfPlayer(playerid, pPos[0], pPos[1], 10.0);
  120.             MapAndreas_FindZ_For2DCoord(pPos[0]+5, pPos[1]+5, pPos[2]);
  121.             TearGasData[GasUsed][Pos][0] = pPos[0];
  122.             TearGasData[GasUsed][Pos][1] = pPos[1];
  123.             TearGasData[GasUsed][Pos][2] = pPos[2];
  124.             SetTimerEx("StopTheEffect", 20000, 0, "d", GasUsed);
  125.             GasUsed ++;
  126.             if(TimerStarted == false) {
  127.                 TearGasTimer = SetTimer("EffectOfGas", 100, 1);
  128.                 TimerStarted = true;
  129.             }
  130.         }
  131.     }
  132.     #if defined HOLD_GAS_ENABLED
  133.         if(HOLDING(KEY_FIRE)) {
  134.               if(GetPlayerWeapon(playerid) == 17) {
  135.                 SetPVarInt(playerid, "Holding", 1);
  136.                 GasUsed --;
  137.                 GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
  138.                 GetXYInFrontOfPlayer(playerid, pPos[0], pPos[1], 36.0);
  139.                 MapAndreas_FindZ_For2DCoord(pPos[0], pPos[1], pPos[2]);
  140.                 TearGasData[GasUsed][Pos][0] = pPos[0];
  141.                 TearGasData[GasUsed][Pos][1] = pPos[1];
  142.                 #if defined DEBUG_MODE
  143.                     CreatePickup(1248, 1, pPos[0], pPos[1], pPos[2]+5); // Debug
  144.                     SetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]); // Debug
  145.                 #endif
  146.                 TearGasData[GasUsed][Pos][2] = pPos[2];
  147.                 SetTimerEx("StopTheEffect", 20000, 0, "d", GasUsed);
  148.                 GasUsed ++;
  149.                 if(TimerStarted == false) {
  150.                     TearGasTimer = SetTimer("EffectOfGas", 100, 1);
  151.                     TimerStarted = true;
  152.                 }
  153.             }
  154.         }
  155.     #endif
  156.     return 1;
  157. }
  158. //==========================[End]=============================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement