Decrease the health
#1

how to make a command for admins to decrease the target id's health step by step depends on how many seconds i put in my script.

example:
/decrease
SendClientMessage: Usage - /decrease [playerid]

/decrease 3
makes the playerid's health automatically decreases 5% per 10 seconds
Reply
#2

pawn Код:
CMD:sethp(playerid, params[])
{
    new string[128], playa, health;
    if(sscanf(params, "ud", playa, health))
    {
        SendClientMessageEx(playerid, COLOR_GRAD2, "USAGE: /sethp [playerid] [health]");
        return 1;
    }
    if (PlayerInfo[playerid][pAdmin] >= 4) {
        if(IsPlayerConnected(playa)) {
            if(playa != INVALID_PLAYER_ID)
            {
                SetPlayerHealth(playa, health);
                format(string, sizeof(string), "You have set %s's health to %d.", GetPlayerNameEx(playa), health);
                SendClientMessageEx(playerid, COLOR_WHITE, string);
            }
        }
        else SendClientMessageEx(playerid, COLOR_GRAD1, "Invalid player specified.");
    }
    else {
        SendClientMessageEx(playerid, COLOR_GRAD1, "You are not authorized to use that command!");
    }
    return 1;
}
Try it
Reply
#3

Quote:
Originally Posted by Jankingston
Посмотреть сообщение
pawn Код:
CMD:sethp(playerid, params[])
{
    new string[128], playa, health;
    if(sscanf(params, "ud", playa, health))
    {
        SendClientMessageEx(playerid, COLOR_GRAD2, "USAGE: /sethp [playerid] [health]");
        return 1;
    }
    if (PlayerInfo[playerid][pAdmin] >= 4) {
        if(IsPlayerConnected(playa)) {
            if(playa != INVALID_PLAYER_ID)
            {
                SetPlayerHealth(playa, health);
                format(string, sizeof(string), "You have set %s's health to %d.", GetPlayerNameEx(playa), health);
                SendClientMessageEx(playerid, COLOR_WHITE, string);
            }
        }
        else SendClientMessageEx(playerid, COLOR_GRAD1, "Invalid player specified.");
    }
    else {
        SendClientMessageEx(playerid, COLOR_GRAD1, "You are not authorized to use that command!");
    }
    return 1;
}
Try it
Quote:
Originally Posted by AnonScripter
Посмотреть сообщение
makes the playerid's health automatically decreases 5% per 10 seconds
I really like how you do not read and post a command you got from somewhere.
Reply
#4

Give this a go, not tested:

pawn Код:
new decreaser[MAX_PLAYERS];
forward DecreaseHealth(playerid);

CMD:decrease(playerid, params[])
{
    new giveplayerid;
    if(sscanf(params, "u", giveplayerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "Correct usage: /decrease [playerid/name]");
    if(giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFFFFFFFF, "Player not connected.");
    decreaser[giveplayerid] = SetTimerEx("DecreaseHealth", 10000, true, "i", giveplayerid);
    SetPlayerHealth(giveplayerid, GetPlayerHealth(giveplayerid) - 5.0);
    return 1;
}

public DecreaseHealth(playerid) SetPlayerHealth(playerid, GetPlayerHealth(playerid) - 5.0);

public OnPlayerDeath(playerid, killerid, reason)
{
    KillTimer(decreaser[playerid]);
    return 1;
}
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
I really like how you do not read and post a command you got from somewhere.
exactly
Reply
#6

Quote:
Originally Posted by DanishHaq
Посмотреть сообщение
Give this a go, not tested:

pawn Код:
new decreaser[MAX_PLAYERS];
forward DecreaseHealth(playerid);

CMD:decrease(playerid, params[])
{
    new giveplayerid;
    if(sscanf(params, "u", giveplayerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "Correct usage: /decrease [playerid/name]");
    if(giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFFFFFFFF, "Player not connected.");
    decreaser[giveplayerid] = SetTimerEx("DecreaseHealth", 10000, true, "i", giveplayerid);
    SetPlayerHealth(giveplayerid, GetPlayerHealth(giveplayerid) - 5.0);
    return 1;
}

public DecreaseHealth(playerid) SetPlayerHealth(playerid, GetPlayerHealth(playerid) - 5.0);

public OnPlayerDeath(playerid, killerid, reason)
{
    KillTimer(decreaser[playerid]);
    return 1;
}
this is really an idea, thank you
Reply
#7

Here, you can set the target player, the value that decreases each second, and for how many seconds.
pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>


new Timer[MAX_PLAYERS];
new TimerHandler[MAX_PLAYERS] = {0, ...};

CMD:decreasehp(playerid, params[])
{
    new target, Float:value, seconds;
    if(sscanf(params, "ufd", target, value,seconds))
    {
        SendClientMessage(playerid, -1, "USAGE: /decreasehp [playerid] [value] [seconds]");
    }
   
    if(value < 0) value*=-1;
    if(value == 0) value=10;

    if(seconds < 0) seconds *=-1;
    if(seconds == 0) seconds = 10;
   
    TimerHandler[target] = 0;
    Timer[target] = SetTimerEx("DecHP", 1000, true, "dfd", target, value, seconds);
    new str[128];
    format(str, sizeof str, "You are now decreasing ID %d's health by %.3f per second for %d seconds", target, value, seconds);
    SendClientMessage(playerid, -1, str);
    return 1;
}

forward DecHP(player, Float:amount, times);
public DecHP(player, Float: amount, times)
{
    if(TimerHandler[player] < times)
    {
        new Float: hp;
        GetPlayerHealth(player, hp);
        SetPlayerHealth(player, hp-amount);
        TimerHandler[player]++;
    }
    else
    {
        KillTimer(Timer[player]);
        TimerHandler[player] = 0;
    }
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    KillTimer(Timer[playerid]);
    TimerHandler[playerid] = 0;
    return 1;
}
Reply
#8

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
Here, you can set the target player, the value that decreases each second, and for how many seconds.
pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>


new Timer[MAX_PLAYERS];
new TimerHandler[MAX_PLAYERS] = {0, ...};

CMD:decreasehp(playerid, params[])
{
    new target, Float:value, seconds;
    if(sscanf(params, "ufd", target, value,seconds))
    {
        SendClientMessage(playerid, -1, "USAGE: /decreasehp [playerid] [value] [seconds]");
    }
   
    if(value < 0) value*=-1;
    if(value == 0) value=10;

    if(seconds < 0) seconds *=-1;
    if(seconds == 0) seconds = 10;
   
    TimerHandler[target] = 0;
    Timer[target] = SetTimerEx("DecHP", 1000, true, "dfd", target, value, seconds);
    new str[128];
    format(str, sizeof str, "You are now decreasing ID %d's health by %.3f per second for %d seconds", target, value, seconds);
    SendClientMessage(playerid, -1, str);
    return 1;
}

forward DecHP(player, Float:amount, times);
public DecHP(player, Float: amount, times)
{
    if(TimerHandler[player] < times)
    {
        new Float: hp;
        GetPlayerHealth(player, hp);
        SetPlayerHealth(player, hp-amount);
        TimerHandler[player]++;
    }
    else
    {
        KillTimer(Timer[player]);
        TimerHandler[player] = 0;
    }
    return 1;
}
thank you but it's really complicated
Reply
#9

There's nothing complicated about it... Just put it in your code...
If you want to decrease ID 5's hp for 13.5 damage for 6 seconds you'd do /decreasehp 5 13.5 6
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)