PHP Code:
new keepzone[4];
/*
* native IsPlayerInArea3D(playerid, Float:minx, Float:miny, Float:minz, Float:maxx, Float:maxy, Float:maxz);
*/
stock IsPlayerInArea3D(playerid, Float:minx, Float:miny, Float:minz, Float:maxx, Float:maxy, Float:maxz) {
new
Float: x,
Float: y,
Float: z
;
if (!GetPlayerPos(playerid, x, y, z)) return false;
if (x >= minx && x <= maxx && y >= miny && y <= maxy && z >= minz && z <= maxz) {
return true;
}
return false;
}
/*
* native CreateCutZone(gangzone[4], Float:minx, Float:miny, Float:maxx, Float:maxy);
*/
// Map Andreas
// -------------------------------
// +---------B maxx maxy
// | CutZone |
// A---------+
// minx miny
// -------------------------------
stock CreateCutZone(gangzone[4], Float:minx, Float:miny, Float:maxx, Float:maxy)
{
gangzone[0] = GangZoneCreate(minx, maxy, maxx, 3000.0); // top
gangzone[1] = GangZoneCreate(-3000.0, -3000.0, minx, 3000.0); // left
gangzone[2] = GangZoneCreate(minx, -3000.0, maxx, miny); // bottom
gangzone[3] = GangZoneCreate(maxx, -3000.0, 3000.0, 3000.0); // right
}
/*
* native ShowPlayerCutZone(playerid, gangzone[4], color);
*/
stock ShowPlayerCutZone(playerid, gangzone[4], color) {
for (new i; i < 4; i++) {
GangZoneShowForPlayer(playerid, gangzone[i], color);
}
}
/*
* native HidePlayerCutZone(playerid, gangzone[4]);
*/
stock HidePlayerCutZone(playerid, gangzone[4]) {
for (new i; i < 4; i++) {
GangZoneHideForPlayer(playerid, gangzone[i]);
}
}
/*
* native ShowAllCutZone(gangzone[4], color);
*/
stock ShowAllCutZone(gangzone[4], color) {
for (new i; i < 4; i++) {
GangZoneShowForAll(gangzone[i], color);
}
}
/*
* native HideAllCutZone(gangzone[4]);
*/
stock HideAllCutZone(gangzone[4]) {
for (new i; i < 4; i++) {
GangZoneHideForAll(gangzone[i]);
}
}
/*
* native DestroyCutZone(gangzone[4]);
*/
stock DestroyCutZone(gangzone[4]) {
for (new i; i < 4; i++) {
GangZoneHideForAll(gangzone[i]);
GangZoneDestroy(gangzone[i]);
}
}
/*
* native SetCutZoneFlashForPlayer(playerid, gangzone[4], color);
*/
stock SetCutZoneFlashForPlayer(playerid, gangzone[4], color) {
for (new i; i < 4; i++) {
GangZoneFlashForPlayer(playerid, gangzone[i], color);
}
}
/*
* native SetCutZoneStopFlashForPlayer(playerid, gangzone[4]);
*/
stock SetCutZoneStopFlashForPlayer(playerid, gangzone[4]) {
for (new i; i < 4; i++) {
GangZoneStopFlashForPlayer(playerid, gangzone[i]);
}
}
public OnGameModeInit()
{
CreateCutZone(keepzone, -100.0, -100.0, 100.0, 100.0); //minx, miny, maxx, maxy
return 1;
}
public OnGameModeExit()
{
DestroyCutZone(keepzone);
return 1;
}
public OnPlayerConnect(playerid)
{
ShowPlayerCutZone(playerid, keepzone, 0x00000044);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
HidePlayerCutZone(playerid, keepzone);
return 1;
}
public OnPlayerUpdate(playerid)
{
// Keep zone -------------------------------------------------------------------------------
static
delay[MAX_PLAYERS],
bool:keepzone_flash[MAX_PLAYERS]
;
new
time = tickcount()
;
if (delay[playerid] < time) {
if (!IsPointInArea3D(playerid, -100.0, -100.0, -100.0, 100.0, 100.0, 100.0)) {
if (!keepzone_flash[playerid]) {
keepzone_flash[playerid] = true;
SetCutZoneFlashForPlayer(playerid, TW_keepzone, 0xFF000077); // If player ouiside of battlefield enable flashed zone
}
SendClientMessage(playerid, 0xFF0000FF, "You are outside of battlefield. Go back!");
new
Float: hp
;
GetPlayerHealth(playerid, hp);
SetPlayerHealth(playerid, hp - 5.0);
} else {
if (keepzone_flash[playerid]) {
SetCutZoneStopFlashForPlayer(playerid, TW_keepzone); // If player in CutZone disable flashed zone
keepzone_flash[playerid] = false;
}
}
delay[playerid] = time + 2000; // while checking the player position 2 sec.
}
// EOF Keep zone -------------------------------------------------------------------------------
return 1;
}