Safe zone - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Safe zone (
/showthread.php?tid=65744)
Safe zone -
fiordas - 15.02.2009
Hello, i have safe zone in my server where players are immortal, but when player leaves zone, they are still immortal. What is wrong in my script? Code:
pawn Код:
forward IsPlayerInArea();
SetTimer("IsPlayerInArea",1000, 1);
public IsPlayerInArea()
{
new Float:X, Float:Y, Float:Z;
for(new i=0; i < MAX_PLAYERS; i++)
{
GetPlayerPos(i, X, Y, Z);
if (X <= -1665 && X >= -1832 && Y <= 973 && Y >= 784) //safe zone
{
SetPlayerHealth(i, 999999.9);
}
else SetPlayerHealth(i, 100);
}
}
Re: Safe zone -
Pghpunkid - 15.02.2009
your assigning them to 100 everytime the timer is called.. make a array like InArea[MAX_PLAYERS] and make it 1 if their in and 0 if their not, then in the else side, if InArea[playerid] == 1 give them 100 and set InArea[playerid] = 0. that way when they leave it sets it to 100 then will not give them anymore health while outside the area. Dont forget to make InArea[playerid] == 1 when they reenter.
Re: Safe zone -
Salmon - 15.02.2009
you had no brackets in the else statement
pawn Код:
forward IsPlayerInArea();
SetTimer("IsPlayerInArea",1000, 1);
public IsPlayerInArea()
{
new Float:X, Float:Y, Float:Z;
for(new i=0; i < MAX_PLAYERS; i++)
{
GetPlayerPos(i, X, Y, Z);
if (X <= -1665 && X >= -1832 && Y <= 973 && Y >= 784) //safe zone
{
SetPlayerHealth(i, 999999.9);
}
else
{
SetPlayerHealth(i, 100);
}
}
}
I'm assuming this doesn't matter tho?
Re: Safe zone -
fiordas - 15.02.2009
Is it somethink like this? Code:
pawn Код:
new InArea[MAX_PLAYERS];
public IsPlayerInArea()
{
new Float:X, Float:Y, Float:Z;
for(new i=0; i < MAX_PLAYERS; i++)
{
GetPlayerPos(i, X, Y, Z);
if (X <= -1665 && X >= -1832 && Y <= 973 && Y >= 784)
{
InArea[i] = 0;
SetPlayerHealth(i, 999999.9);
InArea[i] = 1;
}
else
{
InArea[i] = 1;
SetPlayerHealth(i, 100);
InArea[i] = 0;
}
}
}
Re: Safe zone -
Pghpunkid - 15.02.2009
No that code would do nothing.. This is what i mean..
pawn Код:
new InArea[MAX_PLAYERS];
public IsPlayerInArea()
{
new Float:X, Float:Y, Float:Z;
for(new i=0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(x)) {
GetPlayerPos(i, X, Y, Z);
if (X <= -1665 && X >= -1832 && Y <= 973 && Y >= 784)
{
SetPlayerHealth(i, 999999.9);
InArea[i] = 1;
}
else
{
if (InArea[i] = 1) {
SetPlayerHealth(i, 100);
InArea[i] = 0;
}
}
}
}
}
Re: Safe zone -
fiordas - 15.02.2009
That gives me error and warning:
Код:
D:\games\GTA San Andreas\GTA San Andreas\serveris\gamemodes\funzone.pwn(1170) : error 017: undefined symbol "x"
D:\games\GTA San Andreas\GTA San Andreas\serveris\gamemodes\funzone.pwn(1179) : warning 211: possibly unintended assignment
Re: Safe zone -
[RP]Rav - 15.02.2009
Код:
public IsPlayerInArea()
{
new Float:X, Float:Y, Float:Z;
for(new i=0; i < MAX_PLAYERS; i++)
{
if (!IsPlayerConnected(i))
continue;
GetPlayerPos(i, X, Y, Z);
if (X <= -1665 && X >= -1832 && Y <= 973 && Y >= 784)
{
SetPlayerHealth(i, 999999.9);
InArea[i] = 1;
}
else if (InArea[i] == 1)
{
SetPlayerHealth(i, 100);
InArea[i] = 0;
}
}
}
make sure you do this too
Код:
OnPlayerConnect(playerid)
{
[...]
InArea[playerid] = 0;
[...]
}
Re: Safe zone -
fiordas - 15.02.2009
Thank you both, works just fine!