/Donut
#1

Hello, I've made a /donut command that it will refills your health, but i want it to refill my health slowly, like refills 2 precent of my health each secend, not sets my health 100 in one sec (SetPlayerHeath) anyone knows how please tell me
Reply
#2

Use SetTimerEx() function.
Reply
#3

Quote:
Originally Posted by xRyder
Посмотреть сообщение
Use SetTimerEx() function.
Yea, I tought about that aswell but what can you do to stop it, when his HP reaches 100% ? I mean like, I`m pretty sure he doesn`t want to continusly heal him, till he /q's
Reply
#4

Put this in your command:

pawn Код:
// Set a repeating timer to call function 'donutHealth' every second.
SetPVarInt(playerid, "donutHealth", SetTimerEx("donutHealth", 1000, true, "i", playerid));
and out of your command:

pawn Код:
// Forward our function
forward donutHealth(playerid);

// Create our function
public donutHealth(playerid) {
        // Create a temp. variable to store the player's health
    new
        Float: fHealth;

        // Get the player's health
    GetPlayerHealth(playerid, fHealth);

    // Check if the player has MORE than 100 health.
    if(fHealth > 100) {
        return KillTimer(GetPVarInt(playerid, "donutHealth")); // Cancel the timer/function and don't add health
    }
   
        // Add health if everything is okay!
    SetPlayerHealth(playerid, fHealth+5);
    return 1;
}
Untested.
Reply
#5

Quote:
Originally Posted by antonio112
Посмотреть сообщение
Yea, I tought about that aswell but what can you do to stop it, when his HP reaches 100% ? I mean like, I`m pretty sure he doesn`t want to continusly heal him, till he /q's
Thats why there is a function called "KillTimer" dumb---..i mean really, just check the wiki next time about the timer functions then reply.
Reply
#6

I added this in my pawno

pawn Код:
dcmd_donut(playerid,params[])
// Set a repeating timer to call function 'donutHealth' every second.
SetPVarInt(playerid, "donutHealth", SetTimerEx("donutHealth", 1000, true, "i", playerid));

// Forward our function
forward donutHealth(playerid);

// Create our function
public donutHealth(playerid) {
        // Create a temp. variable to store the player's health
    new
        Float: fHealth;

        // Get the player's health
    GetPlayerHealth(playerid, fHealth);

    // Check if the player has MORE than 100 health.
    if(fHealth > 100) {
        return KillTimer(GetPVarInt(playerid, "donutHealth")); // Cancel the timer/function and don't add health
    }
   
        // Add health if everything is okay!
    SetPlayerHealth(playerid, fHealth+5);
    return 1;
}
But it didint work in game, It said unknown command, Help please.
Reply
#7

show us the command
Reply
#8

Quote:
Originally Posted by G*Mafia
Посмотреть сообщение
I added this in my pawno

pawn Код:
dcmd_donut(playerid,params[])
// Set a repeating timer to call function 'donutHealth' every second.
SetPVarInt(playerid, "donutHealth", SetTimerEx("donutHealth", 1000, true, "i", playerid));

// Forward our function
forward donutHealth(playerid);

// Create our function
public donutHealth(playerid) {
        // Create a temp. variable to store the player's health
    new
        Float: fHealth;

        // Get the player's health
    GetPlayerHealth(playerid, fHealth);

    // Check if the player has MORE than 100 health.
    if(fHealth > 100) {
        return KillTimer(GetPVarInt(playerid, "donutHealth")); // Cancel the timer/function and don't add health
    }
   
        // Add health if everything is okay!
    SetPlayerHealth(playerid, fHealth+5);
    return 1;
}
But it didint work in game, It said unknown command, Help please.
pawn Код:
dcmd_donut(playerid,params[])
{
    SetPVarInt(playerid, "donutHealth", SetTimerEx("donutHealth", 1000, true, "i", playerid));
    return 1;
}
forward donutHealth(playerid);
public donutHealth(playerid)
{
    new Float: fHealth;
    GetPlayerHealth(playerid, fHealth);
    if(fHealth > 100)
        return KillTimer(GetPVarInt(playerid, "donutHealth"));
    SetPlayerHealth(playerid, fHealth+5);
    return 1;
}
Reply
#9

Quote:
Originally Posted by G*Mafia
Посмотреть сообщение
I added this in my pawno

pawn Код:
dcmd_donut(playerid,params[])
// Set a repeating timer to call function 'donutHealth' every second.
SetPVarInt(playerid, "donutHealth", SetTimerEx("donutHealth", 1000, true, "i", playerid));

// Forward our function
forward donutHealth(playerid);

// Create our function
public donutHealth(playerid) {
        // Create a temp. variable to store the player's health
    new
        Float: fHealth;

        // Get the player's health
    GetPlayerHealth(playerid, fHealth);

    // Check if the player has MORE than 100 health.
    if(fHealth > 100) {
        return KillTimer(GetPVarInt(playerid, "donutHealth")); // Cancel the timer/function and don't add health
    }
   
        // Add health if everything is okay!
    SetPlayerHealth(playerid, fHealth+5);
    return 1;
}
But it didint work in game, It said unknown command, Help please.
Brackets.... blabla(playerid, params) {
Reply
#10

Brackets are not needed here, nor they will not change anything, isn't it logic that you can use it like this:
pawn Код:
dcmd_something( playerid, params[ ] )
    return SendClientMessage( playerid, 0xAAAAAA, "abcd" );
If you can use this, you can also use:
pawn Код:
dcmd_donut(playerid,params[])
    SetPVarInt(playerid, "donutHealth", SetTimerEx("donutHealth", 1000, true, "i", playerid));
So, probbably, not a bracket problem.
The real problem was you need to use return.
pawn Код:
dcmd_donut(playerid,params[])
    SetPVarInt(playerid, "donutHealth"); return SetTimerEx("donutHealth", 1000, true, "i", playerid);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)