Timer Problem
#1

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;
}
Reply
#2

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
Reply
#3

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
Reply
#4

Post the timer function.
Reply
#5

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

////////////////////////
Reply
#7

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;
}
Reply
#8

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 .
Reply
#9

..................
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)