Reallying annoying (OnPlayerTakeDamage)
#1

pawn Код:
new Float:health,Float:armor;
    GetPlayerArmour(playerid,armor);
    GetPlayerHealth(playerid,health);
    if(GetPlayerWeapon(issuerid) == 22 || GetPlayerWeapon(issuerid) == 23)
    {
        if(armor > 0)
        {
            SetPlayerArmour(playerid,armor-40);
        }
        else if(armor < 0 && health > 0)
        {
            SetPlayerHealth(playerid,health-40);
        }
    }
is my code for OnPlayerTakeDamage.. How come when they're under 0 armor, there armor gets set back to 100?
Reply
#2

I recommend using a switch, try this; If it doesn't work, there's something wrong elsewhere.

pawn Код:
new
    Float:health,
    Float:armour
;
   
    GetPlayerArmour(playerid, armour);
    GetPlayerHealth(playerid, health);
   
    switch(weaponid)
    {
        case 22:
        {
            if(armour > 0)
            {
                SetPlayerArmour(playerid, armour-=40);
            }
            else
            {
                SetPlayerHealth(playerid, health-=40);
            }
        }
        case 23:
        {
            if(armour > 0)
            {
                SetPlayerArmour(playerid, armour-=40);
            }
            else
            {
                SetPlayerHealth(playerid, health-=40);
            }
        }
    }
Reply
#3

coz youre setting a negative value to armor:
pawn Код:
if(armor > 0)
assuming armor is 1.0, i get taken away 40.0. 1.0 - 40.0 = -39.0 so you need another way to estimate the "give armor" amount.
what do you want to accomplish with the routine? the more you tell us about what the script is meant to do, the better the algorithm can be adopted.
Reply
#4

The script is ment to make it so if they have armor, the 9mm/silenced 9mm will take away 40 armor instead of the default. But everytime I get the armor gone, and down to the health, it refills their armor, But I want it so when their armor is gone, it starts taking down their health and DOESN'T refill their armor.
edit: Guy with second post.. that makes it so the armor doesnt refill, but one shot brings down all there armor or health.
Reply
#5

pawn Код:
public OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid)
{
    new Float:WepDamage = floatstr(GetPlayerWeaponDamage(weaponid));
    if(pInfo[damagedid][Arrmor] >= WepDamage)
    {
        pInfo[damagedid][Arrmor] -= WepDamage;
    }
    else if(pInfo[damagedid][Arrmor] < WepDamage && pInfo[damagedid][Arrmor] > 0)
    {
        pInfo[damagedid][Arrmor] -= WepDamage;
        if(pInfo[damagedid][Arrmor] < 0)
        {
            pInfo[damagedid][Health] += pInfo[damagedid][Arrmor];
            pInfo[damagedid][Arrmor] = 0;
        }
    }
    else if(pInfo[damagedid][Arrmor] == 0)
    {
        pInfo[damagedid][Health] -= WepDamage;
        if(pInfo[damagedid][Health] <= 0)
        {
            SendDeathMessage(playerid, damagedid, weaponid);
            SetPlayerHealth(damagedid, 0);
        }
    }
    return 1;
}
Maybe you can salvage something from this
Reply
#6

Continuing what Babul said, I think you ought to try something along the lines of
pawn Код:
if(armour > 0.0)
{
   SetPlayerArmour(playerid, (armour >= 40.0) ? (armour - 40.0) : (0.0));
}
else if(health > 0.0)
{
   SetPlayerHealth(playerid, (health >= 40.0) ? (health - 40.0) : (0.0));
}
Setting health/armor to negative values can have strange effects.
Reply
#7

Try to salvage something out of my RP mode, then..

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    if(issuerid != INVALID_PLAYER_ID)
    {
        new
            Float:armour,
            Float:health,
            Float:P[3]
        ;
           
        GetPlayerArmour(playerid, armour);
        GetPlayerHealth(playerid, health);
           
        if(armour != 0) //Armor?
        {  
            switch(weaponid)
            {
                case 0: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-3); } //Fists
                case 1: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-5); } //Brass Knuckles
                case 2: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-7); } //Golf Club
                case 3: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-5); } //Nite Stick
                case 4: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-10); } //Knife
                case 5: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-9); } //Baseball Bat
                case 6: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-9); } //Shovel
                case 7: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-6); } //Pool Cue
                case 8: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-12); } //Katana
                case 9: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-25); } //Chainsaw (When the hell is this going to be used?)
               
                                                        /* Dildos & Flowers, Don't need to edit these... */
                //case 10..14: {    SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-6); }
                                                                        /* Continue.. */
                                                                       
                case 15: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-5); } //Cane
                case 16: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-75); } //Grenade
                //case 17: {        SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-15); } //Tear gas (How the hell do you get hurt by one of these?)
                case 18: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-45); } //Molotov Cocktail
                case 22: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-13); } //Colt 45 (9mm)
                case 23:
                {
                    if(UsingTazer[issuerid] == 1) //They were being tazed!
                    {
                        UsingTazer[issuerid] = -1;
                        expAmmo[issuerid] = -1;
                        BeingTazed[playerid] = 1;
                        FreezePlayer(playerid, 1);

                        ApplyAnimation(playerid, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 0, 0);
                        ApplyAnimation(playerid, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 0, 0); //Apply it twice so it works
                        SetTimerEx("Unfreeze", 5000, false, "i", playerid); //5 second taze
                       
                        SetPlayerHealth(playerid, health-1.0);
                       
                        UserInfo[issuerid][TazerDarts]--;

                        SendClientMessage(playerid, COLOR_SUCCESSFUL, "* You have been shot with a Tazer!");
                        SendClientMessage(issuerid, COLOR_SUCCESSFUL, "* You have hit them with a tazer. You have switched back to standard rounds!");
                    }
                    else { SetPlayerHealth(playerid, health+amount);        SetPlayerHealth(playerid, health-12); } //Silenced Pistol
                }
                case 24:
                {
                    if(expAmmo[issuerid] == 1) { //Are they using Explosive Ammunition?
                               
                        GetPlayerPos(playerid, P[0], P[1], P[2]);
                       
                        SetPlayerHealth(playerid, health+amount);
                        SetPlayerHealth(playerid, health-45);

                        expParticle[playerid] = CreateObject(18686, P[0], P[1], P[2], 0, 0, 0, 30); //Explosion particle!
                        SetTimerEx("DestroyObjectP", 1500, 0, "i", playerid);
                       
                        //UserInfo[issuerid][ExplosiveAmmo]--;
                        if(UserInfo[issuerid][ExplosiveAmmo] <= 0) { expAmmo[issuerid] = -1;    SendClientMessage(issuerid, COLOR_ERROR, "* You have ran out of Incendiary rounds, and have been switched back to Standard rounds!"); }
                    }
                    else {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-35);  } //Not using Explosive Ammo!
                }
                case 25:
                {
                    if(expAmmo[issuerid] == 1) { //Are they using Explosive Ammunition?
                               
                        GetPlayerPos(playerid, P[0], P[1], P[2]);
                       
                        SetPlayerHealth(playerid, health+amount);
                        SetPlayerHealth(playerid, health-65);

                        expParticle[playerid] = CreateObject(18686, P[0], P[1], P[2], 0, 0, 0, 30); //Explosion particle!
                        SetTimerEx("DestroyObjectP", 350, 0, "i", playerid);
                       
                        //UserInfo[issuerid][ExplosiveAmmo]--;
                        if(UserInfo[issuerid][ExplosiveAmmo] <= 0) { expAmmo[issuerid] = -1;    SendClientMessage(issuerid, COLOR_ERROR, "* You have ran out of Incendiary rounds, and have been switched back to Standard rounds!"); }
                    }
                    else {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-25);  } //Not using Explosive Ammo!
                }
                case 26: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-23); } //Sawn-off Shotgun
                case 27: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-20); } //SPAS 12 (Auto shotgun does LESS damage!)
                case 28: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-7); } //Uzi
                case 29: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-12); } //MP5
                case 30: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-15); } //AK47
                case 31: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-14); } //M4A1
                case 32: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-8); } //Tec9
                case 33:
                {              
                    if(expAmmo[issuerid] == 1) { //Are they using Explosive Ammunition?
                               
                        GetPlayerPos(playerid, P[0], P[1], P[2]);
                       
                        SetPlayerHealth(playerid, health+amount);
                        SetPlayerHealth(playerid, health-45);

                        expParticle[playerid] = CreateObject(18686, P[0], P[1], P[2], 0, 0, 0, 30); //Explosion particle!
                        SetTimerEx("DestroyObjectP", 350, 0, "i", playerid);
                       
                        //UserInfo[issuerid][ExplosiveAmmo]--;
                        if(UserInfo[issuerid][ExplosiveAmmo] <= 0) { expAmmo[issuerid] = -1;    SendClientMessage(issuerid, COLOR_ERROR, "* You have ran out of Incendiary rounds, and have been switched back to Standard rounds!"); }
                    }
                    else {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-25);  } //Not using Explosive Ammo!
                }
                case 34:
                {
                    if(expAmmo[issuerid] == 1) { //Are they using Explosive Ammunition?
                               
                        GetPlayerPos(playerid, P[0], P[1], P[2]);
                       
                        SetPlayerHealth(playerid, health+amount);
                        SetPlayerHealth(playerid, health-75);

                        expParticle[playerid] = CreateObject(18686, P[0], P[1], P[2], 0, 0, 0, 30); //Explosion particle!
                        SetTimerEx("DestroyObjectP", 350, 0, "i", playerid);
                       
                        //UserInfo[issuerid][ExplosiveAmmo]--;
                        if(UserInfo[issuerid][ExplosiveAmmo] <= 0) { expAmmo[issuerid] = -1;    SendClientMessage(issuerid, COLOR_ERROR, "* You have ran out of Incendiary rounds, and have been switched back to Standard rounds!"); }
                    }
                    else {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-50);  } //Not using Explosive Ammo!
                }
                case 35:
                {
                    if(random(300) == 35) //Random chance to survive it because they have armor..
                    {      
                        SetPlayerHealth(playerid, 5);      
                        SendClientMessage(playerid, COLOR_SUCCESSFUL, "* Somehow you survive!");
                        return 1;
                    }
                    else {
                        return      SetPlayerHealth(playerid, 0);
                    }
                }
               
            }
        }
        else //no armor
        {
            switch(weaponid)
            {
                case 0: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-3); } //Fists
                case 1: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-5); } //Brass Knuckles
                case 2: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-7); } //Golf Club
                case 3: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-5); } //Nite Stick
                case 4: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-10); } //Knife
                case 5: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-9); } //Baseball Bat
                case 6: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-9); } //Shovel
                case 7: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-6); } //Pool Cue
                case 8: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-12); } //Katana
                case 9: {           SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-25); } //Chainsaw (When the hell is this going to be used?)
               
                                                        /* Dildos & Flowers, Don't need to edit these... */
                //case 10..14: {    SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-6); }
                                                                        /* Continue.. */
                                                                       
                case 15: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-5); } //Cane
                case 16: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-75); } //Grenade
                //case 17: {        SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-15); } //Tear gas (How the hell do you get hurt by one of these?)
                case 18: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-45); } //Molotov Cocktail
                case 22: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-13); } //Colt 45 (9mm)
                case 23:
                {
                    if(UsingTazer[issuerid] == 1) //They were being tazed!
                    {
                        UsingTazer[issuerid] = -1;
                        expAmmo[issuerid] = -1;
                        BeingTazed[playerid] = 1;
                        FreezePlayer(playerid, 1);

                        ApplyAnimation(playerid, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 0, 0);
                        ApplyAnimation(playerid, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 0, 0); //Apply it twice so it works!
                        SetTimerEx("Unfreeze", 5000, false, "i", playerid); //5 second taze
                       
                        SetPlayerHealth(playerid, health-1.0);
                       
                        UserInfo[issuerid][TazerDarts]--;

                        SendClientMessage(playerid, COLOR_SUCCESSFUL, "* You have been shot with a Tazer!");
                        SendClientMessage(issuerid, COLOR_SUCCESSFUL, "* You have hit them with a tazer. You have switched back to standard rounds!");
                    }
                    else { SetPlayerHealth(playerid, health+amount);        SetPlayerHealth(playerid, health-12); } //Silenced Pistol
                }
                case 24:
                {
                    if(expAmmo[issuerid] == 1) { //Are they using Explosive Ammunition?
                               
                        GetPlayerPos(playerid, P[0], P[1], P[2]);
                       
                        SetPlayerHealth(playerid, health+amount);
                        SetPlayerHealth(playerid, health-60);

                        expParticle[playerid] = CreateObject(18686, P[0], P[1], P[2], 0, 0, 0, 30); //Explosion particle!
                        SetTimerEx("DestroyObjectP", 1500, 0, "i", playerid);
                       
                        //UserInfo[issuerid][ExplosiveAmmo]--;
                        if(UserInfo[issuerid][ExplosiveAmmo] <= 0) { expAmmo[issuerid] = -1;    SendClientMessage(issuerid, COLOR_ERROR, "* You have ran out of Incendiary rounds, and have been switched back to Standard rounds!"); }
                    }
                    else {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-35);  } //Not using Explosive Ammo!
                }
                case 25:
                {
                    if(expAmmo[issuerid] == 1) { //Are they using Explosive Ammunition?
                               
                        GetPlayerPos(playerid, P[0], P[1], P[2]);
                       
                        SetPlayerHealth(playerid, health+amount);
                        SetPlayerHealth(playerid, health-49);

                        expParticle[playerid] = CreateObject(18686, P[0], P[1], P[2], 0, 0, 0, 30); //Explosion particle!
                        SetTimerEx("DestroyObjectP", 350, 0, "i", playerid);
                       
                        //UserInfo[issuerid][ExplosiveAmmo]--;
                        if(UserInfo[issuerid][ExplosiveAmmo] <= 0) { expAmmo[issuerid] = -1;    SendClientMessage(issuerid, COLOR_ERROR, "* You have ran out of Incendiary rounds, and have been switched back to Standard rounds!"); }
                    }
                    else {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-45);  } //Not using Explosive Ammo!
                }
                case 26: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-40); } //Sawn-off Shotgun
                case 27: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-37); } //SPAS 12 (Auto shotgun does LESS damage!)
                case 28: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-13); } //Uzi
                case 29: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-16); } //MP5
                case 30: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-20); } //AK47
                case 31: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-17); } //M4A1
                case 32: {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-14); } //Tec9
                case 33:
                {              
                    if(expAmmo[issuerid] == 1) { //Are they using Explosive Ammunition?
                               
                        GetPlayerPos(playerid, P[0], P[1], P[2]);
                       
                        SetPlayerHealth(playerid, health+amount);
                        SetPlayerHealth(playerid, health-67);

                        expParticle[playerid] = CreateObject(18686, P[0], P[1], P[2], 0, 0, 0, 30); //Explosion particle!
                        SetTimerEx("DestroyObjectP", 350, 0, "i", playerid);
                       
                        //UserInfo[issuerid][ExplosiveAmmo]--;
                        if(UserInfo[issuerid][ExplosiveAmmo] <= 0) { expAmmo[issuerid] = -1;    SendClientMessage(issuerid, COLOR_ERROR, "* You have ran out of Incendiary rounds, and have been switched back to Standard rounds!"); }
                    }
                    else {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-55);  } //Not using Explosive Ammo!
                }
                case 34:
                {
                    if(expAmmo[issuerid] == 1) { //Are they using Explosive Ammunition?
                               
                        GetPlayerPos(playerid, P[0], P[1], P[2]);
                       
                        SetPlayerHealth(playerid, health+amount);
                        SetPlayerHealth(playerid, health-92);

                        expParticle[playerid] = CreateObject(18686, P[0], P[1], P[2], 0, 0, 0, 30); //Explosion particle!
                        SetTimerEx("DestroyObjectP", 350, 0, "i", playerid);
                       
                        //UserInfo[issuerid][ExplosiveAmmo]--;
                        if(UserInfo[issuerid][ExplosiveAmmo] <= 0) { expAmmo[issuerid] = -1;    SendClientMessage(issuerid, COLOR_ERROR, "* You have ran out of Incendiary rounds, and have been switched back to Standard rounds!"); }
                    }
                    else {          SetPlayerHealth(playerid, health+amount);       SetPlayerHealth(playerid, health-75);  } //Not using Explosive Ammo!
                }
                case 35:
                {
                    return      SetPlayerHealth(playerid, 0);
                }
               
            }
        }
    }
    return true;
}
Reply
#8

I took some from your script.. But that makes it so they dont lose armor, just health.. heres my new script
pawn Код:
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid)
{
    new Float:armor = GetPlayerArmour(playerid,armor);
    new Float:health = GetPlayerHealth(playerid,health);
    if(GetPlayerWeapon(playerid) == 22 || GetPlayerWeapon(playerid) == 23)
    {
        if(armor != 0)
        {
            SetPlayerArmour(damagedid,armor-35);
        }
    }
    return 1;
}
Reply
#9

oh you swapped playerid with damageid, the amount depends on the shooter atm. you had no armor when shooting, right? ^^
Reply
#10

I used onplayertakedamage then some one above recommended I used OnPlayerGiveDamage? I'm so confused right now.. The first way I had it, there was a bug so if they had armor, you would shoot all their armor down, then their armor would fill back up..
Reply
#11

Quote:
Originally Posted by Azzeto
Посмотреть сообщение
I used onplayertakedamage then some one above recommended I used OnPlayerGiveDamage? I'm so confused right now.. The first way I had it, there was a bug so if they had armor, you would shoot all their armor down, then their armor would fill back up..
lol my bad, I was trying to show you the mathematical formula I used with my OnPlayerGiveDamage which would simulate something similar to what you're trying to achieve. OnPlayerTakeDamage is when they are hit on their screen, OnPlayerGiveDamage is when you hit their skin
Reply
#12

oh btw: joypad users will benefit from OnPlayerGiveDamage(), coz they can use their aim function, where lag shooters will still need to aim in front of a player - its your decision which "group" you want to disappoint ><
Reply
#13

Ok, well Imma use OnPlayerTakeDamage, but how could I do this, just make the 9mm and silenced 9mm stronger? Because my way seems to fail.
Reply
#14

I'll just bump this instead of making a new topic.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)