2019-01-03 01:26:39 +00:00
|
|
|
/***
|
|
|
|
*
|
2019-01-16 16:43:50 +00:00
|
|
|
* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved.
|
|
|
|
*
|
|
|
|
* See the file LICENSE attached with the sources for usage details.
|
2019-01-03 01:26:39 +00:00
|
|
|
*
|
|
|
|
****/
|
2016-12-02 23:12:10 +00:00
|
|
|
|
2017-01-10 18:24:45 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Damage_CastOrbituary
|
|
|
|
|
|
|
|
Sends a message to the clients to display a death message
|
|
|
|
=================
|
|
|
|
*/
|
2019-02-20 13:30:16 +00:00
|
|
|
void Damage_CastOrbituary(entity eAttacker, entity eTarget, float fWeapon, float fHeadShot)
|
|
|
|
{
|
|
|
|
WriteByte(MSG_BROADCAST, SVC_CGAMEPACKET);
|
|
|
|
WriteByte(MSG_BROADCAST, EV_ORBITUARY);
|
|
|
|
WriteByte(MSG_BROADCAST, num_for_edict(eAttacker) - 1);
|
|
|
|
WriteByte(MSG_BROADCAST, eAttacker.team);
|
|
|
|
WriteByte(MSG_BROADCAST, num_for_edict(eTarget) - 1);
|
|
|
|
WriteByte(MSG_BROADCAST, eTarget.team);
|
|
|
|
WriteByte(MSG_BROADCAST, fWeapon);
|
|
|
|
WriteByte(MSG_BROADCAST, fHeadShot);
|
2016-12-09 23:03:13 +00:00
|
|
|
msg_entity = self;
|
2019-02-20 13:30:16 +00:00
|
|
|
multicast([0,0,0], MULTICAST_ALL);
|
2016-12-09 23:03:13 +00:00
|
|
|
}
|
|
|
|
|
2017-01-10 18:24:45 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Damage_GetHitLocation
|
|
|
|
|
|
|
|
Debug function
|
|
|
|
=================
|
|
|
|
*/
|
2019-02-20 13:30:16 +00:00
|
|
|
string Damage_GetHitLocation(int iSurface)
|
|
|
|
{
|
2019-01-19 04:50:25 +00:00
|
|
|
#ifdef CSTRIKE
|
2019-02-20 13:30:16 +00:00
|
|
|
switch (iSurface) {
|
2017-01-03 01:02:00 +00:00
|
|
|
case BODY_HEAD:
|
|
|
|
return "Head";
|
|
|
|
break;
|
|
|
|
case BODY_CHEST:
|
|
|
|
return "Chest";
|
|
|
|
break;
|
|
|
|
case BODY_STOMACH:
|
|
|
|
return "Stomach";
|
|
|
|
break;
|
|
|
|
case BODY_ARMLEFT:
|
|
|
|
return "Left Arm";
|
|
|
|
break;
|
|
|
|
case BODY_ARMRIGHT:
|
|
|
|
return "Right Arm";
|
|
|
|
break;
|
|
|
|
case BODY_LEGLEFT:
|
|
|
|
return "Left leg";
|
|
|
|
break;
|
|
|
|
case BODY_LEGRIGHT:
|
|
|
|
return "Right Leg";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return "Generic";
|
|
|
|
}
|
2019-01-19 04:50:25 +00:00
|
|
|
#endif
|
2017-01-03 01:02:00 +00:00
|
|
|
}
|
|
|
|
|
2019-02-20 13:30:16 +00:00
|
|
|
int Damage_ShouldDamage(float fTargetTeam, float fAttackerTeam)
|
|
|
|
{
|
2019-01-19 04:50:25 +00:00
|
|
|
#ifdef CSTRIKE
|
2019-02-20 13:30:16 +00:00
|
|
|
if (fTargetTeam == TEAM_VIP) {
|
2017-01-14 15:00:31 +00:00
|
|
|
fTargetTeam = TEAM_CT;
|
2019-02-20 13:30:16 +00:00
|
|
|
} else if (fAttackerTeam == TEAM_VIP) {
|
2017-01-14 15:00:31 +00:00
|
|
|
fAttackerTeam = TEAM_CT;
|
|
|
|
}
|
|
|
|
|
2019-02-20 13:30:16 +00:00
|
|
|
if (fTargetTeam == fAttackerTeam) {
|
2017-01-14 15:00:31 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2019-01-19 04:50:25 +00:00
|
|
|
#endif
|
2017-01-14 15:00:31 +00:00
|
|
|
}
|
2017-01-10 18:24:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Damage_Apply
|
|
|
|
|
|
|
|
Generic function that applies damage, pain and suffering
|
|
|
|
=================
|
|
|
|
*/
|
2019-02-20 13:30:16 +00:00
|
|
|
void Damage_Apply(entity eTarget, entity eAttacker, float iDamage, vector vHitPos, int iSkipArmor)
|
|
|
|
{
|
2019-01-19 04:50:25 +00:00
|
|
|
#ifdef CSTRIKE
|
2017-01-10 15:45:41 +00:00
|
|
|
// Modify the damage based on the location
|
2019-02-20 13:30:16 +00:00
|
|
|
if (trace_surface_id == BODY_HEAD) {
|
|
|
|
if (eTarget.iEquipment & EQUIPMENT_HELMET) {
|
|
|
|
sound(self, CHAN_ITEM, "weapons/ric_metal-2.wav", 1, ATTN_IDLE);
|
2017-11-16 02:25:20 +00:00
|
|
|
iDamage = 0;
|
2017-01-10 15:45:41 +00:00
|
|
|
eTarget.iEquipment -= EQUIPMENT_HELMET;
|
|
|
|
} else {
|
|
|
|
iDamage *= 4;
|
|
|
|
}
|
2019-02-20 13:30:16 +00:00
|
|
|
} else if (trace_surface_id == BODY_STOMACH) {
|
2017-01-03 01:02:00 +00:00
|
|
|
iDamage *= 0.9;
|
2019-02-20 13:30:16 +00:00
|
|
|
} else if (trace_surface_id == BODY_LEGLEFT) {
|
2017-01-03 18:46:19 +00:00
|
|
|
iDamage *= 0.4;
|
2019-02-20 13:30:16 +00:00
|
|
|
} else if (trace_surface_id == BODY_LEGRIGHT) {
|
2017-01-03 18:46:19 +00:00
|
|
|
iDamage *= 0.4;
|
2017-01-03 01:02:00 +00:00
|
|
|
}
|
2019-02-20 13:30:16 +00:00
|
|
|
dprint(sprintf("[DEBUG] Hit Bodypart: %s\n", Damage_GetHitLocation(trace_surface_id)));
|
2018-09-20 20:38:01 +00:00
|
|
|
|
2019-01-05 23:22:06 +00:00
|
|
|
if (eTarget != eAttacker) {
|
2019-02-20 13:30:16 +00:00
|
|
|
if (!Damage_ShouldDamage(eTarget.team, eAttacker.team)) {
|
2019-01-05 23:22:06 +00:00
|
|
|
if (!autocvar_mp_friendlyfire) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-09-20 20:38:01 +00:00
|
|
|
}
|
|
|
|
|
2019-01-04 04:56:14 +00:00
|
|
|
eTarget.velocity = [0,0,0];
|
|
|
|
|
2017-01-10 15:45:41 +00:00
|
|
|
// Apply the damage finally
|
2019-02-20 13:30:16 +00:00
|
|
|
if (eTarget.armor) {
|
2017-09-26 05:10:21 +00:00
|
|
|
float fRatio = 0.5;
|
|
|
|
|
2019-02-20 13:30:16 +00:00
|
|
|
if (eAttacker.weapon) {
|
|
|
|
fRatio *= wptTable[eAttacker.weapon].fWeaponArmorRatio;
|
2017-09-26 05:10:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Simple implementation of how kevlar damage is calculated
|
|
|
|
float fNewDmg = iDamage * fRatio;
|
2019-02-20 13:30:16 +00:00
|
|
|
float fNewArmor = (iDamage - fNewDmg) / 2;
|
2017-09-26 05:10:21 +00:00
|
|
|
|
2019-02-20 13:30:16 +00:00
|
|
|
if (fNewArmor > eTarget.armor) {
|
2017-09-26 05:10:21 +00:00
|
|
|
fNewArmor = eTarget.armor;
|
|
|
|
fNewArmor *= (1/0.5);
|
2019-02-20 13:30:16 +00:00
|
|
|
fNewDmg = rint(iDamage - fNewArmor);
|
2017-09-26 05:10:21 +00:00
|
|
|
eTarget.armor = 0;
|
2017-09-26 05:18:32 +00:00
|
|
|
eTarget.iEquipment -= EQUIPMENT_KEVLAR;
|
2017-09-26 05:10:21 +00:00
|
|
|
} else {
|
2019-02-20 13:30:16 +00:00
|
|
|
if (fNewArmor < 0) {
|
2017-09-26 05:10:21 +00:00
|
|
|
fNewArmor = 1;
|
|
|
|
}
|
2019-02-20 13:30:16 +00:00
|
|
|
eTarget.armor = rint(eTarget.armor - fNewArmor);
|
2017-09-26 05:10:21 +00:00
|
|
|
}
|
2017-11-11 21:46:04 +00:00
|
|
|
|
2019-02-20 13:30:16 +00:00
|
|
|
if (iSkipArmor == TRUE) {
|
|
|
|
eTarget.health = rint(eTarget.health -= iDamage);
|
2018-12-09 04:56:34 +00:00
|
|
|
eTarget.dmg_take = (float)iDamage;
|
2017-11-11 21:46:04 +00:00
|
|
|
} else {
|
2019-02-20 13:30:16 +00:00
|
|
|
eTarget.health = rint(eTarget.health -= fNewDmg);
|
2018-12-09 04:56:34 +00:00
|
|
|
eTarget.dmg_take = (float)fNewDmg;
|
2017-11-11 21:46:04 +00:00
|
|
|
}
|
2017-09-26 05:10:21 +00:00
|
|
|
} else {
|
|
|
|
// No armor
|
|
|
|
eTarget.health -= iDamage;
|
2018-12-09 04:56:34 +00:00
|
|
|
eTarget.dmg_take = (float)iDamage;
|
2017-09-26 05:10:21 +00:00
|
|
|
}
|
2018-12-09 04:56:34 +00:00
|
|
|
eTarget.dmg_inflictor = eAttacker;
|
2017-01-10 15:45:41 +00:00
|
|
|
|
2017-01-10 18:24:45 +00:00
|
|
|
// Special monetary punishment for hostage murderers
|
2019-02-20 13:30:16 +00:00
|
|
|
if (eTarget.classname == "hostage_entity") {
|
|
|
|
if (eTarget.health > 0) {
|
|
|
|
Money_AddMoney(eAttacker, autocvar_fcs_penalty_pain); // Pain
|
2017-01-10 18:24:45 +00:00
|
|
|
} else {
|
2019-02-20 13:30:16 +00:00
|
|
|
Money_AddMoney(eAttacker, autocvar_fcs_penalty_kill); // Death
|
2017-01-10 18:24:45 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-09 04:56:34 +00:00
|
|
|
|
2016-12-10 14:25:16 +00:00
|
|
|
// Target is dead and a client....
|
2019-02-20 13:30:16 +00:00
|
|
|
if (eTarget.health <= 0) {
|
|
|
|
if (eTarget.flags & FL_CLIENT) {
|
2016-12-09 23:03:13 +00:00
|
|
|
eTarget.fDeaths++;
|
2019-02-20 13:30:16 +00:00
|
|
|
forceinfokey(eTarget, "*deaths", ftos(eTarget.fDeaths));
|
2016-12-18 09:09:01 +00:00
|
|
|
}
|
|
|
|
|
2019-02-20 13:30:16 +00:00
|
|
|
if ((eTarget.flags & FL_CLIENT) && (eAttacker.flags & FL_CLIENT)) {
|
2017-01-14 15:00:31 +00:00
|
|
|
// Don't encourage them to kill their own team members for $$$
|
2019-02-20 13:30:16 +00:00
|
|
|
if (Damage_ShouldDamage(eTarget.team, eAttacker.team) == TRUE) {
|
2017-01-14 15:00:31 +00:00
|
|
|
eAttacker.frags++;
|
2019-02-20 13:30:16 +00:00
|
|
|
Money_AddMoney(eAttacker, autocvar_fcs_reward_kill);
|
2017-01-14 15:00:31 +00:00
|
|
|
} else {
|
|
|
|
eAttacker.frags--;
|
|
|
|
}
|
|
|
|
|
2019-02-20 13:30:16 +00:00
|
|
|
Damage_CastOrbituary(eAttacker, eTarget, eAttacker.weapon, trace_surface_id == BODY_HEAD ? TRUE:FALSE);
|
2016-12-09 23:03:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-07 23:09:50 +00:00
|
|
|
entity eOld = self;
|
2016-12-02 23:12:10 +00:00
|
|
|
self = eTarget;
|
2019-02-28 07:18:01 +00:00
|
|
|
|
2019-02-20 13:30:16 +00:00
|
|
|
if (self.health <= 0) {
|
2016-12-07 23:09:50 +00:00
|
|
|
self.health = 0;
|
2019-02-20 13:30:16 +00:00
|
|
|
self.vDeath(trace_surface_id);
|
2016-12-02 23:12:10 +00:00
|
|
|
} else {
|
2019-02-20 13:30:16 +00:00
|
|
|
self.vPain(trace_surface_id);
|
2016-12-02 23:12:10 +00:00
|
|
|
}
|
2019-02-28 07:18:01 +00:00
|
|
|
|
2016-12-02 23:12:10 +00:00
|
|
|
self = eOld;
|
2019-01-19 04:50:25 +00:00
|
|
|
#endif
|
2016-12-02 23:12:10 +00:00
|
|
|
}
|
2016-12-07 02:35:01 +00:00
|
|
|
|
2017-11-20 02:03:30 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Damage_CheckAttack
|
|
|
|
|
|
|
|
This verifies that the entity is actually able to receive some damage,
|
|
|
|
from a plain geographical standpoint
|
|
|
|
=================
|
|
|
|
*/
|
2019-02-20 13:30:16 +00:00
|
|
|
float Damage_CheckAttack(entity eTarget, vector vAttackPos)
|
|
|
|
{
|
|
|
|
if (eTarget.movetype == MOVETYPE_PUSH) {
|
|
|
|
traceline(vAttackPos, 0.5 * (eTarget.absmin + eTarget.absmax), TRUE, self);
|
2017-11-20 02:03:30 +00:00
|
|
|
|
2019-02-20 13:30:16 +00:00
|
|
|
if (trace_fraction == 1) {
|
2017-11-20 02:03:30 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2019-02-20 13:30:16 +00:00
|
|
|
if (trace_ent == eTarget) {
|
2017-11-20 02:03:30 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-02-20 13:30:16 +00:00
|
|
|
traceline(vAttackPos, eTarget.origin, TRUE, self);
|
|
|
|
if (trace_fraction == 1) {
|
2017-11-20 02:03:30 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2019-02-20 13:30:16 +00:00
|
|
|
traceline(vAttackPos, eTarget.origin + '15 15 0', TRUE, self);
|
|
|
|
if (trace_fraction == 1) {
|
2017-11-20 02:03:30 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2019-02-20 13:30:16 +00:00
|
|
|
traceline(vAttackPos, eTarget.origin + '-15 -15 0', TRUE, self);
|
|
|
|
if (trace_fraction == 1) {
|
2017-11-20 02:03:30 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2019-02-20 13:30:16 +00:00
|
|
|
traceline(vAttackPos, eTarget.origin + '-15 15 0', TRUE, self);
|
|
|
|
if (trace_fraction == 1) {
|
2017-11-20 02:03:30 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2019-02-20 13:30:16 +00:00
|
|
|
traceline(vAttackPos, eTarget.origin + '15 -15 0', TRUE, self);
|
|
|
|
if (trace_fraction == 1) {
|
2017-11-20 02:03:30 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-01-10 18:24:45 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Damage_Radius
|
|
|
|
|
|
|
|
Even more pain and suffering, mostly used for explosives
|
|
|
|
=================
|
|
|
|
*/
|
2019-02-20 13:30:16 +00:00
|
|
|
void Damage_Radius(vector vOrigin, entity eAttacker, float fDamage, float fRadius, int iCheckClip)
|
|
|
|
{
|
|
|
|
for (entity eDChain = world; (eDChain = findfloat(eDChain, takedamage, DAMAGE_YES));) {
|
2019-01-03 01:26:39 +00:00
|
|
|
vector vecRealPos;
|
2019-02-20 13:30:16 +00:00
|
|
|
vecRealPos[0] = eDChain.absmin[0] + (0.5 * (eDChain.absmax[0] - eDChain.absmin[0]));
|
|
|
|
vecRealPos[1] = eDChain.absmin[1] + (0.5 * (eDChain.absmax[1] - eDChain.absmin[1]));
|
|
|
|
vecRealPos[2] = eDChain.absmin[2] + (0.5 * (eDChain.absmax[2] - eDChain.absmin[2]));
|
2019-01-03 01:26:39 +00:00
|
|
|
|
2019-02-20 13:30:16 +00:00
|
|
|
float fDist = vlen(vOrigin - vecRealPos);
|
2019-01-03 01:26:39 +00:00
|
|
|
//vector vPush;
|
|
|
|
|
2019-02-20 13:30:16 +00:00
|
|
|
if (fDist > fRadius) {
|
2019-01-03 01:26:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-02-20 13:30:16 +00:00
|
|
|
if (Damage_CheckAttack(eDChain, vOrigin) || iCheckClip == FALSE) {
|
|
|
|
float fDiff = vlen(vOrigin - vecRealPos);
|
2019-01-03 01:26:39 +00:00
|
|
|
|
2019-02-20 13:30:16 +00:00
|
|
|
fDiff = (fRadius - fDiff) / fRadius;
|
2019-01-03 01:26:39 +00:00
|
|
|
fDamage = rint(fDamage * fDiff);
|
|
|
|
|
2019-02-20 13:30:16 +00:00
|
|
|
if (fDiff > 0) {
|
|
|
|
Damage_Apply(eDChain, eAttacker, fDamage, eDChain.origin, TRUE);
|
|
|
|
/*if (eDChain.movetype != MOVETYPE_NONE) {
|
|
|
|
vPush = vectoangles(vecRealPos - vOrigin);
|
|
|
|
makevectors(vPush);
|
|
|
|
eDChain.velocity += (v_forward * fDamage * 5) + (v_up * fDamage * 2.5);
|
2019-01-03 01:26:39 +00:00
|
|
|
}*/
|
2017-01-08 14:11:34 +00:00
|
|
|
}
|
2019-01-03 01:26:39 +00:00
|
|
|
|
2016-12-07 02:35:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|