04.10.2013, 06:34
(
Последний раз редактировалось RafaelZam; 29.10.2013 в 23:39.
Причина: fixed that about ZoneInfo
)
hi guys !
i will show you how to create a Turf War system simple !
well let's go !
firstly we need define the teams !
in my case i will define 3 teams
now that the teams are already defined !
we need define Teams colors
how to define it?
simple we need do something like this !
now that the colors are defined
we need define max teams and the max gang zones
also we need define gTeam[MAX_PLAYERS];
if you don't know how i will show you how
now we need define the zones ! Bases and zones gang capturables
now that the zones are defined we need the coords ! how to get coords?
i use GangZoneMarker made by iPleomax
download it here
https://sampforum.blast.hk/showthread.php?tid=279647
remember that when you get the coords you must change "," to "." change the comma ! dont forget that ! is important !
well we need define ZoneInfo and these thing...!
but we need add before this
now we need create an enum !
somehitng like this..
well now that we have defined the zones we need create a timer !
just add this !
and also add this in OnGameModeInIt
now we have a !killtimer well done guy !
well now if you want define the spawn zones really is not important for you know bcz i guess that you have already defined your teams and the spawns no?
but however i will show you how to do it :'3 !
well now that we defined thats spawns xD or teams skins etc !
we need define the Zones that we defined before, do you remember?
remember that all this are in OnGameModeInIt
thats all i;ve explained all in tthat code
now if you have problems with that i will show you how is OnGameModeInIt
now that you know and have defined all this !
we need go to OnPlayerSpawn and add some codes !
codes simples you know :3 e_E !
something like this(we'll use this code https://sampwiki.blast.hk/wiki/GangZoneShowForAll )
now that we have defined this on OnPlayerSpawn
we will create a forward !
i will explain it in the code so check this
do something like this !
now we need define when a player is in the gang zone to able to capture
something like this
remember that i'm explaining all in the codes so pay atenttion !
well now we need define the colors when a player capture a area or zone !
something like this !
now gonna check if the player is in the zone
well thats all !
hope you like this tutorial
i used this in my gm a works fine !
+rep me if you like and ...if you have internet see you later !
-RafaelZam !
bai
i will show you how to create a Turf War system simple !
well let's go !
firstly we need define the teams !
in my case i will define 3 teams
pawn Код:
//Here we will define the teams !
#define TEAM_GROOVE 0
#define TEAM_BALLAS 1
#define TEAM_VAGOS 2
we need define Teams colors
how to define it?
simple we need do something like this !
pawn Код:
//We will define the colors of the team
#define GROOVE_COLOR 0x0FEA1F96 //here we define that Groove team will be green
#define BALLAS_COLOR 0xBC0EC096 // here we define that Ballas team is rose
#define VAGOS_COLOR 0xDFEF1F96 // here we define that vagos team is yellow
we need define max teams and the max gang zones
pawn Код:
#define MAX_ZONES 3
//this will change if you have other zone, example if you have 5 zones or 5 gang zones you must change this for 5 and if is 6 change it to 6 etc..!
#define MAX_TEAMS 3
if you don't know how i will show you how
pawn Код:
new gTeam[MAX_PLAYERS]; //you need define this i will explain later !
pawn Код:
//defining zones...!
//well we need define some zones here ! something like this !
//here also we will define the bases for the players !
new GROOVEZ;
new BALLASZ;
new VAGOSZ;
//for the bases will be something like this
new GROOVEB;
new BALLASB;
new VAGOSB; //you can change the name ^ of this ^ whatever do you want !
//now that Bases and Zones are defined we gotta go to OnGameModeInIt
i use GangZoneMarker made by iPleomax
download it here
https://sampforum.blast.hk/showthread.php?tid=279647
remember that when you get the coords you must change "," to "." change the comma ! dont forget that ! is important !
well we need define ZoneInfo and these thing...!
but we need add before this
now we need create an enum !
somehitng like this..
pawn Код:
enum Z_Info
{
Float:z_minx,
Float:z_miny,
Float:z_maxx,
Float:z_maxy,
z_team, //team
z_id //the id
}
pawn Код:
new ZoneTakeOverTeam[MAX_ZONES];// and this
new ZoneTakeOverTime[MAX_ZONES]; //fixed, define this too !
new ZoneInfo[MAX_ZONES][Z_Info] = {
//here we need post the coord of zones that are capturable
{2437.5,-1722.65625,2525.390625,-1634.765625, TEAM_GROVE},//an example, but this gang zone are defined as GROVEB in OnGameModeInIt
{x,y,z, TEAM_BALLAS},
{x,y,z, TEAM_VAGOS} //here without a comma ,
}; //close
//remember that if you have 4 5 6..etc or more zones capturables you must change #define MAX_ZONES 3 this to the numbers of zones that are you getting.. in this case is 3
just add this !
pawn Код:
//new savetimer;
new zonetimer; // here we define the timer !!! in the zone
pawn Код:
KillTimer(zonetimer);//We need define this to define the kill time(You don't say)
well now if you want define the spawn zones really is not important for you know bcz i guess that you have already defined your teams and the spawns no?
but however i will show you how to do it :'3 !
pawn Код:
//Here we define the spawn of the players ! and here we can define a base if you want, but that base aren't capturable
AddPlayerClass(107,2478.6343,-1662.2228,13.3438,249.9869,0,0,0,0,0,0); // GROOVE SPAWN
AddPlayerClass(104,1961.4006,-1152.5022,26.0251,249.9869,0,0,0,0,0,0); // BALLAS SAWN
AddPlayerClass(108,2804.2061,-1092.7837,30.7285,251.2403,0,0,0,0,0,0); // vagos spawn
//AddPlayerClass(skinid, coord:x, Coord:y, COord:z, angle, here we can add weapons too, weapon ammo, weap2,ammo2,weap3,ammo3);
//we need close it with a ; to avoid many errors !
//This is a example
we need define the Zones that we defined before, do you remember?
remember that all this are in OnGameModeInIt
pawn Код:
//well now we need define the BASES ZONES AND ZONES CAPTURABLES !
//Here we need do something like this !
GROOVEZ = GangZoneCreate(2229.4921875,-1731.4453125,2326.171875,-1666.9921875); //here we define that GROOVE zone is now a gang zone but still isn't capturable
BALLASZ = GangZoneCreate(1851.5625,-1453.125,1974.609375,-1353.515625); //same as GROOVE
VAGOSZ = GangZoneCreate(2452.1484375,-1262.6953125,2563.4765625,-1201.171875); //Like groove and ballas
//now we gonna define the bases
GROOVEB = GangZoneCreate(2437.5,-1722.65625,2525.390625,-1634.765625); //here we defined the bases are not capturables but are defined now
BALLASB = GangZoneCreate(1869.140625,-1265.625,2059.5703125,-1148.4375); //now we need show the players that the zone is created go to OnPlayerSpawn
VAGOSB = GangZoneCreate(2742.1875,-1262.6953125,2841.796875,-1163.0859375); // :D !
//now after do these things ! we must define this (is important)
//this for the zones this define that we gonna take a zone and will be capturable but still don't define what zone is capturable
for(new i=0; i<MAX_ZONES; i++)
{
ZoneInfo[i][z_id] = GangZoneCreate(ZoneInfo[i][z_minx], ZoneInfo[i][z_miny], ZoneInfo[i][z_maxx], ZoneInfo[i][z_maxy]);
ZoneTakeOverTeam[i] = -1;
}
now if you have problems with that i will show you how is OnGameModeInIt
pawn Код:
public OnGameModeInit()
{
// Don't use these lines if it's a filterscript
SetGameModeText("Blank Script");
KillTimer(zonetimer);//We need define this to define the kill time(You don't say)
//Here we define the spawn of the players ! and here we can define a base if you want, but that base aren't capturable
AddPlayerClass(107,2478.6343,-1662.2228,13.3438,249.9869,0,0,0,0,0,0); // GROOVE SPAWN
AddPlayerClass(104,1961.4006,-1152.5022,26.0251,249.9869,0,0,0,0,0,0); // BALLAS SAWN
AddPlayerClass(108,2804.2061,-1092.7837,30.7285,251.2403,0,0,0,0,0,0); // vagos spawn
//AddPlayerClass(skinid, coord:x, Coord:y, COord:z, angle, here we can add weapons too, weapon ammo, weap2,ammo2,weap3,ammo3);
//we need close it with a ; to avoid many errors !
//This is a example
//i will add a base but later ! i will explain it too ! don't worry
//well now we need define the BASES ZONES AND ZONES CAPTURABLES !
//Here we need do something like this !
GROOVEZ = GangZoneCreate(2229.4921875,-1731.4453125,2326.171875,-1666.9921875); //here we define that GROOVE zone is now a gang zone but still isn't capturable
BALLASZ = GangZoneCreate(1851.5625,-1453.125,1974.609375,-1353.515625); //same as GROOVE
VAGOSZ = GangZoneCreate(2452.1484375,-1262.6953125,2563.4765625,-1201.171875); //Like groove and ballas
//now we gonna define the bases
GROOVEB = GangZoneCreate(2437.5,-1722.65625,2525.390625,-1634.765625); //here we defined the bases are not capturables but are defined now
BALLASB = GangZoneCreate(1869.140625,-1265.625,2059.5703125,-1148.4375); //now we need show the players that the zone is created go to OnPlayerSpawn
VAGOSB = GangZoneCreate(2742.1875,-1262.6953125,2841.796875,-1163.0859375); // :D !
//now after do these things ! we must define this (is important)
//this for the zones this define that we gonna take a zone and will be capturable but still don't define what zone is capturable
for(new i=0; i<MAX_ZONES; i++)
{
ZoneInfo[i][z_id] = GangZoneCreate(ZoneInfo[i][z_minx], ZoneInfo[i][z_miny], ZoneInfo[i][z_maxx], ZoneInfo[i][z_maxy]);
ZoneTakeOverTeam[i] = -1;
}
return 1;
}
we need go to OnPlayerSpawn and add some codes !
codes simples you know :3 e_E !
something like this(we'll use this code https://sampwiki.blast.hk/wiki/GangZoneShowForAll )
pawn Код:
public OnPlayerSpawn(playerid)
{
for(new i=0; i<MAX_ZONES; i++)
{
GangZoneShowForPlayer(playerid, ZoneInfo[i][z_id], GetTeamColor(ZoneInfo[i][z_team]));
if(ZoneTakeOverTeam[i] != -1) GangZoneFlashForPlayer(playerid, ZoneInfo[i][z_id], GetTeamColor(ZoneTakeOverTeam[i]));
}
GangZoneShowForAll(GROOVEZ, 0x0FEA1F96); //this define the colors of the zones !
GangZoneShowForAll(BALLASZ, 0xBC0EC096);
GangZoneShowForAll(VAGOSZ, 0x0FEA1F96);
//Now the bases
GangZoneShowForAll(GROOVEB, 0x0FEA1F96);
GangZoneShowForAll(VAGOSB, 0xDFEF1F96);//now we must define something
GangZoneShowForAll(BALLASB, 0xBC0EC096);//what we gonna explain and create now? we need a forward a new funtion ! c'mon !
return 1;
}
we will create a forward !
i will explain it in the code so check this
do something like this !
pawn Код:
//Here we will post the code of the new Funtion !
//what do this funtion? this send a message and send the score and check if a player is in the zone check if
//3 users are in the zone to start to capture the zone !
//check the time that you must stay to capture the zone !
//i;m gonna explain the funtion !
forward ZoneUpdate();
public ZoneUpdate()
{
for(new z=0; z < MAX_ZONES; z++)
{
if(ZoneTakeOverTeam[z] == -1)
{
for(new t=0; t < MAX_TEAMS; t++)
{
if(t == ZoneInfo[z][z_team]) continue;
if(GetMembersInZone(z, t) >= 3) //this you can change ! if you change this to 1, you can capture a zone with 1 player and don't need more help !
{
ZoneTakeOverTeam[z] = t;
GangZoneFlashForAll(ZoneInfo[z][z_id], GetTeamColor(t));// this is when you are in the zone start to attack it, and will change of color !
ZoneTakeOverTime[z] = 0;
}
}
}
else
{
if(GetMembersInZone(z, ZoneTakeOverTeam[z]) > 0)
{
ZoneTakeOverTime[z]++;
if(ZoneTakeOverTime[z] >= 30)//this is the time that you need wait to capture the zone, now is 30 seconds but you can change it ! :D !
{
GangZoneStopFlashForAll(ZoneInfo[z][z_id]);
GangZoneShowForAll(ZoneInfo[z][z_id], GetTeamColor(ZoneTakeOverTeam[z]));///here if you capture the zones, the zone will change to the color of your team !
ZoneInfo[z][z_team] = ZoneTakeOverTeam[z];
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))//above, checks if you are online
{
if(GetPlayerZone(i) == z && gTeam[i] == ZoneTakeOverTeam[z])//this checks if you capture the gang zone !
{
SetPlayerScore(i, GetPlayerScore(i) + 2);//here if u capture the zone will give you 2 of score you can change it to 5 20 523 :D
pInfo[i][Kills] += 2;//will add you 2 kills
GameTextForPlayer(i, "~g~Turf ~r~taken over~n~~b~~h~+2 score", 6000, 3);// this is the message when you capture the zone
}
}
}
ZoneTakeOverTeam[z] = -1;
ZoneTakeOverTime[z] = 0;
}
}
else
{
ZoneTakeOverTeam[z] = -1;
GangZoneStopFlashForAll(ZoneInfo[z][z_id]);//this shows to all players when the zone is attacked and when is captured (with the ned color)
ZoneTakeOverTime[z] = 0;
}
}
}
}
something like this
remember that i'm explaining all in the codes so pay atenttion !
pawn Код:
//now we need define more things ! with this you can check if a player is the gang zone ! if no, isn't able to capture the zone (logic)
//im gonna to explain !
GetMembersInZone(zoneid, team)
{
new count = 0; // you do here a new count ! above
new Float:px, Float:py, Float:pz; //this to check if the players is in the x gang zone !
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))///checks if you are online
{
if(GetPlayerState(i) != PLAYER_STATE_WASTED && gTeam[i] == team)//this checks if you are in Wasted state !
{
GetPlayerPos(i, px, py, pz);//gets your position and start to capture the zone !
if(px > ZoneInfo[zoneid][z_minx] && py > ZoneInfo[zoneid][z_miny] && px < ZoneInfo[zoneid][z_maxx] && py < ZoneInfo[zoneid][z_maxy])//this gets the zone info where are you possioned !
{
count++;
}
}
}
}
return count;
}
something like this !
pawn Код:
//now we need define the colors of the teams
//ups not of the teams of the gang zones when you capture for example
// case:TEAM_GROOVE: return 0x0FEA1F96 thats says that if a user that is using
//Groove team will capture with the color GReen this is the code of the color green 0x0FEA1F96
GetTeamColor(team)
{
switch(team)
{
case TEAM_GROOVE: return 0x0FEA1F96;//we define the colors i explained before
case TEAM_BALLAS: return 0xBC0EC096;
case TEAM_VAGOS: return 0xDFEF1F96;// :D continue !
}
return 0;
}
pawn Код:
stock GetPlayerZone(playerid)
{
if(GetPlayerState(playerid) != PLAYER_STATE_WASTED)//waa this?, this get the zone that we are attacking in the momment !, this checks if the zone is capturable or not !
{
new Float:px, Float:py, Float:pz;//here gets the coords !
GetPlayerPos(playerid, px, py, pz);//gets your position !
for(new i=0; i<MAX_ZONES; i++)//to all players
{
if(px > ZoneInfo[i][z_minx] && py > ZoneInfo[i][z_miny] && px < ZoneInfo[i][z_maxx] && py < ZoneInfo[i][z_maxy]) return i;
}//and finito ! already we defined all zones capturables and zones not capturables
}
return -1;
}
hope you like this tutorial
i used this in my gm a works fine !
+rep me if you like and ...if you have internet see you later !
-RafaelZam !
bai