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};
MapZone = GangZoneCreate(Min[0],Min[1],Max[0],Max[1]);
GangZoneHideForPlayer(playerid, MapZone); // hides the zone/area when the player leaves.
GangZoneShowForPlayer(playerid, MapZone, 0xBBBBBB88); // Shows the zone to the player when he spawns, '0xBBBBBB88' is the color GREY.
new maintimer; // our timer <3
maintimer = SetTimer("MainTimer", 1000, true); // 1000 = one second. true = loops/repeats every 1 second.
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.
}
}
}
}
KillTimer(maintimer); // kill the timer, just in case.
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.
}
}
}
}
|
Your idea could also be done on servers to force the players to get moved to the location by themselves, though I prefer SetPlayerWorldBounds for DM activities.
|
|
Yes but when they die, it counts as a death in their statistics, which is not good for them.
|
, have been facing this since years!
static mapZones[MAX_GANGZONES] = {-1, ...},
mainTimer;
new Float: gZones[][4] =
{
{-838.9635, 1163.5237, 569.5944, 2742.9941}
// {minX, minY, maxX, maxY}
};
forward public MainTimer();
public OnGameModeInit()
{
for(new i = 0; i < sizeof(gZones); i++)
mapZones[i] = GangZoneCreate(gZones[i][0], gZones[i][1], gZones[i][2], gZones[i][3]);
mainTimer = SetTimer("MainTimer", 1000, true);
return 1;
}
public OnPlayerDisconnect(playerid)
{
for(new i = 0; i < sizeof(gZones); i++)
GangZoneHideForPlayer(playerid, mapZones[i]);
return 1;
}
public OnPlayerConnect(playerid)
{
for(new i = 0; i < sizeof(gZones); i++)
GangZoneShowForPlayer(playerid, MapZone, 0xBBBBBB88);
// Again, per zone colors can be added in the array too!
return 1;
}
public MainTimer()
{
new Float:HP; // player health
for(new i= 0; i < MAX_PLAYERS; i++) // loops through players
{
if(IsPlayerConnected(i)) //You can add more exceptions here, where you don't want boundaries e.g. dms, duels, etc.
{
for(new j = 0; j < sizeof(gZones); j++)
{
if(IsPlayerInArea(i, gZones[j][0], gZones[j][1], gZones[j][2], gZones[j][3] ) != 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.
}
}
}
}
}