SA-MP Forums Archive
Custom Health System bug[Rep+] - 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: Custom Health System bug[Rep+] (/showthread.php?tid=317154)



Custom Health System bug[Rep+] - KingHual - 10.02.2012

Hello, well I've got a pretty weird bug here. Or 2 actually... My script:
pawn Code:
new Float:pHP[MAX_PLAYERS], bool:test, KillerID[MAX_PLAYERS], WeapID[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
    pHP[playerid] = 100;
    test = true;
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    SendDeathMessage(KillerID[playerid], playerid, WeapID[playerid]);
    return 1;
}

public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid)
{
    if (test == true)
    {
        pHP[damagedid]-=amount;
        if (pHP[damagedid] < 1)
        {
            KillerID[damagedid] = playerid;
            WeapID[damagedid] = weaponid;
            SetPlayerHealth(damagedid, 0);
        }
        else
        {
            SetPlayerHealth(damagedid, pHP[damagedid]);
        }
        test = false;
    }
    else
    {
        test = true;
    }
    return 1;
}
Here are the two issues: 1st - With some weapons, like the desert eagle, OnPlayerGiveDamage gets called 2 times (That's what the variable "test" is used for, but it looks like it doesn't fix it). And 2nd - Some low-damage weapons (like fists, dual UZIs, flowers etc.) are actually GIVING the attacked player HP, not taking it from him... Please help if you've got any ideas on how to fix this script.


Re: Custom Health System bug[Rep+] - IceCube! - 10.02.2012

SetPlayerHealth(damagedid, -pHP[damagedid]); - is take away simple maths...

The second problem are you calling the code from else where?


Re: Custom Health System bug[Rep+] - MP2 - 10.02.2012

I made this a while ago: http://pastebin.com/JGLgHJTX

All players must be on the same team for it to work (SetPlayerTeam - cancels out native damage system).


Re: Custom Health System bug[Rep+] - KingHual - 10.02.2012

Quote:
Originally Posted by MP2
View Post
I made this a while ago: http://pastebin.com/JGLgHJTX

All players must be on the same team for it to work (SetPlayerTeam - cancels out native damage system).
Ahhhhhh thank you! I never thought of using SetPlayerTeam to cancel the native damage! +Rep for u :3


Re: Custom Health System bug[Rep+] - MP2 - 10.02.2012

By the way, I don't understand this:

pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
    SendDeathMessage(KillerID[playerid], playerid, WeapID[playerid]);
    return 1;
}
Shouldn't it just be

pawn Code:
SendDeathMessage(killerid, playerid, reason);
?


Re: Custom Health System bug[Rep+] - KingHual - 10.02.2012

Quote:
Originally Posted by MP2
View Post
By the way, I don't understand this:

pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
    SendDeathMessage(KillerID[playerid], playerid, WeapID[playerid]);
    return 1;
}
Shouldn't it just be

pawn Code:
SendDeathMessage(killerid, playerid, reason);
?
Well, that was another bug, just because SetPlayerHealth(playerid, 0) doesn't return the correct values when the player dies... Like, if I killed someone with a shotgun, it would return he just died or something.


Re: Custom Health System bug[Rep+] - MP2 - 10.02.2012

Right, but if you shoot someone, then ten minutes they suicide, it's going to say that the person who shot them killed them. What if they leave the server? That'll cause the script to fail to execute if used in an array.
It should still detect killerid with the custom health system. Not sure.


Re: Custom Health System bug[Rep+] - KingHual - 10.02.2012

Quote:
Originally Posted by MP2
View Post
Right, but if you shoot someone, then ten minutes they suicide, it's going to say that the person who shot them killed them. What if they leave the server? That'll cause the script to fail to execute if used in an array.
It should still detect killerid with the custom health system. Not sure.
Well, I only showed you a part of the script, the critical one. There's also "OnPlayerTakeDamage" in my script, which makes the variables KillerID[playerid] and WeapID[playerid] invalid values like INVALID_PLAYER_ID and 500. But in the test, I commented it out, so I thought it's not the problem and left it like that.


Re: Custom Health System bug[Rep+] - IceCube! - 10.02.2012

Then use a variable to help decide which to use on /kill just cahgen the variable to somthing else, And if it doesnt change the player killed him... and use of other timers and stuff