Lil of a problem with my timer. -
JamesS - 23.03.2013
Scripthing something which will reduce the player's health by 1 every second, and stop on the players' death, but it seems to be crashing my server...
Anyone who could thow in his code for this real quick? I was using a repeating timer, but that wasn't working out so well.
Re: Lil of a problem with my timer. -
Scenario - 23.03.2013
This could be used as an include if you wanted to. If not, take the code from the hook statements and put it into the correct callbacks.
pawn Код:
#include <a_samp>
#include <YSI\y_timers>
#include <YSI\y_hooks>
new
g_Spawned[MAX_PLAYERS] = false
;
ptask removeHealthPoint[1000](playerid)
{
if(g_Spawned[playerid])
{
new
Float:fHealth
;
GetPlayerHealth(playerid, fHealth);
SetPlayerHealth(playerid, fHealth-1);
}
return 1;
}
hook OnPlayerDeath(playerid, reason)
{
g_Spawned[playerid] = false;
return 1;
}
hook OnPlayerSpawn(playerid)
{
g_Spawned[playerid] = true;
return 1;
}
You'll need y_timers for this to work.
Re: Lil of a problem with my timer. -
JamesS - 23.03.2013
Quote:
Originally Posted by RealCop228
This could be used as an include if you wanted to. If not, take the code from the hook statements and put it into the correct callbacks.
pawn Код:
#include <a_samp> #include <YSI\y_timers> #include <YSI\y_hooks>
new g_Spawned[MAX_PLAYERS] = false ;
ptask removeHealthPoint[1000](playerid) { if(g_Spawned[playerid]) { new Float:fHealth ; GetPlayerHealth(playerid, fHealth); SetPlayerHealth(playerid, fHealth-1); } return 1; }
hook OnPlayerDeath(playerid, reason) { g_Spawned[playerid] = false; return 1; }
hook OnPlayerSpawn(playerid) { g_Spawned[playerid] = true; return 1; }
You'll need y_timers for this to work.
|
no way to do this w/o y_timers?
Re: Lil of a problem with my timer. - Patrick - 23.03.2013
here you go without y_hooks and y_timers
pawn Код:
#include <a_samp>
main () { }
new
bool:g_Spawned[MAX_PLAYERS] = false
;
public OnPlayerConnect(playerid)
{
SetTimerEx("RemoveHealthPoint", 1000, true,"i",playerid); //put this where you want your timer
return 1;
}
forward RemoveHealthPoint(playerid);
public RemoveHealthPoint(playerid)
{
if(g_Spawned[playerid])
{
new
Float:fHealth
;
GetPlayerHealth(playerid, fHealth);
SetPlayerHealth(playerid, fHealth-1);
}
return 1;
}
public OnPlayerDeath(playerid,killerid,reason)
{
g_Spawned[playerid] = false;
return 1;
}
public OnPlayerSpawn(playerid)
{
g_Spawned[playerid] = true;
return 1;
}
Re: Lil of a problem with my timer. -
Scenario - 23.03.2013
Quote:
Originally Posted by JamesS
no way to do this w/o y_timers?
|
pds2012 did it above. However, you really should use y_timers. It may seem confusing at first, but it's honestly 100,000x easier than using SetTimer() and SetTimerEx(). Plus, I don't think the timers collide as much with y_timers.
As a side note, depleting someone's health by 1 each second would kill them in 1 minute and 40 seconds... :P
Re: Lil of a problem with my timer. -
JamesS - 23.03.2013
Still gives me the same problem, when I die, it's all good, hp going down, when I die again, I respawn, also okay, but if I die again, I spawn in the middle of nowhere, and nothing is working anymore, please help me out here!
Re: Lil of a problem with my timer. -
Scenario - 23.03.2013
Seems like a different problem in your script then. The code I gave you doesn't set the player's position to a different location and it shouldn't effect that.
Can you show your OnPlayerDeath and OnPlayerSpawn callbacks?
Re: Lil of a problem with my timer. -
JamesS - 23.03.2013
It's a whole gamemode. Anyways, I think the problem is that a timer gets set twice..