SA-MP Forums Archive
how to create a command that takes 1 HP per sec from a player to another player? - 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: how to create a command that takes 1 HP per sec from a player to another player? (/showthread.php?tid=540013)



how to create a command that takes 1 HP per sec from a player to another player? - JJack - 02.10.2014

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..


Re: how to create a command that takes 1 HP per sec from a player to another player? - VinPure - 02.10.2014

GetPlayerHealth
SetPlayerHealth


Re: how to create a command that takes 1 HP per sec from a player to another player? - JJack - 02.10.2014

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


Re: how to create a command that takes 1 HP per sec from a player to another player? - The__ - 02.10.2014

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.


Re: how to create a command that takes 1 HP per sec from a player to another player? - DavidBilla - 02.10.2014

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...


Respuesta: how to create a command that takes 1 HP per sec from a player to another player? - SickAttack - 02.10.2014

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;
}



Re: how to create a command that takes 1 HP per sec from a player to another player? - JJack - 02.10.2014

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.