Hi all,
I hope everyone has been well, I have been having a hard time coding my PVX mod and ended up burning out.
I am wanting to get back into it, however, I keep getting stuck and end up giving up early.
At the moment I am working on a clean version of the mod and have started from scratch, the biggest issue for me was the damage call.
See the biggest issue is that I have to determine what is doing damage and what to then apply the settings, so originally I was just doing a lot of if called eg:
What I would like to know is if anyone has a better recommendation to clean this up.Code:if ((Attacker == Baseplayer)&&(Victim==Baseplayer)) else if ((Attacker == Baseplayer)&&(Victim==Building))
Thanks for any help in advance.
Tips for working with damage types
Discussion in 'Rust Development' started by Alphawar, Jan 30, 2018.
-
if ((Attacker is BasePlayer) && (Victim is BasePlayer)){
}
else if ((Attacker is BasePlayer) && (Victim is BuildingBlock)) {
} -
If anyone else knows an efficient way please let me know, because I will be dealing with a lot of different "types".
here is a snippet from my old version:
Code:void OnEntityTakeDamage(BaseCombatEntity Target, HitInfo HitInfo) { BaseEntity _attacker = HitInfo.Initiator; object _n = Target.GetType(); if (_attacker is BasePlayer && Target is BasePlayer) PlayerVPlayer((BasePlayer)Target, (BasePlayer)_attacker, HitInfo); else if (_attacker is BasePlayer && BuildEntityList.Contains(_n) && !(_n is AutoTurret)) PlayerVBuilding(Target, (BasePlayer)_attacker, HitInfo); else if (_attacker is BasePlayer && Target is BaseHelicopter) PlayerVHeli((BasePlayer)_attacker, HitInfo); else if ((_attacker is BaseHelicopter || (_attacker is FireBall && _attacker.ShortPrefabName == "napalm")) && Target is BasePlayer) HeliVPlayer((BasePlayer)Target, HitInfo); else if ((_attacker is BaseHelicopter || (_attacker is FireBall && _attacker.ShortPrefabName == "napalm")) && BuildEntityList.Contains(_n)) HeliVBuilding(Target, HitInfo); else if ((_attacker is BaseHelicopter || (_attacker is FireBall && _attacker.ShortPrefabName == "napalm")) && Target is BaseNPC) HeliVAnimal((BaseNPC)Target, HitInfo); else if (_attacker is BasePlayer && Target is AutoTurret) PlayerVTurret((AutoTurret)Target, (BasePlayer)_attacker, HitInfo); else if (_attacker is AutoTurret && Target is BasePlayer) TurretVPlayer((BasePlayer)Target, (AutoTurret)_attacker, HitInfo); else if (_attacker is AutoTurret && Target is AutoTurret) TurretVTurret((AutoTurret)Target, (AutoTurret)_attacker, HitInfo); else if (_attacker is AutoTurret && Target is BaseNPC) TurretVAnimal((BaseNPC)Target, (AutoTurret)_attacker, HitInfo); else if (_attacker is BasePlayer && Target is BaseNPC) PlayerVAnimal((BasePlayer)_attacker, HitInfo); else if (_attacker is BaseNPC && Target is BasePlayer) AnimalVPlayer((BasePlayer)Target, HitInfo); else if (_attacker is FireBall) { FireBall _fire = (FireBall)_attacker; if (Target is BasePlayer) FireVPlayer((BasePlayer)Target, HitInfo); else if (BuildEntityList.Contains(_n)) FireVBuilding(Target, HitInfo); } //if (HitInfo.Initiator is BaseTrap) //if (HitInfo.Initiator is Barricade) //if (HitInfo.WeaponPrefab.ShortPrefabName == "rocket_heli" || //HitInfo.WeaponPrefab.ShortPrefabName == "rocket_heli_napalm") //if (HitInfo.Initiator != null && HitInfo.Initiator.ShortPrefabName == "napalm") }
-
Maybe it will help:
Code:void OnEntityTakeDamage(BaseEntity entity, BaseEntity target) { switch (entity.GetType().ToString()) { case "BasePlayer": break; } }
Last edited by a moderator: Jan 30, 2018