Quote:
Originally Posted by Sebz
I already have a pretty solid system setting player's teams based on their classid every time they spawn or change class, somehow they are still tking on occasion though.
|
Alright so okay
In this case, first of all Hittype represents
PHP код:
BULLET_HIT_TYPE_PLAYER
There are no bullets in this case as pistol whip. I recommend you to.
Check their position & check if they are in range (max 3-4, see whats the maximum range for the pistol whip). If they receive damage from the attacker who is in their 3-4 meters range, detect it as pistol whip & restore HitID health.
Also dont forget you are using OnPlayerWEAPONSHOT. Player is not shooting if they pistol whip someone.
Example code:
PHP код:
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart) {
if(gTeam[playerid] == gTeam[damagedid]) {
switch(weaponid) {
case 0 .. 15: GivePlayerHealth(damagedid,-amount); //positive damage if its a melee weapon
default: { //if its anything else
new Float:MyPos[3];
GetPlayerPos(damagedid,MyPos[0],MyPos[1],MyPos[2]); //getting player thats receiving damage position
if(IsPlayerInRangeOfPoint(playerid,3.0,MyPos[0],MyPos[1],MyPos[3]))
return SendClientMessage(playerid,COLOR_RED,"NO WHIPS!"); //if they are in range of them and they have any other weapon which aint a melee
else if(!IsPlayerInRangeOfPoint(playerid,3.0,MyPos[0],MyPos[1],MyPos[3]))
return GivePlayerHealth(damagedid,-amount);
}
}
}
}
return true;
}
Regarding damaging the passengers, simple, grant them immunity.
PHP код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart) {
new playerState = GetPlayerState(playerid);
if(issuerid != INVALID_PLAYER_ID && playerState == PLAYER_STATE_PASSENGER) { //if there is a valid shooter & playerid is passenger
GivePlayerHealth(playerid,amount); //We will restore their health
}
return true;
}
Also add this
PHP код:
stock GivePlayerHealth(playerid,Float:Health) //credits aircombat
{
new Float:health; GetPlayerHealth(playerid,health);
SetPlayerHealth(playerid,health+Health);
}
I havent tested this code, its just an example.