Advertisement
Guest User

Yet Another Taser System

a guest
Jun 1st, 2016
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.47 KB | None | 0 0
  1. #define     FILTERSCRIPT
  2. #include    <a_samp>
  3. #undef      MAX_PLAYERS
  4. #define     MAX_PLAYERS     (100)   // change this according to your maxplayers on server.cfg
  5.  
  6. #include    <progress2>
  7.  
  8. #define     TASER_BASETIME  (3)     // player will get tased for at least 3 seconds
  9. #define     TASER_INDEX     (4)     // setplayerattachedobject index for taser object
  10.  
  11. enum    e_taser
  12. {
  13.     bool: TaserEnabled,
  14.     TaserCountdown,
  15.     GetupTimer,
  16.     TaserUpdate,
  17.     bool: TaserCharged,
  18.     ChargeTimer
  19. };
  20.  
  21. new
  22.     TaserData[MAX_PLAYERS][e_taser],
  23.     PlayerBar: ChargeBar[MAX_PLAYERS];
  24.  
  25. new
  26.     RGY[100] = {
  27.         // http://forum.sa-mp.com/showpost.php?p=3372369&postcount=19
  28.         0xFF0000FF, 0xFF0500FF, 0xFF0A00FF, 0xFF0F00FF, 0xFF1400FF, 0xFF1900FF, 0xFF1E00FF, 0xFF2300FF, 0xFF2800FF, 0xFF2D00FF,
  29.         0xFF3300FF, 0xFF3800FF, 0xFF3D00FF, 0xFF4200FF, 0xFF4700FF, 0xFF4C00FF, 0xFF5100FF, 0xFF5600FF, 0xFF5B00FF, 0xFF6000FF,
  30.         0xFF6600FF, 0xFF6B00FF, 0xFF7000FF, 0xFF7500FF, 0xFF7A00FF, 0xFF7F00FF, 0xFF8400FF, 0xFF8900FF, 0xFF8E00FF, 0xFF9300FF,
  31.         0xFF9900FF, 0xFF9E00FF, 0xFFA300FF, 0xFFA800FF, 0xFFAD00FF, 0xFFB200FF, 0xFFB700FF, 0xFFBC00FF, 0xFFC100FF, 0xFFC600FF,
  32.         0xFFCC00FF, 0xFFD100FF, 0xFFD600FF, 0xFFDB00FF, 0xFFE000FF, 0xFFE500FF, 0xFFEA00FF, 0xFFEF00FF, 0xFFF400FF, 0xFFF900FF,
  33.         0xFFFF00FF, 0xF9FF00FF, 0xF4FF00FF, 0xEFFF00FF, 0xEAFF00FF, 0xE4FF00FF, 0xDFFF00FF, 0xDAFF00FF, 0xD5FF00FF, 0xD0FF00FF,
  34.         0xCAFF00FF, 0xC5FF00FF, 0xC0FF00FF, 0xBBFF00FF, 0xB6FF00FF, 0xB0FF00FF, 0xABFF00FF, 0xA6FF00FF, 0xA1FF00FF, 0x9CFF00FF,
  35.         0x96FF00FF, 0x91FF00FF, 0x8CFF00FF, 0x87FF00FF, 0x82FF00FF, 0x7CFF00FF, 0x77FF00FF, 0x72FF00FF, 0x6DFF00FF, 0x68FF00FF,
  36.         0x62FF00FF, 0x5DFF00FF, 0x58FF00FF, 0x53FF00FF, 0x4EFF00FF, 0x48FF00FF, 0x43FF00FF, 0x3EFF00FF, 0x39FF00FF, 0x34FF00FF,
  37.         0x2EFF00FF, 0x29FF00FF, 0x24FF00FF, 0x1FFF00FF, 0x1AFF00FF, 0x14FF00FF, 0x0FFF00FF, 0x0AFF00FF, 0x05FF00FF, 0x00FF00FF
  38.     };
  39.  
  40. stock IsACopSkin(skinid)
  41. {
  42.     // includes corrupt cops from singleplayer, SWAT, FBI and Army skin and 0.3.7 cop ones
  43.     switch(skinid)
  44.     {
  45.         case 265..267, 280..288, 300..302, 306, 307, 309..311: return 1;
  46.         default: return 0;
  47.     }
  48.  
  49.     return 0;
  50. }
  51.  
  52. public OnFilterScriptInit()
  53. {
  54.     for(new i, maxp = GetPlayerPoolSize(); i <= maxp; ++i)
  55.     {
  56.         if(!IsPlayerConnected(i)) continue;
  57.         TaserData[i][TaserEnabled] = false;
  58.         TaserData[i][TaserCharged] = true;
  59.         TaserData[i][TaserCountdown] = 0;
  60.         TaserData[i][GetupTimer] = -1;
  61.         TaserData[i][ChargeTimer] = -1;
  62.  
  63.         ApplyAnimation(i, "KNIFE", "null", 0.0, 0, 0, 0, 0, 0, 0);
  64.         ApplyAnimation(i, "CRACK", "null", 0.0, 0, 0, 0, 0, 0, 0);
  65.     }
  66.  
  67.     return 1;
  68. }
  69.  
  70. public OnFilterScriptExit()
  71. {
  72.     for(new i, maxp = GetPlayerPoolSize(); i <= maxp; ++i)
  73.     {
  74.         if(!IsPlayerConnected(i)) continue;
  75.         if(!TaserData[i][TaserEnabled]) continue;
  76.         RemovePlayerAttachedObject(i, TASER_INDEX);
  77.         DestroyPlayerProgressBar(i, ChargeBar[i]);
  78.     }
  79.  
  80.     return 1;
  81. }
  82.  
  83. public OnPlayerConnect(playerid)
  84. {
  85.     TaserData[playerid][TaserEnabled] = false;
  86.     TaserData[playerid][TaserCharged] = true;
  87.     TaserData[playerid][TaserCountdown] = 0;
  88.     TaserData[playerid][GetupTimer] = -1;
  89.     TaserData[playerid][ChargeTimer] = -1;
  90.  
  91.     ApplyAnimation(playerid, "KNIFE", "null", 0.0, 0, 0, 0, 0, 0, 0);
  92.     ApplyAnimation(playerid, "CRACK", "null", 0.0, 0, 0, 0, 0, 0, 0);
  93.     return 1;
  94. }
  95.  
  96. public OnPlayerDisconnect(playerid, reason)
  97. {
  98.     if(TaserData[playerid][GetupTimer] != -1)
  99.     {
  100.         KillTimer(TaserData[playerid][GetupTimer]);
  101.         TaserData[playerid][GetupTimer] = -1;
  102.     }
  103.  
  104.     if(TaserData[playerid][ChargeTimer] != -1)
  105.     {
  106.         KillTimer(TaserData[playerid][ChargeTimer]);
  107.         TaserData[playerid][ChargeTimer] = -1;
  108.     }
  109.  
  110.     return 1;
  111. }
  112.  
  113. public OnPlayerUpdate(playerid)
  114. {
  115.     if(TaserData[playerid][TaserEnabled] && TaserData[playerid][TaserUpdate] < tickcount())
  116.     {
  117.         if(GetPlayerWeapon(playerid) == 0) {
  118.             SetPlayerAttachedObject(playerid, TASER_INDEX, 18642, 6, 0.0795, 0.015, 0.0295, 180.0, 0.0, 0.0);
  119.         }else{
  120.             RemovePlayerAttachedObject(playerid, TASER_INDEX);
  121.         }
  122.  
  123.         TaserData[playerid][TaserUpdate] = tickcount()+100;
  124.     }
  125.  
  126.     return 1;
  127. }
  128.  
  129. public OnPlayerCommandText(playerid, cmdtext[])
  130. {
  131.     if(!strcmp(cmdtext, "/taser"))
  132.     {
  133.         if(!IsACopSkin(GetPlayerSkin(playerid))) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only cops can use this command.");
  134.         if(!TaserData[playerid][TaserCharged]) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't use this command while your taser is charging.");
  135.         TaserData[playerid][TaserEnabled] = !TaserData[playerid][TaserEnabled];
  136.         new string[64];
  137.         format(string, sizeof(string), "TASER: {FFFFFF}Taser %s.", (TaserData[playerid][TaserEnabled]) ? ("{2ECC71}on") : ("{E74C3C}off"));
  138.         SendClientMessage(playerid, 0x3498DBFF, string);
  139.  
  140.         if(TaserData[playerid][TaserEnabled]) {
  141.             SetPlayerArmedWeapon(playerid, 0);
  142.             SetPlayerAttachedObject(playerid, TASER_INDEX, 18642, 6, 0.0795, 0.015, 0.0295, 180.0, 0.0, 0.0);
  143.             TaserData[playerid][TaserUpdate] = tickcount()+100;
  144.  
  145.             ChargeBar[playerid] = CreatePlayerProgressBar(playerid, 548.000000, 58.000000, 62.000000, 4.699999, 0x00FF00FF, 100.0, 0);
  146.             SetPlayerProgressBarValue(playerid, ChargeBar[playerid], 100.0);
  147.         }else{
  148.             RemovePlayerAttachedObject(playerid, TASER_INDEX);
  149.             DestroyPlayerProgressBar(playerid, ChargeBar[playerid]);
  150.         }
  151.  
  152.         return 1;
  153.     }
  154.  
  155.     return 0;
  156. }
  157.  
  158. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  159. {
  160.     if(newkeys & KEY_FIRE && TaserData[playerid][TaserEnabled] && GetPlayerWeapon(playerid) == 0 && !IsPlayerInAnyVehicle(playerid) && TaserData[playerid][TaserCharged])
  161.     {
  162.         TaserData[playerid][TaserCharged] = false;
  163.  
  164.         new Float: x, Float: y, Float: z, Float: health, string[64];
  165.         GetPlayerPos(playerid, x, y, z);
  166.         PlayerPlaySound(playerid, 6003, 0.0, 0.0, 0.0);
  167.         ApplyAnimation(playerid, "KNIFE", "KNIFE_3", 4.1, 0, 1, 1, 0, 0, 1);
  168.         SetPlayerProgressBarColour(playerid, ChargeBar[playerid], RGY[0]);
  169.         SetPlayerProgressBarValue(playerid, ChargeBar[playerid], 0.0);
  170.         TaserData[playerid][ChargeTimer] = SetTimerEx("ChargeUp", 100, true, "i", playerid);
  171.  
  172.         for(new i, maxp = GetPlayerPoolSize(); i <= maxp; ++i)
  173.         {
  174.             if(!IsPlayerConnected(i)) continue;
  175.             if(playerid == i) continue;
  176.             if(TaserData[i][TaserCountdown] != 0) continue;
  177.             if(IsPlayerInAnyVehicle(i)) continue;
  178.             if(IsACopSkin(GetPlayerSkin(i))) continue;
  179.             if(GetPlayerDistanceFromPoint(i, x, y, z) > 2.0) continue;
  180.             ClearAnimations(i, 1);
  181.             TogglePlayerControllable(i, false);
  182.             ApplyAnimation(i, "CRACK", "crckdeth2", 4.1, 0, 0, 0, 1, 0, 1);
  183.             PlayerPlaySound(i, 6003, 0.0, 0.0, 0.0);
  184.  
  185.             GetPlayerHealth(i, health);
  186.             TaserData[i][TaserCountdown] = TASER_BASETIME + floatround((100 - health) / 12);
  187.             format(string, sizeof(string), "TASER: {FFFFFF}You got tased for %d seconds!", TaserData[i][TaserCountdown]);
  188.             SendClientMessage(i, 0x3498DBFF, string);
  189.             format(string, sizeof(string), "~n~~n~~n~~b~~h~~h~Taser: ~g~~h~~h~%d", TaserData[i][TaserCountdown]);
  190.             GameTextForPlayer(i, string, 1000, 3);
  191.             TaserData[i][GetupTimer] = SetTimerEx("TaserGetUp", 1000, true, "i", i);
  192.             break;
  193.         }
  194.     }
  195.  
  196.     return 1;
  197. }
  198.  
  199. forward TaserGetUp(playerid);
  200. public TaserGetUp(playerid)
  201. {
  202.     if(TaserData[playerid][TaserCountdown] > 1) {
  203.         new string[48];
  204.         TaserData[playerid][TaserCountdown]--;
  205.         format(string, sizeof(string), "~n~~n~~n~~b~~h~~h~Taser: ~g~~h~~h~%d", TaserData[playerid][TaserCountdown]);
  206.         GameTextForPlayer(playerid, string, 1000, 3);
  207.     }else if(TaserData[playerid][TaserCountdown] == 1) {
  208.         TogglePlayerControllable(playerid, true);
  209.         ClearAnimations(playerid, 1);
  210.         KillTimer(TaserData[playerid][GetupTimer]);
  211.         TaserData[playerid][GetupTimer] = -1;
  212.         TaserData[playerid][TaserCountdown] = 0;
  213.         GameTextForPlayer(playerid, "~n~~n~~n~~g~~h~~h~Taser Effect Clear", 1000, 3);
  214.     }
  215.  
  216.     return 1;
  217. }
  218.  
  219. forward ChargeUp(playerid);
  220. public ChargeUp(playerid)
  221. {
  222.     new Float: charge = GetPlayerProgressBarValue(playerid, ChargeBar[playerid]);
  223.     charge++;
  224.     if(charge >= 100.0)
  225.     {
  226.         charge = 100.0;
  227.         TaserData[playerid][TaserCharged] = true;
  228.         KillTimer(TaserData[playerid][ChargeTimer]);
  229.         TaserData[playerid][ChargeTimer] = -1;
  230.         PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
  231.         SendClientMessage(playerid, 0x3498DBFF, "TASER: {FFFFFF}Taser charged and ready to use.");
  232.     }
  233.  
  234.     if(charge < 100.0) SetPlayerProgressBarColour(playerid, ChargeBar[playerid], RGY[ floatround(charge) ]);
  235.     SetPlayerProgressBarValue(playerid, ChargeBar[playerid], charge);
  236.     return 1;
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement