SA-MP Forums Archive
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=452008)



Timer Problem - RandomDude - 19.07.2013

I want the life to go up 1hp each 5 seconds here is the command

pawn Код:
CMD:td(playerid,params[])
{
    new amount;
    if(sscanf(params, "d", amount)) return SendClientMessage(playerid, -1, "USAGE: /td [amount]");
    if(0 < amount <= PlayerInfo[playerid][drugs])
    {
        new Float:Health;
        GetPlayerHealth(playerid, Health);
        SetPlayerHealth(playerid, Health+10);
        PlayerInfo[playerid][drugs] -= amount;
        SetTimerEx("Usedrugs", 2500*amount, false, "d", playerid); // 2 SECONDS IN REAL LIFE
        new string[ 128 ];
        format(string, sizeof(string), "You are smoking %d gram(s).", amount);
        SendClientMessage(playerid, -1, string);
    }
    else
    {
        SendClientMessage(playerid, -1, "You don't have enough drugs.");
    }
    return 1;
}



Re: Timer Problem - Wizza - 19.07.2013

Quote:
Originally Posted by RandomDude
Посмотреть сообщение
I want the life to go up 1hp each 5 seconds here is the command

pawn Код:
CMD:td(playerid,params[])
{
    new amount;
    if(sscanf(params, "d", amount)) return SendClientMessage(playerid, -1, "USAGE: /td [amount]");
    if(0 < amount <= PlayerInfo[playerid][drugs])
    {
        new Float:Health;
        GetPlayerHealth(playerid, Health);
        SetPlayerHealth(playerid, Health+10);
        PlayerInfo[playerid][drugs] -= amount;
        SetTimerEx("Usedrugs", 2500*amount, false, "d", playerid); // 2 SECONDS IN REAL LIFE
        new string[ 128 ];
        format(string, sizeof(string), "You are smoking %d gram(s).", amount);
        SendClientMessage(playerid, -1, string);
    }
    else
    {
        SendClientMessage(playerid, -1, "You don't have enough drugs.");
    }
    return 1;
}
pawn Код:
CMD:td(playerid,params[])
{
    new amount;
    if(sscanf(params, "d", amount)) return SendClientMessage(playerid, -1, "USAGE: /td [amount]");
    if(0 < amount <= PlayerInfo[playerid][drugs])
    {
        new Float:Health;
        GetPlayerHealth(playerid, Health);
        SetPlayerHealth(playerid, Health+10);
        PlayerInfo[playerid][drugs] -= amount;
        SetTimerEx("Usedrugs", 5000*amount, false, "d", playerid);
        new string[ 128 ];
        format(string, sizeof(string), "You are smoking %d gram(s).", amount);
        SendClientMessage(playerid, -1, string);
    }
    else
    {
        SendClientMessage(playerid, -1, "You don't have enough drugs.");
    }
    return 1;
}
5 sec = 5000 mm


Re: Timer Problem - RandomDude - 19.07.2013

It does not work tho
I do /td 1 and it will just fill my health
It won't go up with the timer each time


Re: Timer Problem - Gangster-rocks - 19.07.2013

Post the timer function.


Re: Timer Problem - RandomDude - 19.07.2013

pawn Код:
forward Usedrugs(playerid);
public Usedrugs(playerid)
{
    SendClientMessage(playerid, -1,"The Grams you have used are finished.");
    return 1;
}
This?


Re: Timer Problem - RandomDude - 19.07.2013

////////////////////////


Re: Timer Problem - arakuta - 20.07.2013

pawn Код:
//global var
new timerdrug[MAX_PLAYERS];
new drugamount[MAX_PLAYERS];

CMD:td(playerid,params[])
{
    new amount;
    if(sscanf(params, "d", amount)) return SendClientMessage(playerid, -1, "USAGE: /td [amount]");
    if(amount > 0 || amount < PlayerInfo[playerid][drugs])
    {
        new Float:Health;
        GetPlayerHealth(playerid, Health);
        SetPlayerHealth(playerid, Health+1);
        PlayerInfo[playerid][drugs] --;
        KillTimer(timerdrug[playerid]);
        drugamount[playerid] = 0;
        timerdrug[playerid] = SetTimerEx("Usedrugs", 5000, false, "dd", playerid,amount);
        new string[ 128 ];
        format(string, sizeof(string), "You are smoking %d gram(s).", amount);
        SendClientMessage(playerid, -1, string);
    }
    else
    {
        SendClientMessage(playerid, -1, "You don't have enough drugs.");
    }
    return 1;
}

// Now the timer function

forward Usedrugs(playerid);
public Usedrugs(playerid,amount)
{
    drugamount[playerid] ++;
    new Float:health;
    GetPlayerHealth(playerid,health);
    if(health >= 100)
        return SendClientMessage(playerid,-1,"Your life is full.");
    SetPlayerHealth(playerid,health + 1);
    PlayerInfo[playerid][drugs] --;
    if(drugamount[playerid] == amount)
        return SendClientMessage(playerid, -1,"The Grams you have used are finished.");
    SetTimerEx("Usedrugs",5000,false,"dd",playerid,amount);
    return 1;
}



Re: Timer Problem - RandomDude - 20.07.2013

Now it sends the drugs into minus like if I DO /drugsinv I will have -200 drugs from 0 if I /td 200 I have -200
Because it won't stop me and say you don't have 200 grams
+ it won't let one gram last 5 seconds .


Re: Timer Problem - RandomDude - 20.07.2013

..................