Timer problem - 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)
+--- Thread: Timer problem (
/showthread.php?tid=438524)
Timer problem -
RedWolfX - 20.05.2013
Hello, I got a problem with some timers. When you enter a specific area where you are not allowed, you start to loose health. You start to loose health, but it wont stop, even if you go away.
Here is the code:
Код:
new bool:IsInArea[MAX_PLAYERS];
new HealthTimer[MAX_PLAYERS];
forward areacheck();
forward health(playerid);
public OnGameModeInit()
{
SetTimer("areacheck", 200, 1);
}
public areacheck()
{
for (new i=0; i<MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
if (IsPlayerInRangeOfPoint(put things here) && IsInArea[i]==false)
{
HealthTimer[i]=SetTimerEx("health", 400, 1, "i", i);
IsInArea[i]=true;
}
else
{
if (IsInArea[i]==true)
{
IsInArea[i]=false;
KillTimer(HealthTimer[i]);
}
}
}
}
}
public health(playerid)
{
new Float:h;
GetPlayerHealth(playerid, h);
SetPlayerHealth(playerid, h-5)
}
I cant figure out whats wrong.
Any help would be appreciated
Re: Timer problem -
Jefff - 20.05.2013
You dont need 2 arrays
pawn Код:
new MaxPlayers;
new HealthTimer[MAX_PLAYERS] = {-1, ...};
forward areacheck();
forward health(playerid);
public OnGameModeInit()
{
MaxPlayers = GetMaxPlayers();
SetTimer("areacheck", 500, 1);
return 1;
}
OnPlayerDisconnect
pawn Код:
if(HealthTimer[playerid] != -1)
{
KillTimer(HealthTimer[playerid]);
HealthTimer[playerid] = -1;
}
pawn Код:
public health(playerid)
{
new Float:h;
GetPlayerHealth(playerid, h);
SetPlayerHealth(playerid, h-5);
return 1;
}
public areacheck()
{
static State;
for(new i = 0; i != MaxPlayers; i++)
if(IsPlayerConnected(i))
{
State = GetPlayerState(i);
if(PLAYER_STATE_ONFOOT <= State <= PLAYER_STATE_PASSENGER && IsPlayerInRangeOfPoint(put things here))
{
if(HealthTimer[i] < 0)
HealthTimer[i] = SetTimerEx("health", 400, true, "i", i);
}
else
{
if(HealthTimer[i] > -1)
{
KillTimer(HealthTimer[i]);
HealthTimer[i] = -1;
}
}
}
return 1;
}
Re: Timer problem -
RedWolfX - 20.05.2013
Not working now either, It worked before, You started to loose health, but when you got away, it wouldnt stop.
Re: Timer problem -
Jefff - 20.05.2013
Works good, try to increase the disctance in IsPlayerInRangeOfPoint
//EDIT
Use better version up
Re: Timer problem -
Pooh7 - 20.05.2013
Why wouldn't you just use OnPlayerEnterDynamicArea to start a timer and OnPlayerLeaveDynamicArea to stop it?
The callbacks are a part of the
Streamer Plugin.