SA-MP Forums Archive
Help with Health and Armour (Limits) - 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: Help with Health and Armour (Limits) (/showthread.php?tid=541996)



Help with Health and Armour (Limits) - kbalor - 16.10.2014

I need a little help. The codes below works so good but the problem was every time my health goes below 100 hp. Let say 70 hp then I picked up a health, now my health became 120 hp (It goes over 100 hp limit)

So can someone please help me with this what code should I add to make amount limit for both armour and health?

Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == lvapickup1)
	{
        new Float:armour;
        GetPlayerArmour(playerid,armour);
        if(armour < 100)
        {
            SetPlayerArmour(playerid, armour+50);
            GameTextForPlayer(playerid, "~g~Armour +50", 3000, 3);
        }
        else
        {

        }
	}
    else if(pickupid == lvapickup2)
    {
        new Float:hp;
        GetPlayerHealth(playerid,hp);
        if(hp < 100)
        {
            SetPlayerHealth(playerid, hp+50);
            GameTextForPlayer(playerid, "~g~Health +50", 3000, 3);
        }
        else
        {

        }
    }
    return 1;
}



Re: Help with Health and Armour (Limits) - RockyGamer - 16.10.2014

Well, then just make this:
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == lvapickup1)
    {
        SetPlayerArmour(playerid, 100)
    }
    else if(pickupid == lvapickup2)
    {
        SetPlayerHealth(playerid, 100)
    }
    return 1;
}



Re: Help with Health and Armour (Limits) - kbalor - 16.10.2014

Quote:
Originally Posted by RockyGamer
Посмотреть сообщение
Well, then just make this:
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == lvapickup1)
    {
        SetPlayerArmour(playerid, 100)
    }
    else if(pickupid == lvapickup2)
    {
        SetPlayerHealth(playerid, 100)
    }
    return 1;
}
This is the same code I used before. But my members suggested me to make it 50 hp.

thanks anyway.


Re: Help with Health and Armour (Limits) - Threshold - 16.10.2014

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == lvapickup1)
    {
        new Float:armour;
        GetPlayerArmour(playerid, armour);
        if(armour < 100.0)
        {
            new Float:var = armour + 50.0;
            SetPlayerArmour(playerid, (var > 100.0) ? (100.0) : (var));
            GameTextForPlayer(playerid, "~g~Armour +50", 3000, 3);
        }
        else
        {
            //?
        }
    }
    else if(pickupid == lvapickup2)
    {
        new Float:hp;
        GetPlayerHealth(playerid, hp);
        if(hp < 100.0)
        {
            new Float:var = hp + 50.0;
            SetPlayerHealth(playerid, (var > 100.0) ? (100.0) : (var));
            GameTextForPlayer(playerid, "~g~Health +50", 3000, 3);
        }
        else
        {
            //?
        }
    }
    return 1;
}
This line:
pawn Код:
SetPlayerArmour(playerid, (var > 100.0) ? (100.0) : (var));
Is basically the same as:
pawn Код:
if((armour + 50.0) > 100.0) SetPlayerArmour(playerid, 100.0);
else SetPlayerArmour(playerid, armour + 50.0);



Re: Help with Health and Armour (Limits) - RockyGamer - 16.10.2014

I'm sorry for not noticing that you sad you want +50 health. So here is the code for that!
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == lvapickup1)
    {
        new Float:armour;
        GetPlayerArmour(playerid,armour);
        if(armour < 50)
        {
            SetPlayerArmour(playerid, armor+50);
            GameTextForPlayer(playerid, "~g~Armour +50", 3000, 3);
        }
        else
        {
            SetPlayerArmour(playerid, 100);
            GameTextForPlayer(playerid, "~g~Armour 100%", 3000, 3);
        }
    }
    else if(pickupid == lvapickup2)
    {
        new Float:health;
        GetPlayerHealth(playerid,health);
        if(health < 50)
        {
            SetPlayerHealth(playerid, health+50);
            GameTextForPlayer(playerid, "~g~Health +50", 3000, 3);
        }
        else
        {
            SetPlayerHealth(playerid, 100);
            GameTextForPlayer(playerid, "~g~Health 100%", 3000, 3);
        }
    }
    return 1;
}
Once again I'm really sorry for not noticing.


Re: Help with Health and Armour (Limits) - kbalor - 16.10.2014

Amazing! Thanks Threshold ++ rep

good job explaining the last 2 codes.