new Float:pHealth[MAX_PLAYERS] // Variable to store the player's health
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(playerid) { pHealth[playerid] = 100.0; return 1; }
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.
|
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; }
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;
}
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 Код:
|
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.
|
#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; }
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; }
All the players need to be on the same team so OnPlayerTakeDamage() doesn't do anything though.
|
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; }