Trying to make anti health hack
#1

So im trying to make an anti health hack for my server and this is what I have so far:

Код:
new Float:pHealth[MAX_PLAYERS] // Variable to store the player's health
OnPlayerTakeDamage

Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
    if(issuerid != INVALID_PLAYER_ID) // If not self-inflicted
    {
        if(GetPlayerTeam(issuerid) != GetPlayerTeam(playerid)) // If the players are not in the same team 
        {
        	GetPlayerHealth(playerid,pHealth[playerid]);
        	SetPlayerHealth(playerid,pHealth[playerid]-amount);
        }
    }
    if(issuerid == INVALID_PLAYER_ID) // If self-inflicted
    {
        GetPlayerHealth(playerid,pHealth[playerid]);
    	SetPlayerHealth(playerid,pHealth[playerid]-amount);
    }
    return 0;
}
OnPlayerSpawn

Код:
OnPlayerSpawn(playerid)
{
     	pHealth[playerid] = 100.0;
        return 1;
}
So could anyone tell me is this code good or I need to improve it? I don't need the anti-armour hack.

EDIT: I added the self inflicted damage.
Reply
#2

Here is the deal dude, the new SAMP version SHOULD have a Skinhit system that controls damage the new sync doesn't always work when you shoot the skin. That means you need to use OnPlayerGiveDamage() in my view OnPlayerTakeDamage() is completely obsolete this method makes health hacking impossible even if the player locks their health they will still be killed.
Reply
#3

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Here is the deal dude, the new SAMP version SHOULD have a Skinhit system that controls damage the new sync doesn't always work when you shoot the skin. That means you need to use OnPlayerGiveDamage() in my view OnPlayerTakeDamage() is completely obsolete this method makes health hacking impossible even if the player locks their health they will still be killed.
So if I replace the OnPlayerTakeDamage with this OnPlayerGiveDamage will that work?

Код:
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart)
{
	if(playerid != INVALID_PLAYER_ID) // If not self-inflicted
        {
              if(GetPlayerTeam(playerid) != GetPlayerTeam(damagedid))
	      {
   	           GetPlayerHealth(damagedid,pHealth[damagedid]);
    	           SetPlayerHealth(damagedid,pHealth[damagedid]-amount);
	      }
	}
	if(playerid == damagedid) // If self-inflicted
        {
   		GetPlayerHealth(damagedid,pHealth[damagedid]);
    	        SetPlayerHealth(damagedid,pHealth[damagedid]-amount);
	}
	return 1;
}
Reply
#4

It's a bit more complicated than that Remba, I'm sorry I should have explained this you need to set all players to the same team so they can't damage each other otherwise they will be taking double damage. You will also need some variables to indicate who killed the player so that OnPlayerDeath() knows who killed the player.

Here is the basic logic structure.
pawn Код:
new KilledBy[MAX_PLAYERS];
new KillReason[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
    ...
    // Killed by no one (reset each spawn)
    KilledBy[playerid] = INVALID_PLAYER_ID;
}

public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart)
{
    ...
    // Player was killed set their killer id
    KilledBy[damagedid] = playerid;
    KillReason[damagedid] = weaponid;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    // Player was killed by another player set the killerid
    if(KilledBy[playerid] != INVALID_PLAYER_ID)
    {
        killerid = KilledBy[playerid];
        reason = KillReason[damagedid];
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
It's a bit more complicated than that Remba, I'm sorry I should have explained this you need to set all players to the same team so they can't damage each other otherwise they will be taking double damage. You will also need some variables to indicate who killed the player so that OnPlayerDeath() knows who killed the player.

Here is the basic logic structure.
pawn Код:
new KilledBy[MAX_PLAYERS];
new KillReason[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
    ...
    // Killed by no one (reset each spawn)
    KilledBy[playerid] = INVALID_PLAYER_ID;
}

public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart)
{
    ...
    // Player was killed set their killer id
    KilledBy[damagedid] = playerid;
    KillReason[damagedid] = weaponid;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    // Player was killed by another player set the killerid
    if(KilledBy[playerid] != INVALID_PLAYER_ID)
    {
        killerid = KilledBy[playerid];
        reason = KillReason[damagedid];
    }
    return 1;
}
Thank you for explaining this I already have set the teams in my gamemode I should have mention that.
I will add this to my code thanks alot.
Reply
#6

If you have teams set and plan on using teams you will need to make some function hooks and modify how SetPlayerTeam() / GetPlayerTeam() operate so that they set the players to the same team with the native functions but save the team in your script let me know if you need help with that it's pretty easy to do.
Reply
#7

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
If you have teams set and plan on using teams you will need to make some function hooks and modify how SetPlayerTeam() / GetPlayerTeam() operate so that they set the players to the same team with the native functions but save the team in your script let me know if you need help with that it's pretty easy to do.
I have made teams like this - and it worked it was no teamkilling it's tested:

Код:
#define BLUE_TEAM 1
#define RED_TEAM 2
Код:
public OnPlayerRequestClass(playerid, classid)
{
      //....
      switch(classid)
      {
	    case 0,1,2,3:
	    {
                   //...
                   SetPlayerTeam(playerid,BLUE_TEAM);
            }
            case 4,5,6,7:
	    {
                   //...
                   SetPlayerTeam(playerid,RED_TEAM); 
            }
      }
      return 1;
}
And now I added this to save the team in the script:

Код:
static gTeam[MAX_PLAYERS];
Код:
public OnPlayerRequestClass(playerid, classid)
{
      //....
      switch(classid)
      {
	    case 0,1,2,3:
	    {
                   //...
                   SetPlayerTeam(playerid,BLUE_TEAM);
                   gTeam[playerid] = BLUE_TEAM;
            }
            case 4,5,6,7:
	    {
                   //...
                   SetPlayerTeam(playerid,RED_TEAM); 
                   gTeam[playerid] = RED_TEAM;
            }
      }
      return 1;
}
Reply
#8

All the players need to be on the same team so OnPlayerTakeDamage() doesn't do anything though.
Reply
#9

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
All the players need to be on the same team so OnPlayerTakeDamage() doesn't do anything though.
So something like this?

Код:
public OnPlayerRequestClass(playerid, classid)
{
      //....
      switch(classid)
      {
	    case 0,1,2,3:
	    {
                   //...
                   SetPlayerTeam(playerid,0);
                   gTeam[playerid] = BLUE_TEAM;
            }
            case 4,5,6,7:
	    {
                   //...
                   SetPlayerTeam(playerid,0); 
                   gTeam[playerid] = RED_TEAM;
            }
      }
      return 1;
}
Код:
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart)
{
	if(playerid != INVALID_PLAYER_ID) // If not self-inflicted
        {
               if(gTeam[playerid] != gTeam[damagedid])
	       {
   		    GetPlayerHealth(damagedid,pHealth[damagedid]);
    		    SetPlayerHealth(damagedid,pHealth[damagedid]-amount);
	 	}
	}
	if(playerid == damagedid) // If self-inflicted
       {
   	      GetPlayerHealth(damagedid,pHealth[damagedid]);
    	      SetPlayerHealth(damagedid,pHealth[damagedid]-amount);
	}
 	KilledBy[damagedid] = playerid;
        KillReason[damagedid] = weaponid;
	return 1;
}
Reply
#10

Yes that would work, as long as you don't plan on using GetPlayerTeam() in which case you need to use gTeam[playerid] OR create an include with function hooking makes sense ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)