18.01.2017, 15:44
Can I use prox detector for dmg? I want to make the DMG for shotgun and I want to deal more DMG from close range and less from far.
stock Float:GetDistanceBetweenPlayers(playerid, targetid)
{
new
Float:x1, Float:y1, Float:z1,
Float:x2, Float:y2, Float:z2;
if(GetPlayerPos(playerid, x1, y1, z1) && GetPlayerPos(targetid, x2, y2, z2))
{
return VectorSize(x1 - x2, y1 - y2, z1 - z2);
}
return Float:0x7f800000; // infinity
}
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
if(issuerid != INVALID_PLAYER_ID && weaponid == WEAPON_SHOTGUN)
{
new
Float:multiplier = 1.0,
Float:distance = GetDistanceBetweenPlayers(playerid, issuerid),
Float:extraDamage = 100.0 - distance - amount; // - amount to account for damage already taken
switch(bodypart)
{
case 3, 4 : multiplier = 1.10; // chest, +10% damage
case 5, 6 : multiplier = 0.85; // arms, -15% damage
case 7, 8 : multiplier = 0.75; // legs, -25% damage
case 9 : multiplier = 1.50; // head, +50% damage
}
extraDamage *= multiplier;
if(extraDamage > 0.0)
{
new Float:currentHealth;
GetPlayerHealth(playerid, currentHealth);
SetPlayerHealth(playerid, currentHealth - extraDamage)
}
}
}
amount += 20.0