The Death Timer!! - 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: The Death Timer!! (
/showthread.php?tid=254921)
The Death Timer!! -
Swiftz - 13.05.2011
I need a timer, So it decreases like 5 or less hp each second, I'm confused with it. So after a few seconds the hp should finally reach 0 and the player dies. Please help me with this
Re: The Death Timer!! -
Hobod - 13.05.2011
Set a timer for 1 second that repeats.
Then in the function decrease the players health.
pawn Код:
// Your function
forward Death(playerid);
public Death(playerid)
{
new Float:Health;
GetPlayerHealth(playerid, Health);
SetPlayerHealth(playerid, Health-5);
}
i'm not the with timers but i hope this helps!
Re: The Death Timer!! -
[SU]Balli - 13.05.2011
Hello!
Okay, that ^ is a start, but not all.
on top under includes and stuff :
OnGameModeInit
pawn Код:
KillTimer = SetTimer("KillTimer", 5000, 0);
This comes anywhere outside other publics.
pawn Код:
forward KillTimer();
public KillTimer()
{
new Float:HP;
GetPlayerHealth(playerid, HP);
SetPlayerHealth(playerid, HP -5);
}
//Other stuff..
OnGameModeExit..
Should work just fine. :P
Re: The Death Timer!! -
__ - 13.05.2011
Hobod provided a better solution than you did.
Working from his solution:
pawn Код:
forward Death(playerid);
public Death(playerid)
{
new Float:Health;
GetPlayerHealth(playerid, Health);
SetPlayerHealth(playerid, Health-5)
if(Health-5 <= 0) KillTimer(GetPVarInt(playerid, "timerDeath"));
}
Then to set the timer in action:
pawn Код:
SetTimerEx("Death", 1000, true, "i", playerid);
Re: The Death Timer!! -
Laronic - 13.05.2011
Whole command.
Not Tested
pawn Код:
new InfectedTimer[MAX_PLAYERS];
COMMAND:infect(playerid, params[])
{
new targetid;
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /infect [playeris | name]");
else if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, 0xFFFFFFAA, "That player is not connected");
{
InfectedTimer[playerid] = SetTimerEx("Infected", 1000, true, "d", targetid);
SendClientMessage(playerid, 0xFFFFFFAA, "You infected someone");
SendClientMessage(targetid, 0xFFFFFFAA, "Someone infected you");
}
return 1;
}
forward Infected(playerid);
public Infected(playerid)
{
new Float:Health;
GetPlayerHealth(playerid, Health);
if(Health >= 5)
{
SetPlayerHealth(playerid, Health - 5);
}
else
{
SetPlayerHealth(playerid, 0.0);
KillTimer(InfectedTimer[playerid]);
SendClientMessageToAll(0xFFFFFFAA, "Someone died of a infection");
}
return 1;
}
Re: The Death Timer!! -
__ - 13.05.2011
Quote:
Originally Posted by CyberGhost
Whole command.
Not Tested
pawn Код:
new InfectedTimer[MAX_PLAYERS];
COMMAND:infect(playerid, params[]) { new targetid; if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /infect [playeris | name]"); else if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, 0xFFFFFFAA, "That player is not connected"); { InfectedTimer[playerid] = SetTimerEx("Infected", 1000, true, "u", targetid); SendClientMessage(playerid, 0xFFFFFFAA, "You infected someone"); SendClientMessage(targetid, 0xFFFFFFAA, "Someone infected you"); } return 1; }
forward Infected(playerid); public Infected(playerid) { new Float:Health; GetPlayerHealth(playerid, Health); if(Health >= 5) { SetPlayerHealth(playerid, Health - 5); } else { SetPlayerHealth(playerid, 0.0); KillTimer(InfectedTimer[playerid]); SendClientMessageToAll(0xFFFFFFAA, "Someone died of a infection"); } return 1; }
|
"u" is a parameter in sscanf, not SetTimerEx.
Re: The Death Timer!! -
Laronic - 13.05.2011
Quote:
Originally Posted by __
"u" is a parameter in sscanf, not SetTimerEx.
|
Yeah i forgot, edited.
Код:
This forum requires that you wait 120 seconds between posts. Please try again in 30 seconds.
Re: The Death Timer!! -
Swiftz - 13.05.2011
Quote:
if(Health-2 <= 0) KillTimer(GetPVarInt(playerid, "timerDeath"));
|
On this line i get some errors like "Expected token ; but found if...."
Re: The Death Timer!! -
Laronic - 13.05.2011
Quote:
Originally Posted by Swiftz
On this line i get some errors like "Expected token ; but found if...."
|
pawn Код:
if(Health <= 0) KillTimer(GetPVarInt(playerid, "timerDeath"));
Re: The Death Timer!! -
Swiftz - 13.05.2011
No i still get that error
please help