OnPlayerGiveDamage
#1

Hi there, can anyone explain to me why this callback isn't allowing damage to go through under the following circumstances?

pawn Код:
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid)
{
    new playername[24], string[128];
    GetPlayerName(playerid, playername, 24);
   
    if(damagedid != INVALID_PLAYER_ID && CoolDownTime[playerid] == 0)
    {
        if(gTeam[playerid] == TEAM_POLICE && gTeam[damagedid] == TEAM_CIVILIAN)
        {
            if(GetPlayerWantedLevel(damagedid) == 0 && Warning[playerid] <= 2)
            {
                format(string, sizeof(string), "%s[%d] has been warned by auto-admin. Reason: Attacking innocent players.", playername, playerid);
                SendClientMessageToAll(COLOR_ADMIN, string);
                CoolDownTime[playerid] = 1;
                SetTimer("CoolDownTimer", 10000, 0);
                Warning[playerid]++;
            }
        }
    }
   
    if(damagedid != INVALID_PLAYER_ID && CoolDownTime[playerid] == 0)
    {
        if(gTeam[playerid] == TEAM_CIVILIAN && gTeam[damagedid] == TEAM_POLICE)
        {
            if(GetPlayerWantedLevel(playerid) >= 0 && GetPlayerWantedLevel(playerid) <= 5)
            {
                SendClientMessage(playerid, COLOR_WANTED, "Your wanted level has increased.");
                CoolDownTime[playerid] = 1;
                SetTimer("CoolDownTimer", 10000, 0);
                SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) +1);
            }
        }
    }
    return 1;
}
I realise it's not a very efficient way of coding.
Reply
#2

I suggest you use OnPlayerTAKEdamage callback and try this code in it, see if that works.
Reply
#3

That does seem to function properly, i can't understand why using the code under ONPlayerGiveDamage would block the damage though.

Either way thankyou for your quick reply. +1
Reply
#4

"block the damage" ?
Reply
#5

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
"block the damage" ?
As in the damagedid is in a god mode like state, with no health being removed at all.
Reply
#6

Ok this is really annoying now, sometimes it works fine under OnPlayerTakeDamage but sometimes it still puts players in god-mode.

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
    new playername[24], string[128];
    GetPlayerName(issuerid, playername, 24);

    if(CoolDownTime[issuerid] == 0)
    {
        if(gTeam[issuerid] == TEAM_POLICE && gTeam[playerid] == TEAM_CIVILIAN)
        {
            if(GetPlayerWantedLevel(playerid) == 0 && Warning[issuerid] <= 2)
            {
                format(string, sizeof(string), "%s[%d] has been warned by auto-admin. Reason: Attacking innocent players.", playername, issuerid);
                SendClientMessageToAll(COLOR_ADMIN, string);
                CoolDownTime[issuerid] = 1;
                SetTimer("CoolDownTimer", 10000, 0);
                Warning[issuerid]++;
            }
        }
    }
    else return 1;

    if(CoolDownTime[issuerid] == 0)
    {
        if(gTeam[issuerid] == TEAM_CIVILIAN && gTeam[playerid] == TEAM_POLICE)
        {
            if(GetPlayerWantedLevel(issuerid) == 0)
            {
                SendClientMessage(issuerid, COLOR_WANTED, "Your wanted level has increased.");
                CoolDownTime[issuerid] = 1;
                SetTimer("CoolDownTimer", 10000, 0);
                SetPlayerWantedLevel(issuerid, GetPlayerWantedLevel(issuerid) +1);
            }
        }
    }
    else return 1;
    return 1;
}
Could it be a bug with the two new callbacks? (OnPlayerGiveDamage, OnPlayerTakeDamage)
Reply
#7

Could it be a problem with
pawn Код:
CoolDownTime[issuerid] = 1;
SetTimer("CoolDownTimer", 10000, 0);
As you dont specify in the timer which person your going to cool down?

Can you please give some more information as to what is going wrong, and what you are trying to do?
Reply
#8

Basically if a police officer shoots an innocent player it will warn them.

If an innocent player shoots a cop, they will recieve 1 wanted star.

Sometimes when a cop shoots another player the player that has been shot will lose no health at all, he will be in a god-mode like state.

here is my timer public:

pawn Код:
public CoolDownTimer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && CoolDownTime[i] == 1)
        {
            CoolDownTime[i] = 0;
        }
    }
}
Note: Commenting out OnPlayerGive/TakeDamage callbacks stops the problem.
Reply
#9

OnPlayerGiveDamage is not designed to be accurate. It's only really useful for checking if the player is engaged in something.

Use OnPlayerTakeDamage for a more stable and reliable result, however even this will occasionally return strange values at times due to lag.

If you script serverside health, you can actually observe health bounce up and down the bar thanks to this phenomenon.
Reply
#10

I've never had any accuracy problems with the callbacks, and the callbacks cannot prevent health loss, I believe you are suffering some kind of team bug where you're not setting the team id properly with SetSpawnInfo
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)