s3rious

s3GZS - Gang Zone System v1.3

Mar 3rd, 2012
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.65 KB | None | 0 0
  1. // This is a comment
  2. // uncomment the line below if you want to write a filterscript
  3. //#define FILTERSCRIPT
  4.  
  5. // --- * INCLUDES * ------------------------------------------------------------
  6. #include <a_samp>
  7. #include <s3Zone.pwn>
  8. #include <YSI\y_timers>
  9.                                                     //--------------------------
  10.                                                         #undef MAX_PLAYERS
  11.                                                         #define MAX_PLAYERS 72      // change this to maximum players on your server.
  12.                                                     //--------------------------
  13.  
  14.  
  15. // WARNING: Define your function to get player team ----------------------------
  16. stock GetTeam(playerid)
  17. {
  18.     return playerid;           // change playerid to variable with your team ID (example 'return pInfo[playerid][Team];')
  19. }
  20.  
  21.  
  22.  
  23. // --- * DEFINES * -------------------------------------------------------------
  24. #define     MIN_ENEMIES_TO_WAR      2       // Change to number which you want to start gang war
  25. #define     MAX_TEAMS               6       // Change number of all your teams
  26.  
  27. #define     FOREACH(%0,%1)          for(new %0=0;%0<%1;%0++) if (IsPlayerConnected(%0))
  28.  
  29. // --- * VARIABLES * -----------------------------------------------------------
  30. new OLD_ZONE[ MAX_PLAYERS ],
  31.     NEW_ZONE[ MAX_PLAYERS ]
  32.     ;
  33.    
  34. new PlayerIsEnemy[ MAX_PLAYERS ][ MAX_GANGZONES ],
  35.     TotalEnemies[ MAX_TEAMS ][ MAX_GANGZONES ],
  36.     EnemyTeam[ MAX_GANGZONES ]
  37.     ;
  38.    
  39. new PlayerIsProtector[ MAX_PLAYERS ][ MAX_GANGZONES ],
  40.     TotalProtectors[ MAX_TEAMS ][ MAX_GANGZONES ],
  41.     ProtectTeam[ MAX_GANGZONES ]
  42.     ;
  43.  
  44. new G_WarStarted = false, G_GangZoneInWar = -1, T_GangZone;
  45.  
  46. // --- * BODY * ----------------------------------------------------------------
  47. public OnFilterScriptInit()
  48. {
  49.     print("\n--------------------------------------");
  50.     print(" Blank Filterscript by your name here");
  51.     print("--------------------------------------\n");
  52.     return 1;
  53. }
  54.  
  55. public OnFilterScriptExit()
  56. {
  57.     return 1;
  58. }
  59.  
  60. forward s_OnPlayerDisconnect(playerid);
  61. public s_OnPlayerDisconnect(playerid)
  62. {
  63.     PlayerQuit(playerid);
  64.     return 1;
  65. }
  66.  
  67. forward s_OnPlayerDeath(playerid);
  68. public s_OnPlayerDeath(playerid)
  69. {
  70.     PlayerQuit(playerid);
  71.     return 1;
  72. }
  73.  
  74. Timer:MainBody[1000]()
  75. {
  76.     FOREACH (i, MAX_PLAYERS)
  77.     {
  78.         if (IsPlayerInAnyGangZone(i))
  79.         {
  80.             new zoneid = GetPlayerGangZone(i);
  81.             if (zoneid != NEW_ZONE[ i ])
  82.             {
  83.                 OLD_ZONE[ i ] = NEW_ZONE[ i ];
  84.                 NEW_ZONE[ i ] = zoneid;
  85.             }
  86.             if (NEW_ZONE[ i ] != OLD_ZONE[ i ])
  87.             {
  88.                 OnPlayerChangeGangZone(i, NEW_ZONE[ i ], OLD_ZONE[ i ]);
  89.             }
  90.         }
  91.         else
  92.         {
  93.  
  94.         }
  95.     }
  96. }
  97.  
  98. // --- * FUNCTIONS * -----------------------------------------------------------
  99. forward OnPlayerChangeGangZone(playerid, newzoneid, oldzoneid);
  100. public OnPlayerChangeGangZone(playerid, newzoneid, oldzoneid)
  101. {
  102.     new teamid = GetTeam(playerid);
  103.    
  104.     // War is not started
  105.     if (!G_WarStarted)
  106.     {
  107.         // Player is not owner of this zone - Enemy
  108.         //if (!IsPlayerZoneOwner(playerid, newzoneid))
  109.         if (!PlayerIsEnemy[ playerid ][ newzoneid ] && !IsPlayerZoneOwner(playerid, newzoneid))
  110.         {
  111.             // attack can each member of the team.
  112.             // This write value 1 to this zone.
  113.             SetPlayerEnemy(playerid, teamid, newzoneid);
  114.            
  115.             // It allow players are more than other,
  116.             if (TotalEnemies[ teamid ][ newzoneid ] >= MIN_ENEMIES_TO_WAR)
  117.             {
  118.                 OnPlayerStartGangWar(playerid, newzoneid, teamid);
  119.                
  120.                 GameTextForPlayer(playerid, "~r~YOU START GANG WAR!", 1000*3, 5);
  121.             }
  122.         }
  123.     }
  124.     else
  125.     {
  126.         if (PlayerIsEnemy[ playerid ][ oldzoneid ] || PlayerIsProtector[ playerid ][ oldzoneid ])
  127.         {
  128.        
  129.             // ------ PLAYER HAS LEFT THE GANG WAR ZONE ---------------------
  130.  
  131.             // if oldzone is in gangwar
  132.             if (NEW_ZONE[ playerid ] != G_GangZoneInWar)
  133.             {
  134.                 // If player is owner  ot means decrease Protectors
  135.                
  136.                 //if (IsPlayerZoneOwner(playerid, oldzoneid))
  137.                 if (PlayerIsEnemy[ playerid ][ oldzoneid ] && !IsPlayerZoneOwner(playerid, oldzoneid))
  138.                 {
  139.                     // if enemy left the war zone
  140.                     //if (EnemyTeam[ oldzoneid ] == teamid)
  141.                     //{
  142.                         //
  143.                         PlayerIsEnemy[ playerid ][ oldzoneid ] = 0;
  144.                         TotalEnemies[ teamid ][ oldzoneid ]--;
  145.                        
  146.                         GameTextForPlayer(playerid, "~r~YOU LEFT FROM GANG WAR!", 1000*5, 5);
  147.  
  148.                         if (TotalEnemies[ teamid ][ oldzoneid ] <= 0)
  149.                         {
  150.                             EndGangWar(oldzoneid);
  151.                             GangWarCallBack();
  152.  
  153.                             SendClientMessage(playerid, -1, "Gangwar has ended!");
  154.                         }
  155.                     //}
  156.                 }
  157.                 //else
  158.                 if (PlayerIsProtector[ playerid ][ oldzoneid ] && IsPlayerZoneOwner(playerid, oldzoneid))
  159.                 {
  160.                     PlayerIsProtector[ playerid ][ oldzoneid ] = 0;
  161.                     TotalProtectors[ teamid ][ oldzoneid ]--;
  162.                    
  163.                     GameTextForPlayer(playerid, "~r~YOU LEFT FROM YOUR GANG ZONE!", 1000*5, 5);
  164.  
  165.                     if (TotalProtectors[ teamid ][ oldzoneid ] <= 0)
  166.                     {
  167.                         EndGangWar(oldzoneid);
  168.                         GangWarCallBack();
  169.                        
  170.                         SendClientMessage(playerid, -1, "Gangwar has ended!");
  171.                     }
  172.                 }
  173.             }
  174.         }
  175.         else
  176.         {
  177.             // War is started. In this time players can come to warzone
  178.             if (ProtectTeam[ newzoneid ] == teamid && PlayerIsProtector[ playerid ][ newzoneid ])
  179.             {
  180.                 // player is owner and he can be as Protector of this zone.
  181.                 SetPlayerProtect(playerid, teamid, newzoneid);
  182.  
  183.                 GameTextForPlayer(playerid, "~r~PROTECT YOUR ZONE!!!", 1000*5, 5);
  184.             }
  185.             else
  186.             {
  187.                 // it add only player from EnemyTeam
  188.                 if (EnemyTeam[ newzoneid ] == teamid && !PlayerIsEnemy[ playerid ][ newzoneid ])
  189.                 {
  190.                     // player is not owner and he can be as Enemy for this zone.
  191.                     SetPlayerEnemy(playerid, teamid, newzoneid);
  192.  
  193.                     GameTextForPlayer(playerid, "~r~KILL ALL PROTECTORS OF THIS ZONE!!!", 1000*3, 5);
  194.                 }
  195.             }
  196.         }
  197.     }
  198.     return 1;
  199. }
  200.  
  201. //------------------------------------------------------------------------------
  202.  
  203. forward OnPlayerStartGangWar(playerid, zoneid, teamid);
  204. public OnPlayerStartGangWar(playerid, zoneid, teamid)
  205. {
  206.     // Start flash gang zone
  207.     SetGangZoneFlash(zoneid);
  208.    
  209.     G_WarStarted = true;
  210.    
  211.     //--------------------------------------------------------------------------
  212.    
  213.     // Main set of variable - You shouldn't to change it
  214.     EnemyTeam[ zoneid ] = teamid;
  215.     ProtectTeam[ zoneid ] = GetGangZoneOwner(zoneid);
  216.     G_GangZoneInWar = zoneid;
  217.    
  218.     //--------------------------------------------------------------------------
  219.    
  220.     T_GangZone = SetTimer("GangWarCallBack", 1000*30, false);
  221. }
  222.  
  223. //------------------------------------------------------------------------------
  224.  
  225. forward GangWarCallBack();
  226. public GangWarCallBack()
  227. {
  228.     new
  229.         zoneid = G_GangZoneInWar,
  230.         protectorid = ProtectTeam[ zoneid ],
  231.         enemyid = EnemyTeam[ zoneid ]
  232.     ;
  233.  
  234.     // All protectors were killed and enemies still
  235.     if (TotalEnemies[ enemyid ][ zoneid ] > 0)
  236.     {
  237.         // Protectors still a live
  238.         if (TotalProtectors[ protectorid ][ zoneid ] == 0)
  239.         {
  240.             SetGangZoneOwnerTeam(zoneid, enemyid);
  241.            
  242.             FOREACH(i, MAX_PLAYERS)
  243.             {
  244.                 if (GetTeam(i) == enemyid)
  245.                 {
  246.                     GameTextForPlayer(i, "~g~THIS HOOD IS YOURS!", 1000*4, 5);
  247.                 }
  248.                 else if (GetTeam(i) == protectorid)
  249.                 {
  250.                     GameTextForPlayer(i, "~r~YOU LOST THIS HOOD!", 1000*4, 5);
  251.                 }
  252.             }
  253.         }
  254.     }
  255.     else
  256.     {
  257.            
  258.         FOREACH(playerid, MAX_PLAYERS)
  259.         {
  260.             if (GetTeam(playerid) == protectorid)
  261.             {
  262.                 GameTextForPlayer(playerid, "~r~YOU LOST THIS HOOD", 1000*4, 5);
  263.             }
  264.            
  265.         }
  266.     }
  267.     EndGangWar(zoneid);
  268. }
  269.  
  270. //------------------------------------------------------------------------------
  271.  
  272. stock EndGangWar(zoneid)
  273. {
  274.     // Main set of variable - You shouldn't to change it
  275.     EnemyTeam[ zoneid ]     =   -1;
  276.     ProtectTeam[ zoneid ]   =   -1;
  277.    
  278.     G_GangZoneInWar         =   -1;
  279.    
  280.     for (new i=0;i < MAX_TEAMS; i++)
  281.     {
  282.         TotalEnemies[ i ][ zoneid ]     =   0;
  283.         TotalProtectors[ i ][ zoneid ]  =   0;
  284.     }
  285.    
  286.     FOREACH(i, MAX_PLAYERS)
  287.     {
  288.         PlayerIsEnemy[ i ][ zoneid ]        =       0;
  289.         PlayerIsProtector[ i ][ zoneid ]    =       0;
  290.         GangZoneStopFlashForPlayer(i, zoneid);
  291.     }
  292.  
  293.     //--------------------------------------------------------------------------
  294.  
  295.     G_WarStarted = false;
  296.     KillTimer(T_GangZone);
  297. }
  298.  
  299. forward PlayerQuit(playerid);
  300. public PlayerQuit(playerid)
  301. {
  302.     if (G_WarStarted)
  303.     {
  304.         new teamid = GetTeam(playerid);
  305.  
  306.         if (PlayerIsEnemy[ playerid ][ G_GangZoneInWar ])
  307.         {
  308.             PlayerIsEnemy[ playerid ][ G_GangZoneInWar ] = 0;
  309.             TotalEnemies[ teamid][ G_GangZoneInWar ]--;
  310.  
  311.             if (TotalEnemies[ teamid ][ G_GangZoneInWar ] <= 0)
  312.             {
  313.                 EndGangWar(G_GangZoneInWar);
  314.                 GangWarCallBack();
  315.  
  316.                 SendClientMessage(playerid, -1, "Gangwar has ended!");
  317.             }
  318.         }
  319.         if (PlayerIsProtector[ playerid ][ G_GangZoneInWar ])
  320.         {
  321.             PlayerIsProtector[ playerid ][ G_GangZoneInWar ] = 0;
  322.             TotalProtectors[ teamid][ G_GangZoneInWar ]--;
  323.             if (TotalProtectors[ teamid ][ G_GangZoneInWar ] <= 0)
  324.             {
  325.                 EndGangWar(G_GangZoneInWar);
  326.                 GangWarCallBack();
  327.  
  328.                 SendClientMessage(playerid, -1, "Gangwar has ended!");
  329.             }
  330.         }
  331.     }
  332.     return 1;
  333. }
  334.  
  335. stock IsPlayerZoneOwner(playerid, zoneid)
  336. {
  337.     if (GetGangZoneOwner(zoneid) == GetTeam(playerid))  return 1;
  338.     else return 0;
  339. }
  340.  
  341. //------------------------------------------------------------------------------
  342.  
  343. stock IsZoneInWar(zoneid)
  344. {
  345.     if (zoneid == G_GangZoneInWar)  return 1;
  346.     else return 0;
  347. }
  348.  
  349. stock SetPlayerEnemy(playerid, teamid, zoneid)
  350. {
  351.     PlayerIsEnemy[ playerid ][ zoneid ] = 1;
  352.     TotalEnemies[ teamid ][ zoneid ]++;
  353. }
  354.  
  355. stock SetPlayerProtect(playerid, teamid, zoneid)
  356. {
  357.     PlayerIsProtector[ playerid ][ zoneid ] = 1;
  358.     TotalProtectors[ teamid ][ zoneid ]++;
  359. }
Advertisement
Add Comment
Please, Sign In to add comment