28.03.2014, 10:03
Hi,
I thought this tutorial might be useful for some people who work on a TDM/DM servers, this tutorial will 'probably' teach you how to keep players within the allowed area only, getting out will kill them(how sad).
Anyway, here we begin:
Now, this:
Max should ALWAYS be the bigger number, if not, everywhere will be out of boundaries! So be careful.
Replace them with your preferred co-ordinates. These co-ordinates are from the abandoned airport to that big bridge.
Now under OnGameModeInit() :
We have created the zone, but it's not visible YET.
Let me explain, as you've seen above, I've set it to Float:Max[2], 2 means the two numbers between the brackets, 569.5944 and 2742.9941, so by using Max[0], it means that we have selected the first number. I guess you understand now. But you always should start with 0.
Under OnPlayerDisconnect :
Now under OnPlayerSpawn :
Now let's create a timer that loops every 1 second. (DO NOT USE OnPlayerUpdate! It's NOT per second!).
You can rename that to whatever you want.
___
Go back to OnGameModeInit()
You can now go anywhere you like, and forward your MainTimer and add your functions:
Now go under OnGameModeExit() :
Full code:
Thank you for taking time to read this, and hope you got some useful information.
Feedback would be appreciated.
I thought this tutorial might be useful for some people who work on a TDM/DM servers, this tutorial will 'probably' teach you how to keep players within the allowed area only, getting out will kill them(how sad).
Anyway, here we begin:
pawn Code:
new MapZone[MAX_PLAYERS]; // we need this to identify the area/zone or whatever.
pawn Code:
new Float:Max[2] = {569.5944,2742.9941};
new Float:Min[2] = {-838.9635,1163.5237};
Replace them with your preferred co-ordinates. These co-ordinates are from the abandoned airport to that big bridge.
Now under OnGameModeInit() :
pawn Code:
MapZone = GangZoneCreate(Min[0],Min[1],Max[0],Max[1]);
Let me explain, as you've seen above, I've set it to Float:Max[2], 2 means the two numbers between the brackets, 569.5944 and 2742.9941, so by using Max[0], it means that we have selected the first number. I guess you understand now. But you always should start with 0.
Under OnPlayerDisconnect :
pawn Code:
GangZoneHideForPlayer(playerid, MapZone); // hides the zone/area when the player leaves.
pawn Code:
GangZoneShowForPlayer(playerid, MapZone, 0xBBBBBB88); // Shows the zone to the player when he spawns, '0xBBBBBB88' is the color GREY.
pawn Code:
new maintimer; // our timer <3
___
Go back to OnGameModeInit()
pawn Code:
maintimer = SetTimer("MainTimer", 1000, true); // 1000 = one second. true = loops/repeats every 1 second.
pawn Code:
forward MainTimer();
public MainTimer()
{
new Float:HP; // player health
for(new i=0; i < MAX_PLAYERS; i++) // loops through players
{
if(IsPlayerConnected(i) && (GetPVarInt(i, "Spectate") == 0)) //You can add more exceptions here, where you don't want boundaries e.g. dms, duels, etc.
{
if(IsPlayerInArea(i,Min[0], Max[0], Min[1], Max[1]) != 1) // check if the player is not in the area/zone.
{
GetPlayerHealth(i, HP); // gets player health
SetPlayerHealth(i, HP-5); // reduces -5%, every 1 second.
GameTextForPlayer(i, "~r~Stay inside boundaries~n~or you will be killed!", 3000, 3); // Shows a game text for the player who got out of the boundaries, 3000 = 3 seconds, 3 = font style.
}
}
}
}
pawn Code:
KillTimer(maintimer); // kill the timer, just in case.
pawn Code:
new MapZone[MAX_PLAYERS]; // we need this to identify the area/zone or whatever.
new Float:Max[2] = {569.5944,2742.9941};
new Float:Min[2] = {-838.9635,1163.5237};
public OnGameModeInit()
{
MapZone = GangZoneCreate(Min[0],Min[1],Max[0],Max[1]);
maintimer = SetTimer("MainTimer", 1000, true); // 1000 = one second. true = loops/repeats every 1 second.
return 1;
}
public OnGameModeExit()
{
KillTimer(maintimer); // kill the timer, just in case.
return 1;
}
forward MainTimer();
public MainTimer()
{
new Float:HP; // player health
for(new i=0; i < MAX_PLAYERS; i++) // loops through players
{
if(IsPlayerConnected(i) && (GetPVarInt(i, "Spectate") == 0)) //You can add more exceptions here, where you don't want boundaries e.g. dms, duels, etc.
{
if(IsPlayerInArea(i,Min[0], Max[0], Min[1], Max[1]) != 1) // check if the player is not in the area/zone.
{
GetPlayerHealth(i, HP); // gets player health
SetPlayerHealth(i, HP-5); // reduces -5%, every 1 second.
GameTextForPlayer(i, "~r~Stay inside boundaries~n~or you will be killed!", 3000, 3); // Shows a game text for the player who got out of the boundaries, 3000 = 3 seconds, 3 = font style.
}
}
}
}
Feedback would be appreciated.