Damage - Client vs Server [rep++]
#1

This is probably a hard question, so I will give rep to whoever can clarify this for me.

I have these three callbacks...
pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    return 1; // allow the bullet to cause damage
}

// called after a player updates that they have taken damage
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
    return 1;
}

// called when a player says they have given damage
public OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid, bodypart)
{
    return 1;
}
I know what OnPlayerWeaponShot does, (correct me if I'm wrong, but it is called when a player syncs to the server that they have fired their weapon), but I have questions about the other two.

I wan't to know what events trigger the other two callbacks. For now I'm assuming that OnPlayerGiveDamage is called when a player syncs to the server that they have hit another player, while OnPlayerTakeDamage is called when the hit player syncs back to say they have been hit.

I tend to be very particular in the way I write my code (correctness is everything), so I desire to understand exactly what happens server vs client side when a player gets shot, so as I can write my code as hack proof as possible.

Just so you know, I need to know this because I am implementing a custom damage system (that aims to be more realistic). Thanks in advance for your help.
Reply
#2

I believe OnPlayerTakeDamage & OnPlayerGiveDamage are called server-sided.
Reply
#3

Quote:
Originally Posted by Abagail
Посмотреть сообщение
I believe OnPlayerTakeDamage & OnPlayerGiveDamage are called server-sided.
Technically, all the callbacks are called server-sided, because the server has to call them, I understand that, what I need to know is what event/s cause these callbacks to be called by the server, sorry if I wasn't clear in my question.
Reply
#4

I don't really understand you exactly want...
Reply
#5

OnPlayerGiveDamage() is reported by the player WHO shoots another player.
OnPlayerTakeDamage() is reported by the player WHO was shot after taking damage.

If you want to use OnPlayerGiveDamage() which is what I recommend when creating your own damage system which any serious server should be using anyways since lagcomp as I have said many times is unreliable. You need to set all players to the same team to negate OnPlayerTakeDamage() I have created an include which I use to hook the SetPlayerTeam() and GetPlayerTeam() functions to do this behind the scenes.

pawn Код:
static PlayerTeam[MAX_PLAYERS];

forward TF_SetPlayerTeam(playerid, team);
public TF_SetPlayerTeam(playerid, team)
{
    PlayerTeam[playerid] = team;
    return SetPlayerTeam(playerid, 999);
}

#if defined _ALS_SetPlayerTeam
    #undef SetPlayerTeam
#else
    #define _ALS_SetPlayerTeam
#endif

#define SetPlayerTeam TF_SetPlayerTeam

forward TF_GetPlayerTeam(playerid);
public TF_GetPlayerTeam(playerid)
{
    return PlayerTeam[playerid];
}

#if defined _ALS_GetPlayerTeam
    #undef GetPlayerTeam
#else
    #define _ALS_GetPlayerTeam
#endif

#define GetPlayerTeam TF_GetPlayerTeam
Now there is a few other things you will need to do and it is quite a bit to explain but I will give a quick outline.

- Calculate damage in OnPlayerGiveDamage() you can set damage values to whatever you want
- Damage for certain weapons will not work (nades, vehicles) these are detectable in OnPlayerTakeDamage() where you can process custom damage values
- Directly call OnPlayerDeath() when a player dies you will also need to set a variable PlayerIsDead[playerid] = true; and return 1; on successive calls to OnPlayerDeath() it will happen
Reply
#6

Quote:
Originally Posted by Pottus
Посмотреть сообщение
OnPlayerGiveDamage() is reported by the player WHO shoots another player.
OnPlayerTakeDamage() is reported by the player WHO was shot after taking damage.

If you want to use OnPlayerGiveDamage() which is what I recommend when creating your own damage system which any serious server should be using anyways since lagcomp as I have said many times is unreliable. You need to set all players to the same team to negate OnPlayerTakeDamage() I have created an include which I use to hook the SetPlayerTeam() and GetPlayerTeam() functions to do this behind the scenes.
Thanks mate, That answers my question, and as always, you have been very informative. I would rep++ you, but I did that a few days ago for something else, so the forum won't let me.

I haven't actually had to use the player teams thing yet, becuase I've just been doing this, to avoid the default samp damage thing that samp does
pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if(!isBulletWeapon(weaponid)){
        new name[MAX_PLAYER_NAME+1];
        GetPlayerName(playerid, name, sizeof(name));
        printf("possible malicious weapon data sent by %s(%d)!", name, playerid);
        return 0; // no damage, the client may be hacking
    }
   
    if(hittype == HITTYPE_PLAYER){
        //CustomWeaponDamage(playerid, weaponid, hittype, hitid);
        return 0; // we are doing custom damage, so prevent damage being done by samp
    }

    return 1; // allow the bullet to cause damage
}
Reply
#7

How about the damage on every weapon type? you dont like it? it's much easier with SetPlayerHealth
Reply
#8

Not a good idea to do that because then players won't actually see bullets (if there ever was such a thing)

@XGreen easier doesn't mean anything if the quality is low.
Reply
#9

Quote:
Originally Posted by XGreen
Посмотреть сообщение
How about the damage on every weapon type? you dont like it? it's much easier with SetPlayerHealth
No, I don't like the samp default damage thing at all I've already got a basic system going that deals out damage how I want it done, depending on what bodypart is hit with what weapon. I just made this thread so as I could ascertain that I was not making any critical mistakes in regard to how I wanted to do it.

I'm not trying to do things the easy way, I'm trying to do them the correct way.
Reply
#10

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Not a good idea to do that because then players won't actually see bullets (if there ever was such a thing)

@XGreen easier doesn't mean anything if the quality is low.
I see, I understand, and now I don't like. I will switch to the teams thing
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)