OnPlayerTakeDamge problem. -
JawsPlus - 20.04.2016
I wanted to make a anti clan shoot system , but i does not work.
What is the problem?
Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
if(issuerid != INVALID_PLAYER_ID)
{
new string[256];
new clanfile[256];
format(clanfile, sizeof(clanfile), "/Clan/user/%s.ini",dini_Get("/Clan/AllUserID.ini",Name(playerid)));
new clanfile1[256];
format(clanfile1, sizeof(clanfile1), "/Clan/user/%s.ini",dini_Get("/Clan/AllUserID.ini",Name(issuerid)));
if(strcmp(dini_Get(clanfile,"PlayerClan"), dini_Get(clanfile1,"PlayerClan")))
{
return 1;
}
else
{
new Float:HP;
GetPlayerHealth(playerid, HP);
SetPlayerHealth(playerid,HP - 0);
SendClientMessage(issuerid,COLOR_RED,"[CLAN] {FFFFFF}Do not shoot your clan member.");
}
}
return 1;
}
Re: OnPlayerTakeDamge problem. -
Manyula - 20.04.2016
The way you're doing it is absolutely inefficient and will most likely cause lag since those function calls are quite slow. Also, for damage prevention between players, you should consider using SetPlayerTeam instead of OnPlayerTakeDamage, because the callback doesn't prevent the damage, it only reverses the damage.
Re: OnPlayerTakeDamge problem. -
HydraHumza - 20.04.2016
if you got clan system I am sure it also got clan tag just make a function to get player tag and if there tag match then set that to not damage. that's all.
Re: OnPlayerTakeDamge problem. -
JawsPlus - 21.04.2016
So what should i do now?
Re: OnPlayerTakeDamge problem. -
Manyula - 21.04.2016
There is multiple ways you can proceed here.
1. OnPlayerTakeDamage is the least effective when it comes to damage prevention, as already stated above.
2. OnPlayerWeaponShot fits a little better if you just filter for issuerid when players shoot each other. However, you can only prevent damage from bullets, not explosions or melee attacks.
3. You set the players of a clan/gang/team to the same team, using SetPlayerTeam. This allows you to prevent all damage, except for some rare cases where the game itself doesn't recognize that damage was inflicted by another player, e.g. explosions. Also, SetPlayerTeam allows you to handle health and armor serverside.
You can go with whatever solution you feel most comfortable with, but in the end you have to consider efficiency too.
Re: OnPlayerTakeDamge problem. -
AdrianG - 21.04.2016
Use OnPlayerWeaponShot and return 0 when you want to stop the shot.