Help with Health and Armour (Limits)
#1

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;
}
Reply
#2

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;
}
Reply
#3

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.
Reply
#4

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);
Reply
#5

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.
Reply
#6

Amazing! Thanks Threshold ++ rep

good job explaining the last 2 codes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)