[Tutorial] To optimize our GM and our Server improves.
#18

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?

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;
}
Instead of

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;
}
Using 1 timer instead of many.
Reply


Messages In This Thread
To optimize our GM and our Server improves. - by Swedky - 23.12.2013, 05:37
Re: To optimize our GM and our Server improves. - by nGen.SoNNy - 23.12.2013, 06:14
Re: To optimize our GM and our Server improves. - by Emmet_ - 23.12.2013, 06:54
Re: To optimize our GM and our Server improves. - by Ada32 - 23.12.2013, 07:02
Re: To optimize our GM and our Server improves. - by Bakr - 23.12.2013, 07:16
Respuesta: Re: To optimize our GM and our Server improves. - by Swedky - 23.12.2013, 10:29
Re: To optimize our GM and our Server improves. - by Konstantinos - 23.12.2013, 11:07
Respuesta: Re: To optimize our GM and our Server improves. - by Swedky - 23.12.2013, 11:38
Re: To optimize our GM and our Server improves. - by xVIP3Rx - 23.12.2013, 11:43
Re: To optimize our GM and our Server improves. - by Patrick - 23.12.2013, 11:50
Re: To optimize our GM and our Server improves. - by Konstantinos - 23.12.2013, 11:54
Re: To optimize our GM and our Server improves. - by Bakr - 23.12.2013, 12:11
Re: To optimize our GM and our Server improves. - by Ada32 - 23.12.2013, 12:14
Re: To optimize our GM and our Server improves. - by xVIP3Rx - 23.12.2013, 12:21
Re: To optimize our GM and our Server improves. - by Riddick94 - 23.12.2013, 12:25
Re: To optimize our GM and our Server improves. - by Konstantinos - 23.12.2013, 12:27
Re: To optimize our GM and our Server improves. - by Riddick94 - 23.12.2013, 12:31
Re: To optimize our GM and our Server improves. - by newbienoob - 23.12.2013, 14:14
Re: To optimize our GM and our Server improves. - by Patrick - 23.12.2013, 14:29
Re: To optimize our GM and our Server improves. - by newbienoob - 23.12.2013, 14:40
Re: To optimize our GM and our Server improves. - by xVIP3Rx - 23.12.2013, 14:42
Re: To optimize our GM and our Server improves. - by Patrick - 23.12.2013, 14:44
Re: To optimize our GM and our Server improves. - by SuperViper - 23.12.2013, 14:50
Re: To optimize our GM and our Server improves. - by xVIP3Rx - 23.12.2013, 14:56
Re: To optimize our GM and our Server improves. - by Konstantinos - 23.12.2013, 15:07
Re: To optimize our GM and our Server improves. - by Patrick - 23.12.2013, 15:12
Re: To optimize our GM and our Server improves. - by PowerPC603 - 23.12.2013, 16:03
Re: To optimize our GM and our Server improves. - by Bakr - 23.12.2013, 20:10
Re: To optimize our GM and our Server improves. - by Djole1337 - 23.12.2013, 20:32
Re: To optimize our GM and our Server improves. - by SuperViper - 23.12.2013, 22:35
Respuesta: To optimize our GM and our Server improves. - by Swedky - 24.12.2013, 18:09
Re: To optimize our GM and our Server improves. - by Patrick - 24.12.2013, 20:21
Respuesta: To optimize our GM and our Server improves. - by Swedky - 24.12.2013, 20:27
Re: To optimize our GM and our Server improves. - by Mister0 - 15.08.2016, 10:56
Respuesta: Re: To optimize our GM and our Server improves. - by Swedky - 17.10.2016, 07:18

Forum Jump:


Users browsing this thread: 1 Guest(s)