Custom Health System bug[Rep+]
#1

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

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

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

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

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

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

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

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

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

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
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)