Teammates can pistol whip despite hittype.
#1

Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
	if(hittype == 1 && gTeam[playerid] == gTeam[hitid]) {
	    SendClientMessage(playerid, COLOR_RED, "Do not shoot your teammates!");
	    return 0;
	}
    return 1;
}
No matter what I do, players can pistol whip each other, and can occasionally kill each other with headshots whilst in vehicles, is this fixable?
Reply
#2

Use
PHP код:
SetPlayerTeam(playeridteamid); 
That will automaticly disable any sort of team damage. Altho bare in mind SetPlayerTeam does resets on OnPlayerRequestClass
Reply
#3

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.
Reply
#4

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(playeriddamagedidFloatamountweaponidbodypart) {
    if(
gTeam[playerid] == gTeam[damagedid]) {
        switch(
weaponid) {
            case 
.. 15GivePlayerHealth(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(playeridissueridFloatamountweaponidbodypart) {
    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:healthGetPlayerHealth(playerid,health);
    
SetPlayerHealth(playerid,health+Health);

I havent tested this code, its just an example.
Reply
#5

Why using variables for team instead of using an included SA-MP function for sa-mp? SetPlayerTeam(playerid, teamid);
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)