how to create a command that takes 1 HP per sec from a player to another player?
#1

Hello,
how to create a command that takes 1 HP per sec from a player to another player?
for example: /gethp [Anyplayer] and each sec it gives me 1 HP and the other player(the one which the command was being used on) looses 1 HP per 1 sec? and a GameText appears for the one who've used the cmd like "Getting HP" and for the target "Loosing HP"
I'm kinda confused.... not sure how it exactly works..
Reply
#2

GetPlayerHealth
SetPlayerHealth
Reply
#3

Quote:
Originally Posted by VinPure
Посмотреть сообщение
GetPlayerHealth
SetPlayerHealth
Ik them already I just need an example... Im kinda confused... also you didn't mention everything.
Reply
#4

Thing is, you won't learn nothing if you get examples after examples. You have to be creative and use what you know + what info we give you.


Your functions:
GetPlayerHealth
SetPlayerHealth

You'll need to create a command, you'll need to create a timer.
Reply
#5

pawn Код:
new Float:phealth,Float:thealth;
GetPlayerHealth(playerid,phealth);
GetPlayerHealth(targetid,thealth);
if((phealth<100)&&(thealth>0))
{
    SetPlayerHealth(playerid,phealth++);
    SetPlayerHealth(targetid,thealth--);
}
This is only an example, i believe you do know how to create a command for this and about getting the targetid and making these codes inside a timer...
Reply
#6

pawn Код:
new Timer[MAX_PLAYERS];

CMD:gethp(playerid, params)
{
    new lookupid;
    if(sscanf(params, "u", lookupid)) return SendClientMessage(playerid, -1, "Usage: /gethp (id/name).");
    Timer[playerid] = SetTimerEx("TransferHealth", 1000, true, "ii", playerid, lookupid);
    return 1;
}

forward public TransferHealth(playerid, lookupid);
{
    new string[144], Float:health;
    GetPlayerHealth(playerid, health);
    if(health <= 1)
    {
        KillTimer(Timer[playerid]);
        return 1;
    }
    GetPlayerHealth(lookupid, health);
    if(health >= 100)
    {
        KillTimer(Timer[playerid]);
        return 1;
    }
    SetPlayerHealth(playerid, GetPlayerHealth(playerid) - 1);
    format(string, sizeof(string), "Transfering health to~n~%s (%d)", PlayerName(lookupid), lookupid);
    GameTextForPlayer(playerid, string, 5000, 2);
    SetPlayerHealth(lookupid, GetPlayerHealth(lookupid) + 1);
    format(string, sizeof(string), "Receiving health from~n~%s (%d)", PlayerName(playerid), playerid);
    GameTextForPlayer(lookupid, string, 5000, 2);
    return 1;
}

stock PlayerName(playerid)
{
    new pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    return pname;
}
Reply
#7

Thanks anyways, I was just a little bit confused...
EDIT: Forgot to add something( how to stop it by a command? ) Well I will actually try it out myself.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)