SA-MP Forums Archive
Is this possible? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Is this possible? (/showthread.php?tid=488923)



Is this possible? - Lajko1 - 19.01.2014

Is possible to raise damage if player is near shooter (issuer)?


Re: Is this possible? - jakejohnsonusa - 19.01.2014

Yes it is, but it will require a bit of work.

OnPlayerShootPlayer will be needed along with GetDistanceBetweenPlayers.

Simply set it up like this:

pawn Код:
public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost)//If a player shoots another player.
{
     if(!IsPlayerConnected(Shooter) || !IsPlayerConnected(Target)) //Error checking
     {        
           return 1;    
     }
     
     if(GetPlayerDistanceFromPlayer(Shooter, Target) < 10)//Get the distance between the shooter and the target, in this case if it's within 10 game units
     {
            if(GetPlayerWeapon(Shooter) == 31 || 30)//Get their weapon, in this case an AK47 or M4
            {
                  new Float:pHealth;  //Created a float variable to use bellow            
                  GetPlayerHealth(Target, pHealth); //Save the target's health to the variable AFTER the normal damage has been taken              
                  SetPlayerHealth(Target, pHealth-60);//Takes away health points (AGAIN, this is after the normal damage from the shot has been taken into effect)
                  //SetPlayerHealth(playerid, 2); <- You could do something like this as well, simply setting the player's health to a certain value 0-100.
                  return 1;//end
            }
     }
     return 1;
}



Re: Is this possible? - Audi_Quattrix - 19.01.2014

EDIT:too late


Re: Is this possible? - Lajko1 - 19.01.2014

Can I use something like this also?

pawn Код:
public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost)//If a player shoots another player.
{
     if(!IsPlayerConnected(Shooter) || !IsPlayerConnected(Target)) //Error checking
     {        
           return 1;    
     }
     
     if(GetPlayerDistanceFromPlayer(Shooter, Target) < 10)//Get the distance between the shooter and the target, in this case if it's within 10 game units
     {
            if(GetPlayerWeapon(Shooter) == 31 || 30)//Get their weapon, in this case an AK47 or M4
            {
                  new Float:pHealth;  //Created a float variable to use bellow            
                  GetPlayerHealth(Target, pHealth); //Save the target's health to the variable AFTER the normal damage has been taken              
                  SetPlayerHealth(Target, pHealth-60);//Takes away health points (AGAIN, this is after the normal damage from the shot has been taken into effect)
                  //SetPlayerHealth(playerid, 2); <- You could do something like this as well, simply setting the player's health to a certain value 0-100.
                  return 1;//end
            }
     }
      else if (GetPlayerDistanceFromPlayer(Shooter, Target) > 10)
      {
         //code
         return 1;
       }

     }
     return 1;
}
EDIT: also can I combine this with? :
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)



Re: Is this possible? - Lajko1 - 19.01.2014

Okay here is an example what I've made:

pawn Код:
#include a_samp

#define WEAPON_BODY_PART_CHEST 1
#define WEAPON_BODY_PART_CROTCH 2
#define WEAPON_BODY_PART_LEFT_ARM 3
#define WEAPON_BODY_PART_RIGHT_ARM 4
#define WEAPON_BODY_PART_LEFT_LEG 5
#define WEAPON_BODY_PART_RIGHT_LEG 6
#define WEAPON_BODY_PART_HEAD 7

forward Float:GetDistanceBetweenPlayers(issuerid,playerid);
public Float:GetDistanceBetweenPlayers(issuerid,playerid)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    if(!IsPlayerConnected(issuerid) || !IsPlayerConnected(playerid)) {
        return -1.00;
    }
    GetPlayerPos(issuerid,x1,y1,z1);
    GetPlayerPos(playerid,x2,y2,z2);
    return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}

public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
    if(!IsPlayerConnected(playerid)) return 0;
    if(!IsPlayerConnected(issuerid)) return 0;
    if(issuerid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 7)
    {
        if(GetDistanceBetweenPlayers(issuerid, playerid) < 10)
        {
            new Float:pHealth;
            GetPlayerHealth(playerid, pHealth);
            SetPlayerHealth(playerid, pHealth-60);
            return 1;
        }
        else if (GetDistanceBetweenPlayers(issuerid, playerid) > 10)
        {
            new Float:pHealth;
            GetPlayerHealth(playerid, pHealth);
            SetPlayerHealth(playerid, pHealth-30);
            return 1;
        }
    }
    return 1;
}
Will this work?
Also will this range between players work?


Re: Is this possible? - Lajko1 - 20.01.2014

Anyone?


Re: Is this possible? - Lajko1 - 20.01.2014

Guys I really need this, why this ISN'T working ?
What I want to make is if player is closer to target it will cause more damage to target, but this isn't working can someone help please?

REP +1 to guy who can help :/
Thanks in advance

pawn Код:
#include a_samp

#define WEAPON_BODY_PART_TORSO 3
#define WEAPON_BODY_PART_GROIN  4
#define WEAPON_BODY_PART_LEFT_ARM 5
#define WEAPON_BODY_PART_RIGHT_ARM 6
#define WEAPON_BODY_PART_LEFT_LEG 7
#define WEAPON_BODY_PART_RIGHT_LEG 8
#define WEAPON_BODY_PART_HEAD 9

forward Float:GetDistanceBetweenPlayers(p1,p2);
public Float:GetDistanceBetweenPlayers(p1,p2)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    if(!IsPlayerConnected(p1) || !IsPlayerConnected(p2))
    {
        return -1.00;
    }
    GetPlayerPos(p1,x1,y1,z1);
    GetPlayerPos(p2,x2,y2,z2);
    return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}

public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
    new Float:pHealth;
    GetPlayerHealth(playerid, pHealth);
   
    new Float:x, Float:y, Float:z;
    GetPlayerPos(issuerid, x, y, z);
   
    if(!IsPlayerConnected(playerid)) return 0;
    if(!IsPlayerConnected(issuerid)) return 0;
    if(issuerid != INVALID_PLAYER_ID && weaponid == 30 && bodypart == 9) // AK, Head
    {
        if(GetDistanceBetweenPlayers(issuerid, playerid) < 10)
        {
            SetPlayerHealth(playerid, pHealth-60);
            return 1;
        }
        else if(GetDistanceBetweenPlayers(issuerid, playerid) > 10)
        {
            SetPlayerHealth(playerid, pHealth-30);
            return 1;
        }
    }
    if(issuerid != INVALID_PLAYER_ID && weaponid == 25 && bodypart == 9) // Shotgun, Head
    {
        if(GetDistanceBetweenPlayers(issuerid, playerid) < 10)
        {
            SetPlayerHealth(playerid, pHealth-80);
            return 1;
        }
        else if (GetDistanceBetweenPlayers(issuerid, playerid) > 10 && GetDistanceBetweenPlayers(issuerid, playerid) < 15)
        {
            SetPlayerHealth(playerid, pHealth-40);
            return 1;
        }
        else if (GetDistanceBetweenPlayers(issuerid, playerid) > 15 && GetDistanceBetweenPlayers(issuerid, playerid) < 20)
        {
            SetPlayerHealth(playerid, pHealth-20);
            return 1;
        }
        else if (GetDistanceBetweenPlayers(issuerid, playerid) > 20)
        {
            SetPlayerHealth(playerid, pHealth-10);
            return 1;
        }
    }
    return 1;
}



Re: Is this possible? - Lajko1 - 21.01.2014

Bump.. I really need help with this, why nobody answer, is possible to script with GetDistanceBetweenPlayers + On PlayerTakeDamage