23.12.2013, 14:14
I've learned a lot in this tutorial (not just from the OP but from the posts). Just 1 question. Is it okay to do something like this?
Instead of
Using 1 timer instead of many.
pawn Code:
public OnGameModeInit()
{
Timer = SetTimer("OneSecTimer", 1000, true);
return 1;
}
CMD:healme(playerid)
{
if(IsHealed[playerid] == 1)
{
SendClientMessage(playerid, -1, "Please wait 1 minute before using this command again!");
HealTimer[playerid] == 60; // 60 seconds
}
else
{
SetPlayerHealth(playerid, 100);
IsHealed[playerid] = 1;
}
return 1;
}
CMD:givearmour(playerid)
{
if(Armoured[playerid] == 1)
{
SendClientMessage(playerid, -1, "Please wait 1 minute before using this command again!");
ArmourTimer[playerid] = 60;
}
else
{
SetPlayerArmour(playerid, 100);
Armoured[playerid] = 1;
}
return 1;
}
forward OneSecTimer();
public OneSecTimer()
{
for(new i = 0; i < MAX_PLAYERS; i++) //foreach
{
if(IsPlayerConnected(i))
{
if(IsHealed[i] == 1)
{
Healtimer[i]--;
if(HealTimer[i] == 0)
{
IsHealed[i] = 0;
SendClientMessage(i, -1, "You can now use /healme command again");
}
}
if(Armoured[i] == 1)
{
Healtimer[i]--;
if(HealTimer[i] == 0)
{
IsHealed[i] = 0;
SendClientMessage(i, -1, "You can now use /healme command again");
}
}
}
}
return 1;
}
pawn Code:
CMD:healme(playerid)
{
if(IsHealed[playerid] == 1)
{
SendClientMessage(playerid, -1, "Please wait 1 minutes before using this command again!");
HealTimer = SetTimerEx("Heal", 60 * 1000, false, "i", playerid);
}
else
{
SetPlayerHealth(playerid, 100);
IsHealed[playerid] = 1;
}
return 1;
}
forward Heal(playerid);
public Heal(playerid)
{
IsHealed[playerid] = 0;
SendClientMessage(playerid, -1, "You can now use /healme command again");
KillTimer(HealTimer);
return 1;
}
CMD:givearmour(playerid)
{
if(Armoured[playerid] == 1)
{
SendClientMessage(playerid, -1, "Please wait 1 minutes before using this command again!");
ArmourTimer = SetTimerEx("Armour", 60 * 1000, false, "i", playerid);
}
else
{
SetPlayerArmour(playerid, 100);
Armoured[playerid] = 1;
}
return 1;
}
forward Armour(playerid);
public Armour(playerid)
{
Armoured[playerid] = 0;
SendClientMessage(playerid, -1, "You can now use /givearmour command again");
KillTimer(ArmourTimer);
return 1;
}