Death system
#9

Well, it's not really all that complex...


pawn Код:
//Info[MAX_PLAYERS][MyEnumName] is just the array i use for my shit...You would use whatever you're using lol

//Inside your player info enum, add - Float:Health and Float:Armor

public OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid)
{
    if(!Info[damagedid][Down])
    {
        new Damage;
        switch(weaponid)
        {
            case 31: Damage = 25; //set the damage here for when this switch is over
            //This for instance makes M4 do 25 damage
        }
        if(Info[damagedid][Armor] > Damage) Info[damagedid][Armor] =- Damage;
        else if(Info[damagedid][Armor] == Damage) Info[damagedid][Armor] = 0;
        else if(Info[damagedid][Armor] < Damage && Info[damagedid][Armor] > 0)
        {
            new subval = floatround(Info[damagedid][Armor])-Damage;
            //takes their armor, subtracts 25 from it. Then it adds that negative number to their health
            //For instance, 15 armor -25 = -10. So we subract 10 basically.
            Info[damagedid][Armor] = 0;
            Info[damagedid][Health] += subval;
        }
        else Info[damagedid][Health] -= Damage;

        if(Info[damagedid][Health] < 1)
        {
            //Give them fall animation and show them the textdraw
            Info[damagedid][Down] = true; //inside of our player info enum - bool:Down
            Timer[damagedid] = SetTimer("Died", 120*1000, false);
            SetPlayerHealth(damagedid, 1);
        }
        else //if above isn't the case, we set their hp and armor so it shows on screen - this MIGHT not work correctly...untested
        {
            SetPlayerHealth(damagedid, Info[damagedid][Health]);
            SetPlayerArmor(damagedid, Info[damagedid][Armor]);
        }
    }
    return 1;
}

public Died(playerid)
{
    if(Info[playerid][Down])
    {
        Info[playerid][Down] = false;
        SetPlayerHealth(playerid, 0); //inside of onplayerdeath, do you hospital stuff
    }
    KillTimer(Timer[playerid]);
    return 1;
}

/*
If you're making a command or anything, you can check if the 'target' player is down by doing this

    if(!Info[TARGET_OR_WHATEVER][Down]) return SendClientMessage(playerid, 0xCC0000AA, "That player isn't down!");

The rest isn't really complicated...This was the most complicated part, and it's actually pretty simple

Also, CREATE the textdraw for them when they connect but don't SHOW it until later
*/
The damage formula was taken from an old post of mine and modified a little bit.
Reply


Messages In This Thread
Death system - by Unknown1195 - 24.04.2012, 21:04
Re: Death system - by MP2 - 24.04.2012, 21:08
Re: Death system - by Unknown1195 - 24.04.2012, 21:48
Re: Death system - by MP2 - 24.04.2012, 22:35
Re: Death system - by Unknown1195 - 25.04.2012, 09:30
Re: Death system - by MP2 - 25.04.2012, 10:11
Re: Death system - by Unknown1195 - 25.04.2012, 10:19
Re: Death system - by MP2 - 25.04.2012, 10:24
Re: Death system - by [ABK]Antonio - 25.04.2012, 10:54

Forum Jump:


Users browsing this thread: 1 Guest(s)