s3rious

s3GZS - Gang Zone System

Mar 2nd, 2012
1,439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.94 KB | None | 0 0
  1. /*
  2.     @author:    s3rious
  3.     @name:      s3GZS - Gang Zone System
  4.     @ver:       1.0
  5.  
  6.                                                                     in 2012
  7. */
  8.  
  9. // Includes --------------------------------------------------------------------
  10. #include <a_samp>
  11. #include <YSI\y_timers>
  12. #include <s3Zone.pwn>
  13.  
  14. //------------------------------------------------------------------------------
  15.  
  16.  
  17.  
  18. // WARNING: Define your function to get player team ---------.------------------
  19. /*stock GetTeam(playerid)
  20. {
  21.     return playerid;           // change playerid to variable with your team ID (example 'return pInfo[playerid][Team];')
  22. }*/
  23.  
  24.  
  25.  
  26. // Defines ---------------------------------------------------------------------
  27. #define FOREACH(%0,%1)      for(new %0=0;%0<%1;%0++) if(IsPlayerConnected(%0))
  28.  
  29. #define MAX_ATTACKERS   2           // Max attackers need to start the gang war (this attackers must be on the same turf).
  30.  
  31. //------------------------------------------------------------------------------
  32. enum s3_ENUM_DATA
  33.     {
  34.         P_Attacker,
  35.         P_Protector
  36.     };
  37.  
  38. new
  39.     S_AttackTeam = -1,
  40.     S_ProtectTeam = -1,
  41.     S_Protectors = 0,
  42.     S_Attackers = 0,
  43.     G_GangZoneInWar = -1,
  44.     G_WarStarted = false,
  45.     T_GangZone
  46.     ;
  47.  
  48. new
  49.     s3_DATA[ MAX_PLAYERS ][ s3_ENUM_DATA ],
  50.     NEW_ZONE[ MAX_PLAYERS ],
  51.     OLD_ZONE[ MAX_PLAYERS ]
  52.     ;
  53.  
  54. forward s_OnPlayerDisconnect(playerid);
  55. public s_OnPlayerDisconnect(playerid)
  56. {
  57.     if (G_WarStarted)
  58.     {
  59.         if (IsPlayerAsProtector(playerid))
  60.         {
  61.             S_Protectors--;
  62.             s3_DATA[ playerid ][ P_Protector ] = 0;
  63.         }
  64.         if (IsPlayerAsAttacker(playerid))
  65.         {
  66.             S_Attackers--;
  67.             s3_DATA[ playerid ][ P_Attacker ] = 0;
  68.         }
  69.     }
  70.     return 1;
  71. }
  72. forward s_OnPlayerDeath(playerid);
  73. public s_OnPlayerDeath(playerid)
  74. {
  75.     if (G_WarStarted)
  76.     {
  77.         if (IsPlayerAsProtector(playerid))
  78.         {
  79.             S_Protectors--;
  80.             s3_DATA[ playerid ][ P_Protector ] = 0;
  81.         }
  82.         if (IsPlayerAsAttacker(playerid))
  83.         {
  84.             S_Attackers--;
  85.             s3_DATA[ playerid ][ P_Attacker ] = 0;
  86.         }
  87.     }
  88.     return 1;
  89. }
  90.  
  91. forward OnPlayerStartGangWar(playerid, zoneid);
  92. public OnPlayerStartGangWar(playerid, zoneid)
  93. {
  94.     // Start flash gang zone
  95.     SetGangZoneFlash(zoneid);
  96.  
  97.     G_WarStarted = true;
  98.  
  99.     S_ProtectTeam = GetGangZoneOwner(zoneid);
  100.     S_AttackTeam = GetTeam(playerid);
  101.     G_GangZoneInWar = zoneid;
  102.    
  103.     /*
  104.         ---------------------------------------------------------
  105.  
  106.         HERE YOU CAN PASTE WHATEVER YOU WANT. WHAT HAVE TO HAPPEN
  107.         WHEN GANG WAR BEGIN.
  108.        
  109.         Example - Send all attacker message about War or protectors.
  110.        
  111.         ---------------------------------------------------------
  112.     */
  113.  
  114.     T_GangZone = SetTimer("OnGangZoneWarFinish", 1000*30, false);
  115. }
  116.  
  117. stock SetPlayerAsProtector(playerid)
  118. {
  119.     s3_DATA[ playerid ][ P_Protector ] = 1;
  120.     S_Protectors++;
  121.     return 1;
  122. }
  123.  
  124. stock IsPlayerAsProtector(playerid)
  125. {
  126.     if (s3_DATA[ playerid ][ P_Protector ]) return 1;
  127.     else return 0;
  128. }
  129.  
  130. stock SetPlayerAsAttacker(playerid)
  131. {
  132.     s3_DATA[ playerid ][ P_Attacker ] = 1;
  133.     S_Attackers++;
  134.     return 1;
  135. }
  136.  
  137. stock IsPlayerAsAttacker(playerid)
  138. {
  139.     if (s3_DATA[ playerid ][ P_Attacker ]) return 1;
  140.     else return 0;
  141. }
  142.  
  143. forward OnGangZoneWarFinish();
  144. public OnGangZoneWarFinish()
  145. {
  146.     if (S_Attackers > 0)
  147.     {
  148.         if (S_Protectors == 0)
  149.         {
  150.             // enemies take out the zone
  151.             SetGangZoneOwnerTeam(G_GangZoneInWar, S_AttackTeam);
  152.  
  153.             FOREACH(playerid, MAX_PLAYERS)
  154.             {
  155.                 if (GetTeam(playerid) == S_AttackTeam)
  156.                 {
  157.                     GameTextForPlayer(playerid, "~g~THIS HOOD IS YOURS!", 1000*3, 5);
  158.                 }
  159.                 if (GetTeam(playerid) == S_ProtectTeam)
  160.                 {
  161.                     GameTextForPlayer(playerid, "~r~YOU'VE LOST THIS HOOD", 1000*3, 5);
  162.                 }
  163.             }
  164.         }
  165.     }
  166.     else
  167.     {
  168.         FOREACH(playerid, MAX_PLAYERS)
  169.         {
  170.             if (GetTeam(playerid) == S_ProtectTeam)
  171.             {
  172.                 GameTextForPlayer(playerid, "~g~YOU PROTECTED YOUR GANG ZONE", 1000*3, 5);
  173.             }
  174.         }
  175.     }
  176.     EndGangWar();
  177. }
  178.  
  179. Timer:GZCallback[1000]()
  180. {
  181.     FOREACH(i, MAX_PLAYERS)
  182.     {
  183.         new zoneid = GetPlayerGangZone(i);
  184.         if (IsPlayerInAnyGangZone(i))
  185.         {
  186.             if (NEW_ZONE[ i ] != zoneid)    // if zone has changed
  187.             {
  188.                 OLD_ZONE[ i ] = NEW_ZONE[ i ];
  189.                 NEW_ZONE[ i ] = zoneid;
  190.             }
  191.  
  192.             // if new zone isn't same as old
  193.             if (NEW_ZONE[ i ] != OLD_ZONE[ i ])
  194.             {
  195.                 OnPlayerChangeGangZone(i);
  196.             }
  197.         }
  198.         else
  199.         {
  200.             if(NEW_ZONE[ i ] == -1)
  201.             {
  202.                 if (s3_DATA[ i ][ P_Attacker ])
  203.                 {
  204.                     s3_DATA[ i ][ P_Attacker ] = 0;
  205.                     S_Attackers--;
  206.  
  207.                     GameTextForPlayer(i, "~r~YOU LEFT FROM GANG WAR", 1000*3, 5);
  208.  
  209.                     if (S_Attackers <= 0)
  210.                     {
  211.                         OnGangZoneWarFinish();
  212.  
  213.                         SendClientMessage(i, -1, "Gangwar has ended!");
  214.                     }
  215.                 }
  216.                 if (s3_DATA[ i ][ P_Protector ])
  217.                 {
  218.                     s3_DATA[ i ][ P_Protector ] = 0;
  219.                     S_Protectors--;
  220.  
  221.                     GameTextForPlayer(i, "~r~YOU LEFT FROM GANG WAR", 1000*3, 5);
  222.  
  223.                     if (S_Protectors <= 0)
  224.                     {
  225.                         OnGangZoneWarFinish();
  226.  
  227.                         SendClientMessage(i, -1, "Gangwar has ended!");
  228.                     }
  229.                 }
  230.             }
  231.         }
  232.     }
  233. }
  234.  
  235. forward OnPlayerChangeGangZone(playerid);
  236. public OnPlayerChangeGangZone(playerid)
  237. {
  238.     // If in this zone run war
  239.     if (G_WarStarted)
  240.     {
  241.         if (s3_DATA[ playerid ][ P_Protector ] || s3_DATA[ playerid ][ P_Attacker ])
  242.         {
  243.             if (NEW_ZONE[ playerid ] != G_GangZoneInWar)
  244.             {
  245.                 if (s3_DATA[ playerid ][ P_Attacker ])
  246.                 {
  247.                     s3_DATA[ playerid ][ P_Attacker ] = 0;
  248.                     S_Attackers--;
  249.                    
  250.                     GameTextForPlayer(playerid, "~r~YOU LEFT FROM GANG WAR", 1000*3, 5);
  251.                    
  252.                     if (S_Attackers <= 0)
  253.                     {
  254.                         OnGangZoneWarFinish();
  255.                        
  256.                         SendClientMessage(playerid, -1, "Gangwar has ended!");
  257.                     }
  258.                 }
  259.                 if (s3_DATA[ playerid ][ P_Protector ])
  260.                 {
  261.                     s3_DATA[ playerid ][ P_Protector ] = 0;
  262.                     S_Protectors--;
  263.                    
  264.                     GameTextForPlayer(playerid, "~r~YOU LEFT FROM GANG WAR", 1000*3, 5);
  265.                    
  266.                     if (S_Protectors <= 0)
  267.                     {
  268.                         OnGangZoneWarFinish();
  269.                        
  270.                         SendClientMessage(playerid, -1, "Gangwar has ended!");
  271.                     }
  272.                 }
  273.             }
  274.         }
  275.         else
  276.         {
  277.             if (GetTeam(playerid) == S_AttackTeam)  SetPlayerAsAttacker(playerid);
  278.             if (GetTeam(playerid) == S_ProtectTeam)     SetPlayerAsProtector(playerid);
  279.         }
  280.     }
  281.     else
  282.     {
  283.         if (GetTeam(playerid) != GetGangZoneOwner(NEW_ZONE[ playerid ]))
  284.         {
  285.             if (!s3_DATA[ playerid ][ P_Attacker ])
  286.             {
  287.                 SetPlayerAsAttacker(playerid);
  288.  
  289.                 // if attackers is more than MAX_ATTACKERS
  290.                 if (S_Attackers >= MAX_ATTACKERS)
  291.                 {
  292.                     OnPlayerStartGangWar(playerid, NEW_ZONE[ playerid ]);
  293.                     GameTextForPlayer(playerid, "~r~YOU START GANG WAR", 1000*3, 5);
  294.                 }
  295.             }
  296.         }
  297.     }
  298. }
  299.  
  300. stock EndGangWar()
  301. {
  302.     FOREACH(playerid, MAX_PLAYERS)
  303.     {
  304.         s3_DATA[ playerid ][ P_Attacker ] = 0;
  305.         s3_DATA[ playerid ][ P_Protector ] = 0;
  306.         GangZoneStopFlashForPlayer(playerid, G_GangZoneInWar);
  307.     }
  308.  
  309.     S_AttackTeam = -1;
  310.     S_ProtectTeam = -1;
  311.  
  312.     S_Protectors = 0;
  313.     S_Attackers = 0;
  314.  
  315.     G_GangZoneInWar = -1;
  316.  
  317.     G_WarStarted = false;
  318.     KillTimer(T_GangZone);
  319. }
Advertisement
Add Comment
Please, Sign In to add comment