private void OnOtherEnterZone(Zone zone, BaseCombatEntity entity) { HashSet<Zone> zones; if (!otherZones.TryGetValue(entity, out zones)) otherZones[entity] = zones = new HashSet<Zone>(); zones.Add(zone); }
public CombatEntityHurtEvent(BaseCombatEntity combatEnt, HitInfo info) : base(info) { var block = combatEnt.GetComponent<BuildingBlock>(); if (block != null) Victim = new BuildingPart(block); else Victim = new Entity(combatEnt); }
void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { var tick = DateTime.Now; try { if (!hitInfo.damageTypes.Has(Rust.DamageType.Decay)) return; var block = entity as BuildingBlock; if (entity.LookupShortPrefabName().StartsWith("campfire_deployed")) ProcessCampfireDamage(hitInfo); else if (block != null) ProcessBuildingDamage(block, hitInfo); else Puts($"Unsupported decaying entity detected: {entity.LookupShortPrefabName()} --- please notify author"); } finally { var ms = (DateTime.Now - tick).TotalMilliseconds; if (ms > 10) Puts($"NoDecay.OnEntityTakeDamage took {ms} ms to execute."); } }
void OnEntityDeath(BaseCombatEntity entity, HitInfo info) { if (!pluginEnabled || starting || entity == null || entity.IsDestroyed) { return; } switch (entity.ShortPrefabName) { case "patrolhelicopter": if (!heliEnabled) { return; } zoneRadius = heliRadius; zoneDuration = heliDuration; botProfile = heliBotProfile; break; case "bradleyapc": if (!apcEnabled) { return; } zoneRadius = apcRadius; zoneDuration = apcDuration; botProfile = apcBotProfile; break; default: return; } Vector3 DynPosition = entity.transform.position; DynPosition.y = TerrainMeta.HeightMap.GetHeight(DynPosition); CreateDynZone(DynPosition, zoneRadius, zoneDuration, botProfile); }
private bool CanUseArrow(BasePlayer player, ArrowType type, BaseCombatEntity combatEntity, out Item outItem) { if (IsPlayerArrow(type) && combatEntity.ToPlayer() == null) { PrintToChat(player, Lang("Error_NotPlayer", player.UserIDString, type)); outItem = null; return(false); } var typeConfig = configFile.Arrows[type]; if (!typeConfig.ArrowPrice.Enabled) { outItem = null; return(true); } if (player.inventory.FindItemID(typeConfig.ArrowPrice.ItemShortname) == null) { PrintToChat(player, Lang("Resources_Needed", player.UserIDString, typeConfig.ArrowPrice.ItemAmount, ItemManager.CreateByPartialName(typeConfig.ArrowPrice.ItemShortname).info.displayName.english) ?? "<color=red>ITEM NOT FOUND</color>"); ActiveArrows.Remove(player.userID); outItem = null; return(false); } var item = player.inventory.FindItemID(typeConfig.ArrowPrice.ItemShortname); var amount = player.inventory.GetAmount(item.info.itemid); if (amount >= typeConfig.ArrowPrice.ItemAmount) { outItem = ItemManager.CreateByName(typeConfig.ArrowPrice.ItemShortname, typeConfig.ArrowPrice.ItemAmount) ?? ItemManager.CreateByName("metal.refined", 30); return(true); } outItem = null; var neededAmount = typeConfig.ArrowPrice.ItemAmount - amount; PrintToChat(player, Lang("Resources_Needed", player.UserIDString, neededAmount, item.info.displayName.english)); return(false); }
private void OnEntityDeath(BaseCombatEntity entity, HitInfo info) { var victim = entity?.ToPlayer(); var killer = info?.Initiator?.ToPlayer(); if (victim == null || killer == null || killer == victim) { return; } if (!permission.UserHasPermission(victim.UserIDString, Permname) || permission.UserHasPermission(victim.UserIDString, Permnameblock)) { return; } var killername = killer.displayName.Replace(" ", "_"); var weaponName = "Unknown"; if (info.Weapon != null) { var usedItem = info.Weapon.GetItem(); if (usedItem != null) { weaponName = usedItem.info.displayName.english.Replace(" ", "_"); } } var distance = Mathf.Round(info.ProjectileDistance).ToString(); if (string.IsNullOrEmpty(distance) || cooldowns.Contains(victim.userID)) { return; } DeathReportUI(victim, killer.UserIDString, distance, killername, weaponName); openUI.Add(victim.UserIDString); }
object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { if (!UseFauxClipGodMode) { return(null); } if (UseFauxClipGodMode) { if (entity is BasePlayer) { var player = (BasePlayer)entity; if (_noclip.ContainsKey(player.userID)) { return(false); } if (_landing.ContainsKey(player.userID)) { return(false); } } } return(null); }
void OnLootEntityEnd(BasePlayer player, BaseCombatEntity entity) { if (!rcloot.ContainsKey(entity.net.ID)) { return; } if (entity == null) { return; } if (rcloot[entity.net.ID] == player.userID) { #if DEBUG Puts($"Removing recycler {entity.net.ID.ToString()}"); #endif CuiHelper.DestroyUi(player, RCGUI); if (!((entity as Recycler).IsOn() && (useEconomics || useServerRewards))) { rcloot.Remove(entity.net.ID); } } }
void doDamage(BaseCombatEntity entity, Vector3 position, BarrelEffect effect) { List <DamageTypeEntry> damage = new List <DamageTypeEntry>(); foreach (KeyValuePair <string, float> entry in effect.damageMap) { if (!Enum.IsDefined(typeof(DamageType), entry.Key)) { PrintWarning(String.Format(GetMessage("Warning_InvalidDamageType"), entry.Key)); continue; } if (entry.Value == null || entry.Value < 0.0f) { PrintWarning(String.Format(GetMessage("Warning_InvalidDamageValue"), new object[] { entry.Key, entry.Value })); continue; } DamageTypeEntry d = new DamageTypeEntry(); d.type = (DamageType)Enum.Parse(typeof(DamageType), entry.Key); d.amount = entry.Value; damage.Add(d); } DamageUtil.RadiusDamage(entity, null, position, effect.minRadius, effect.maxRadius, damage, -1, false); }
public bool IsBlocked(BaseCombatEntity entity) { var result = false; if (entity is BuildingBlock) { result = true; } if (!result && !string.IsNullOrEmpty(entity.ShortPrefabName)) { var prefabName = entity.ShortPrefabName; if (blockCache.TryGetValue(prefabName, out result)) { return(result); } foreach (string p in prefabs) { if (prefabName.IndexOf(p) != -1) { result = true; break; } } if (!blockCache.ContainsKey(prefabName)) { blockCache.Add(prefabName, result); } } return(result); }
/// <summary> /// Executes the actual repair logic. /// </summary> /// <param name="block"></param> /// <param name="player"></param> void Repair(BaseCombatEntity block, BasePlayer player) { //Set message timer to prevent user spam ConfigureMessageTimer(); //Checks to see if the player can build if (player.CanBuild()) { //yes - Player can build - check if we can display our fix message if (_allowHandyManFixMessage) { //yes - display our fix message SendChatMessage(player, _ChatmessagePrefix, GetMsg("Fix", player.userID)); _allowHandyManFixMessage = false; } //Envoke the AOE repair set RepairAOE(block, player); } else { SendChatMessage(player, _ChatmessagePrefix, GetMsg("NotAllowed", player.userID)); } }
// Disable Friendly Fire for Players in Teams object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { if (!(entity is BasePlayer)) { return(null); } if (!(info.Initiator is BasePlayer)) { return(null); } if ((info.Initiator as BasePlayer) == (entity as BasePlayer)) { return(null); } if ((entity as BasePlayer).currentTeam == (info.Initiator as BasePlayer).currentTeam) { return(false); } return(null); }
private void OnEntityDeath(BaseCombatEntity entity, HitInfo hitInfo) { if (entity == null || !(entity is BasePlayer)) { return; } // Cast the entity to a BasePlayer BasePlayer player = (BasePlayer)entity; if (player == null || !playerSkills.ContainsKey(player.userID) || player.IsSleeping()) { return; } // The XP Penalty that will be applied to all skills long xpPenalty = 200; // Loop through all skills foreach (Skill skill in Skills.all) { long xp = playerSkills[player.userID].GetXp(skill.code); if (xp < xpPenalty) { return; } // Decrease the xp and level playerSkills[player.userID].SetXp(skill.code, xp - xpPenalty); playerSkills[player.userID].SetLevel(skill.code, GetXpLevel(xp - xpPenalty)); // Update the GUI UpdateGUI(player, skill); } }
public static object HandleTurretTarget(BaseCombatEntity turret, User defender) { if (!Instance.Options.Pvp.RestrictPvp) { return(null); } // A player can be always be targeted by their own turrets, to prevent exploiting this mechanic. if (defender.Player.userID == turret.OwnerID) { return(null); } Area turretArea = Instance.Areas.GetByEntityPosition(turret); if (turretArea == null || defender.CurrentArea == null) { Instance.PrintWarning("A turret tried to acquire a target in an unknown area. This shouldn't happen."); return(null); } // If the defender is in a faction, they can be targeted by turrets in areas claimed by factions with which they are at war. if (defender.Faction != null && turretArea.FactionId != null && Instance.Wars.AreFactionsAtWar(defender.Faction.Id, turretArea.FactionId)) { return(null); } // If the defender is in a PVP area or zone, the turret can trigger. // TODO: Ensure the turret is also in the PVP zone. if (IsUserInDanger(defender)) { return(null); } return(false); }
void OnEntityDeath(BaseCombatEntity entity, HitInfo hitInfo) { try { if (entity == null || !IsValidType(entity) || entity is BasePlayer) { return; } if (hitInfo?.Initiator is BasePlayer) { if (entity?.net?.ID == null) { return; } var boxId = entity.net.ID; if (!boxCache.ContainsKey(boxId)) { return; } boxCache[boxId].SetKiller(hitInfo.InitiatorPlayer.userID, hitInfo.InitiatorPlayer.displayName); } } catch { } }
private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitinfo) { if (Started) { try { if (entity is BasePlayer && hitinfo.Initiator is BasePlayer) { var victim = entity.ToPlayer(); var attacker = hitinfo.Initiator.ToPlayer(); if (disableDamage) { if (victim.userID != attacker.userID) { if (jailData.Prisoners.ContainsKey(victim.userID) && jailData.Prisoners.ContainsKey(attacker.userID)) { hitinfo.damageTypes.ScaleAll(0); SendMsg(attacker, lang.GetMessage("ff", this, attacker.UserIDString)); } } } else if (!jailData.Prisoners.ContainsKey(victim.userID) && jailData.Prisoners.ContainsKey(attacker.userID)) { hitinfo.damageTypes.ScaleAll(0); } else if (jailData.Prisoners.ContainsKey(victim.userID) && !jailData.Prisoners.ContainsKey(attacker.userID)) { hitinfo.damageTypes.ScaleAll(0); } } } catch (Exception ex) { } } }
void OnEntityDeath(BaseCombatEntity entity, HitInfo info) { try { if (info.Initiator.ToPlayer().IsValid()) { if (entity.name.Contains("animals")) { GiveMoney(info.Initiator.ToPlayer(), (Double)Config["OnAnimalKill"], "You killed an animal!"); } if (entity.name.Contains("loot-barrel") || entity.name.Contains("loot_barrel") || entity.name.Contains("loot_trash")) { GiveMoney(info.Initiator.ToPlayer(), (Double)Config["OnBarrelKill"], "You broke a loot barrel!"); } if (entity.ToPlayer().IsValid()) { GiveMoney(info.Initiator.ToPlayer(), (Double)Config["OnPlayerKill"], "You killed a player!"); } } } catch { } }
/// <summary> /// Executes the actual repair logic /// </summary> /// <param name="entity"></param> /// <param name="player"></param> void Repair(BaseCombatEntity entity, BasePlayer player) { // Set message timer to prevent user spam ConfigureMessageTimer(); // Checks to see if the player can build if (player.CanBuild()) { // Player can build - check if we can display our fix message if (_allowHandyManFixMessage) { // Display our fix message PrintToChat(player, Lang("Fix", player.UserIDString)); _allowHandyManFixMessage = false; } // Envoke the AOE repair set RepairAOE(entity, player); } else { PrintToChat(player, Lang("NotAllowed", player.UserIDString)); } }
void OnEntityTakeDamage(BaseCombatEntity entity) { var @lock = entity.GetSlot(0); if (@lock != null && @lock.IsLocked()) { if (usepermission) { List <ulong> whitelisted = codelockwhitelist.GetValue(@lock) as List <ulong>; if (whitelisted.Count >= 1) { if (permission.UserHasPermission(whitelisted[0].ToString(), "visionlocks.allow")) { entity.lastDamage = 0; } } } else { entity.lastDamage = 0; } } }
private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { if (!ignoreProjectiles) { return(null); } BaseTrap trap = entity.GetComponent <BaseTrap>(); if (!trap) { return(null); } if (!info.IsProjectile()) { return(null); } BearTrap bearTrap = entity.GetComponent <BearTrap>(); if (bearTrap) { bearTrap.Arm(); } return(true); }
// On Entity died / Call DeathNote void OnEntityDeath(BaseCombatEntity vic, HitInfo hitInfo) { if (!HasNeeded(vic, hitInfo)) // Does death contain needed info? { hitInfo = TryGetLastHit(vic); // Try to get the last availiable info } KillData data = new KillData(); // Initialize new KillData data.attacker = GetAttacker(hitInfo); // Save Attacker in KillData data.victim = GetVictim(vic); // Save Victim in KillData data.distance = GetDistance(vic, hitInfo); // Save Distance in KillData data.weapon = GetWeapon(hitInfo); // Save Weapon in KillData data.bodypart = GetBodypart(hitInfo); // Save Bodypart in KillData data.damage = FirstUpper(vic.lastDamage.ToString() ?? "Unknown Damage"); // Save Damage Type in KillData data.attachments = GetAttachments(hitInfo); // Save Attachments in KillData data.message = GetDeathType(hitInfo, data.damage, data.attacker, vic?.ToPlayer()?.IsSleeping() ?? false); // Save Death Type in KillData if ((Config["Animals"] as Dictionary <string, object>).ContainsKey(data.victim)) { data.message = "Animal Death"; } BroadcastDeath(data, hitInfo?.Initiator); }
object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { var cfgData = Config.ReadObject <ConfigData>(); if (info.InitiatorPlayer == null) { return(null); } if (entity.ToPlayer() == null) { return(null); } var targetPlayer = info.Initiator as BasePlayer; var victim = entity as BasePlayer; if (!CheckIfPlayerInClan(targetPlayer.userID)) { return(null); } if (!CheckIfPlayerInClan(victim.userID)) { return(null); } var targetPlayerClan = GetClanOf(targetPlayer.userID); var victimClan = GetClanOf(victim.userID); if (targetPlayerClan == victimClan && cfgData.FriendlyFireUse == true && victimClan.FriendlyFireActive == true) { LangMessageToPlayer(targetPlayer, LangMessages.FriendlyFire); return(false); } return(null); }
private HitInfo OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { if (bProtectionEnabled == true) { if (entity is BasePlayer) { var player = entity as BasePlayer; if (player.userID < 76560000000000000L || player is NPCPlayer) { return(null); } ProtectionInfo p = null; ProtectionInfo z = null; if (hitInfo.Initiator is BasePlayer) { var attacker = hitInfo.Initiator as BasePlayer; if (attacker.userID < 76560000000000000L || attacker is NPCPlayer) { return(null); } if (storedData.Players.TryGetValue(player.userID, out p)) { if (storedData.Players.TryGetValue(attacker.userID, out z)) { if (attacker.userID == player.userID) { return(null); } else { PunishPlayer(attacker); Log("Punishing " + attacker.displayName.ToString() + " for attempting to pvp."); } } if (attacker.userID != player.userID) { if (player.IsSleeping()) { //TODO possibly bug if (bSleeperProtection == false) { storedData.Players.Remove(player.userID); storedPlayersData.Players.Add(player.userID); Log("Removed " + player.displayName.ToString() + " (Sleeping) from the Start Protection list."); return(null); } } } PrintToChatEx(attacker, GetMessage("tAttackAttempt", attacker.UserIDString)); hitInfo.damageTypes.ScaleAll(0f); return(hitInfo); } else { if (storedData.Players.TryGetValue(attacker.userID, out p)) { PunishPlayer(attacker); Log("Punishing " + attacker.displayName.ToString() + " for attempting to pvp."); hitInfo.damageTypes.ScaleAll(0f); return(hitInfo); } } } else if (hitInfo.Initiator is BaseHelicopter) { if (bHelicopterProtection == true) { if (player == null) { return(null); } if (storedData.Players.TryGetValue(player.userID, out z)) { hitInfo.damageTypes.ScaleAll(0f); return(hitInfo); } } } } else if (entity is BuildingBlock || entity is Door || (entity.PrefabName?.Contains("building") ?? false) || (entity.PrefabName?.Contains("deployable") ?? false)) { if (hitInfo.Initiator is BasePlayer && entity.OwnerID != 0 && entity.OwnerID != (hitInfo.Initiator as BasePlayer).userID) { ProtectionInfo p = null; var attacker = hitInfo.Initiator as BasePlayer; if ((entity as BaseEntity).OwnerID != attacker.userID) { if (storedData.Players.TryGetValue(attacker.userID, out p)) { PunishPlayer(attacker); Log("Punishing " + attacker.displayName.ToString() + " for attempting to blow."); hitInfo.damageTypes.ScaleAll(0f); return(hitInfo); } } } } else if (entity is LootableCorpse && (entity as LootableCorpse).playerSteamID > 76560000000000000L) { if (hitInfo.Initiator is BasePlayer) { ProtectionInfo p = null; var attacker = hitInfo.Initiator as BasePlayer; if ((entity as LootableCorpse).playerSteamID != attacker.userID) { if (storedData.Players.TryGetValue(attacker.userID, out p)) { PunishPlayer(attacker); Log("Punishing " + attacker.displayName.ToString() + " for attempting to corpse."); hitInfo.damageTypes.ScaleAll(0f); return(hitInfo); } } } } } return(null); }
private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { string entity_name = null; if (!hitInfo.damageTypes.Has(DamageType.Decay)) { return(null); } try { entity_name = entity.LookupPrefab().name; } catch { return(null); } #if DEBUG Puts($"OnEntityTakeDamage: START CHECKING {entity_name}."); #endif string pos = entity.transform.position.ToString(); ulong hitEntityOwnerID = entity.OwnerID != 0 ? entity.OwnerID: hitInfo.HitEntity.OwnerID; float before = hitInfo.damageTypes.Get(Rust.DamageType.Decay); float multiplier = 1.0f; // First, we check for protected entities (NeverDecay) if (configData.NeverDecay.Contains(entity_name)) { multiplier = 0.0f; #if DEBUGND Puts($"OnEntityTakeDamage: START Skipping cupboard check for {entity_name} {pos} - will NOT decay!"); Puts("OnEntityTakeDamage: END Set damage for " + entity_name + " to " + multiplier.ToString() + ", was " + before.ToString() + "."); #endif // Apply our damage rules and return hitInfo.damageTypes.Scale(Rust.DamageType.Decay, multiplier); return(null); } #if DEBUG Puts($"OnEntityTakeDamage: START Checking {entity_name} at {pos}"); #endif // Second, we check for attached (BLOCK) or nearby (ENTITY) cupboard BuildingBlock block = entity as BuildingBlock; string isblock = ""; string buildGrade = ""; bool hascup = false; if (block != null) { isblock = " (building block)"; hascup = CheckCupboardBlock(block, hitInfo, entity_name); if (hascup) { multiplier = 0.0f; switch (block.grade) { case BuildingGrade.Enum.Twigs: if (configData.DecayTwig == true) { multiplier = configData.TwigRate; } break; case BuildingGrade.Enum.Wood: if (configData.DecayWood == true) { multiplier = configData.WoodRate; } break; case BuildingGrade.Enum.Stone: if (configData.DecayStone == true) { multiplier = configData.StoneRate; } break; case BuildingGrade.Enum.Metal: if (configData.DecayMetal == true) { multiplier = configData.MetalRate; } break; case BuildingGrade.Enum.TopTier: if (configData.DecayArmor == true) { multiplier = configData.ArmorRate; } break; } #if DEBUG switch (block.grade) { case BuildingGrade.Enum.Twigs: buildGrade = "(TWIG)"; break; case BuildingGrade.Enum.Wood: buildGrade = "(Wood)"; break; case BuildingGrade.Enum.Stone: buildGrade = "(Stone)"; break; case BuildingGrade.Enum.Metal: buildGrade = "(Metal)"; break; case BuildingGrade.Enum.TopTier: buildGrade = "(Armor)"; break; } Puts($"OnEntityTakeDamage: Block - Found cupboard attached to {entity_name}{buildGrade}"); #endif } else { #if DEBUG Puts($"OnEntityTakeDamage: Block - MISSING cupboard attached to {entity_name}{buildGrade}!"); Puts("OnEntityTakeDamage: END Set damage for " + entity_name + buildGrade + " to standard rate of " + before.ToString() + "."); #endif return(null); // Standard damage rates apply } } else if (CheckCupboardEntity(entity, hitInfo, entity_name)) { // Unprotected Entity with cupboard multiplier = 0.0f; #if DEBUG Puts($"OnEntityTakeDamage: Entity - Found cupboard near {entity_name}"); #endif } else { // Unprotected Entity with NO Cupboard #if DEBUG Puts($"OnEntityTakeDamage: Entity - MISSING cupboard near {entity_name}"); Puts("OnEntityTakeDamage: END Set damage for " + entity_name + " to standard rate of " + before.ToString() + "."); #endif return(null); // Standard damage rates apply } // Apply our damage rules and return hitInfo.damageTypes.Scale(Rust.DamageType.Decay, multiplier); #if DEBUG Puts("OnEntityTakeDamage: END Set damage for " + entity_name + isblock + " to " + multiplier.ToString() + ", was " + before.ToString() + "."); #endif return(null); }
void OnEntityDeath(BaseCombatEntity entity, HitInfo hitInfo) { BasePlayer playerVictim = entity as BasePlayer; if (playerVictim == null) { return; } if (!m_players.ContainsKey(playerVictim.userID)) { return; } playerVictim.inventory.Strip(); BasePlayer playerKiller = null; if (hitInfo != null) { if (hitInfo.Initiator != null) { playerKiller = hitInfo.Initiator as BasePlayer; if (playerKiller != null) { if (!m_players.ContainsKey(playerKiller.userID)) { return; } } } } if (playerKiller == playerVictim) { m_playersDeaths[playerVictim.userID]++; m_playersMurders[playerVictim.userID]--; } else { if (m_state == EventState.TeamDeathmatch) { if (m_players[playerVictim.userID] == m_players[playerKiller.userID]) { playerKiller.health = 1; m_playersMurders[playerKiller.userID]--; } else { m_playersDeaths[playerVictim.userID]++; m_playersMurders[playerKiller.userID]++; } } else { m_playersDeaths[playerVictim.userID]++; m_playersMurders[playerKiller.userID]++; } } string message; if (playerKiller != null && playerKiller != playerVictim) { message = m_configData.Messages["player_murder"].Replace("%killer_name", playerScore(playerKiller.userID)); } else { message = m_configData.Messages["player_death"]; } message = message.Replace("%victim_name", playerScore(playerVictim.userID)); PrintToChat(message); if (m_fragsMax != 0 && m_playersMurders[playerKiller.userID] >= m_fragsMax) { PrintToChat(m_configData.Messages["player_win"].Replace("%player", playerKiller.displayName)); m_lootedPlayers.Clear(); m_players.Clear(); m_playersDeaths.Clear(); m_playersMurders.Clear(); m_state = EventState.Disabled; } }
void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { if(protectedBlock.Contains(entity)) { CancelDamage(info); } }
private void OnBuildingExitZone(Zone zone, BaseCombatEntity entity) { buildingZones[entity]?.Remove(zone); if (HasZoneFlag(zone, ZoneFlags.NoStability)) { var block = entity as BuildingBlock; if (block == null) return; var prefab = GameManager.server.FindPrefab(block.blockDefinition.fullName); block.grounded = prefab.GetComponent<BuildingBlock>()?.grounded ?? false; } }
private void OnBuildingEnterZone(Zone zone, BaseCombatEntity entity) { HashSet<Zone> zones; if (!buildingZones.TryGetValue(entity, out zones)) buildingZones[entity] = zones = new HashSet<Zone>(); zones.Add(zone); if (HasZoneFlag(zone, ZoneFlags.NoStability)) { var block = entity as BuildingBlock; if (block == null) return; block.grounded = true; } }
void TryPasteLock(BaseCombatEntity lockableEntity, IDictionary<string, object> structure) { BaseEntity lockentity = null; if (structure.ContainsKey("codelock")) { lockentity = GameManager.server.CreateEntity("build/locks/lock.code", Vector3.zero, new Quaternion()); lockentity.OnDeployed(lockableEntity); var code = (string)structure["codelock"]; if (!string.IsNullOrEmpty(code)) { var @lock = lockentity.GetComponent<CodeLock>(); codelock.SetValue(@lock, (string)structure["codelock"]); @lock.SetFlag(BaseEntity.Flags.Locked, true); } } else if (structure.ContainsKey("keycode")) { lockentity = GameManager.server.CreateEntity("build/locks/lock.key", Vector3.zero, new Quaternion()); lockentity.OnDeployed(lockableEntity); var code = Convert.ToInt32(structure["keycode"]); var @lock = lockentity.GetComponent<KeyLock>(); if ((code & 0x80) != 0) { // Set the keycode only if that lock had keys before. Otherwise let it be random. keycode.SetValue(@lock, (code & 0x7F)); firstKeyCreated.SetValue(@lock, true); @lock.SetFlag(BaseEntity.Flags.Locked, true); } } if (lockentity) { lockentity.gameObject.Identity(); lockentity.SetParent(lockableEntity, "lock"); lockentity.Spawn(true); lockableEntity.SetSlot(BaseEntity.Slot.Lock, lockentity); } }
string GetVictim(BaseCombatEntity vic) { string victim = "Unknown Victim"; if(vic != null) { if(vic.ToPlayer() != null) { victim = vic.ToPlayer().displayName; } else { victim = FirstUpper(vic.LookupShortPrefabName() ?? "Unknown Victim"); victim = victim.Replace(".prefab", ""); } } return victim; }
private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { return Interface.Oxide.CallDeprecatedHook("OnEntityAttacked", entity, info); }
/// <summary> /// Called from <c>BaseCombatEntity.Hurt(HitInfo)</c> . /// </summary> public static void On_CombatEntityHurt(BaseCombatEntity combatEntity, HitInfo info) { try { Assert.Test(combatEntity.isServer, "This should be called serverside only"); if (combatEntity.IsDead()) return; using (TimeWarning.New("Hurt", 50)) { BaseNPC baseNPC = combatEntity.GetComponent<BaseNPC>(); BaseCorpse baseCorpse = combatEntity.GetComponent<BaseCorpse>(); BasePlayer basePlayer = combatEntity.GetComponent<BasePlayer>(); combatEntity.ScaleDamage(info); if (basePlayer != null) { Player player = Server.GetPlayer(basePlayer); if (player.Teleporting) { for (int i = 0; i < info.damageTypes.types.Length; i++) { info.damageTypes.types[i] = 0f; } } HurtEvent he = new PlayerHurtEvent(player, info); OnNext("On_PlayerHurt", he); } else if (baseNPC != null) { HurtEvent he = new NPCHurtEvent(new NPC(baseNPC), info); OnNext("On_NPCHurt", he); } else if (baseCorpse != null) { HurtEvent he = new CorpseHurtEvent(baseCorpse, info); OnNext("On_CorpseHurt", he); } else { HurtEvent he = new CombatEntityHurtEvent(combatEntity, info); OnNext("On_CombatEntityHurt", he); } if (info.PointStart != Vector3.zero) { DirectionProperties[] directionProperties = (DirectionProperties[])combatEntity.GetFieldValue("propDirection"); for (int i = 0; i < directionProperties.Length; i++) { if (!(directionProperties[i].extraProtection == null)) { if (directionProperties[i].IsWeakspot(combatEntity.transform, info)) { directionProperties[i].extraProtection.Scale(info.damageTypes); } } } } // the DebugHurt() method if (ConVar.Vis.attack) { if (info.PointStart != info.PointEnd) { ConsoleNetwork.BroadcastToAllClients("ddraw.arrow", new object[] { 60, UnityEngine.Color.cyan, info.PointStart, info.PointEnd, 0.1 }); ConsoleNetwork.BroadcastToAllClients("ddraw.sphere", new object[] { 60, UnityEngine.Color.cyan, info.HitPositionWorld, 0.05 }); } string text = String.Empty; for (int i = 0; i < info.damageTypes.types.Length; i++) { float num = info.damageTypes.types[i]; if (num != 0) { string text2 = text; text = String.Concat(new string[] { text2, " ", ((global::Rust.DamageType)i).ToString().PadRight(10), num.ToString("0.00"), "\r\n" }); } } string text3 = String.Concat(new object[] { "<color=lightblue>Damage:</color>".PadRight(10), info.damageTypes.Total().ToString("0.00"), "\r\n<color=lightblue>Health:</color>".PadRight(10), combatEntity.health.ToString("0.00"), " / ", (combatEntity.health - info.damageTypes.Total() > 0) ? "<color=green>" : "<color=red>", (combatEntity.health - info.damageTypes.Total()).ToString("0.00"), "</color>", "\r\n<color=lightblue>Hit Ent:</color>".PadRight(10), combatEntity, "\r\n<color=lightblue>Attacker:</color>".PadRight(10), info.Initiator, "\r\n<color=lightblue>Weapon:</color>".PadRight(10), info.Weapon, "\r\n<color=lightblue>Damages:</color>\r\n", text }); ConsoleNetwork.BroadcastToAllClients("ddraw.text", new object[] { 60, UnityEngine.Color.white, info.HitPositionWorld, text3 }); } combatEntity.health -= info.damageTypes.Total(); combatEntity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); if (ConVar.Global.developer > 1) { Debug.Log(string.Concat(new object[] { "[Combat]".PadRight(10), combatEntity.gameObject.name, " hurt ", info.damageTypes.GetMajorityDamageType(), "/", info.damageTypes.Total(), " - ", combatEntity.health.ToString("0"), " health left" })); } combatEntity.lastDamage = info.damageTypes.GetMajorityDamageType(); combatEntity.lastAttacker = info.Initiator; BaseCombatEntity baseCombatEntity = combatEntity.lastAttacker as BaseCombatEntity; if (baseCombatEntity != null) baseCombatEntity.MarkHostileTime(); combatEntity.SetFieldValue("_lastAttackedTime", Time.time); if (combatEntity.health <= 0f) { combatEntity.Die(info); BuildingBlock bb = combatEntity.GetComponent<BuildingBlock>(); if (bb != null) { OnNext("On_BuildingPartDestroyed", new BuildingPartDestroyedEvent(bb, info)); } } } } catch (Exception ex) { Logger.LogError("[Hooks] Error in CombatEntityHurt hook."); Logger.LogException(ex); } }
///////////////////////////////////////// // OnEntityAttacked(BaseCombatEntity entity, HitInfo hitinfo) // Called when any entity is attacked ///////////////////////////////////////// private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitinfo) { if (entity == null) return; if (entity is BasePlayer) { var player = (BasePlayer)entity; if (player.IsSleeping()) { if (HasPlayerFlag(player, ZoneFlags.SleepGod)) CancelDamage(hitinfo); } else if (hitinfo.Initiator != null) { if (hitinfo.Initiator is BasePlayer) { if (((BasePlayer)hitinfo.Initiator).userID < 76560000000000000L) return; if (HasPlayerFlag(player, ZoneFlags.PvpGod)) CancelDamage(hitinfo); else if (HasPlayerFlag((BasePlayer)hitinfo.Initiator, ZoneFlags.PvpGod)) CancelDamage(hitinfo); } else if (HasPlayerFlag(player, ZoneFlags.PveGod)) CancelDamage(hitinfo); } } else if (entity is BaseNPC) { var npcai = (BaseNPC)entity; HashSet<Zone> zones; if (!npcZones.TryGetValue(npcai, out zones)) return; foreach (var zone in zones) { if (HasZoneFlag(zone, ZoneFlags.NoPve)) { CancelDamage(hitinfo); break; } } } else { HashSet<Zone> zones; if (!buildingZones.TryGetValue(entity, out zones)) return; foreach (var zone in zones) { if (HasZoneFlag(zone, ZoneFlags.UnDestr)) { CancelDamage(hitinfo); break; } } } }
// On Entity died / Call DeathNote void OnEntityDeath(BaseCombatEntity vic, HitInfo hitInfo) { if(!HasNeeded(vic, hitInfo)) // Does death contain needed info? { hitInfo = TryGetLastHit(vic); // Try to get the last availiable info } KillData data = new KillData(); // Initialize new KillData data.attacker = GetAttacker(hitInfo); // Save Attacker in KillData data.victim = GetVictim(vic); // Save Victim in KillData data.distance = GetDistance(vic, hitInfo); // Save Distance in KillData data.weapon = GetWeapon(hitInfo); // Save Weapon in KillData data.bodypart = GetBodypart(hitInfo); // Save Bodypart in KillData data.damage = FirstUpper(vic.lastDamage.ToString() ?? "Unknown Damage"); // Save Damage Type in KillData data.attachments = GetAttachments(hitInfo); // Save Attachments in KillData data.message = GetDeathType(hitInfo, data.damage, data.attacker, vic?.ToPlayer()?.IsSleeping() ?? false); // Save Death Type in KillData if((Config["Animals"] as Dictionary<string, object>).ContainsKey(data.victim)) data.message = "Animal Death"; BroadcastDeath(data, hitInfo?.Initiator); }
public void OnEntityDeath(BaseCombatEntity entity) { if (entity == null) return; var resource = entity.GetComponent<ResourceDispenser>(); if (resource != null) Resource.Remove(resource); else if (entity is BasePlayer) Player.Remove((BasePlayer) entity); else if (entity is BaseNPC) Npc.Remove((BaseNPC)entity); else if (!(entity is LootContainer) && !(entity is BaseHelicopter) && !(entity is BaseCorpse)) Building.Remove(entity); else Other.Remove(entity); }
HitInfo TryGetLastHit(BaseCombatEntity vic) { if(vic == null || vic.ToPlayer() == null) return null; if(lastHitInfo.ContainsKey(vic.ToPlayer())) return lastHitInfo[vic.ToPlayer()]; return null; }
int GetDistance(BaseCombatEntity vic, HitInfo hitInfo) { float distance = 0; distance = Vector3.Distance(vic.transform.position, hitInfo?.Initiator?.transform.position ?? vic.transform.position); return Convert.ToInt32(distance); }
public static void CombatEntityHurt(BaseCombatEntity combatEnt, HitInfo info) { try { Assert.Test(combatEnt.isServer, "This should be called serverside only"); if (combatEnt.IsDead()) { return; } BaseNPC npc = combatEnt.GetComponent<BaseNPC>(); BaseCorpse corpse = combatEnt.GetComponent<BaseCorpse>(); BasePlayer player = combatEnt.GetComponent<BasePlayer>(); if (!SkinnedMeshCollider.ScaleDamage(info)) { if (combatEnt.baseProtection != null) { combatEnt.baseProtection.Scale(info.damageTypes); if (ConVar.Global.developer > 1) { Debug.Log("BaseProtection Scaling for entity :" + combatEnt.name); } } } else if (ConVar.Global.developer > 1) { Debug.Log("SMC scaling damage for entity :" + combatEnt.name); } HurtEvent he; if (player != null) { Player p = Server.GetPlayer(player); if (p.Teleporting) { for (int i = 0; i < info.damageTypes.types.Length; i++) { info.damageTypes.types[i] = 0f; } } he = new PlayerHurtEvent(p, info); OnPlayerHurt.OnNext(he as PlayerHurtEvent); } else if (npc != null) { he = new NPCHurtEvent(new NPC(npc), info); OnNPCHurt.OnNext(he as NPCHurtEvent); } else if (corpse != null) { he = new CorpseHurtEvent(corpse, info); OnCorpseHurt.OnNext(he as CorpseHurtEvent); } else { he = new CombatEntityHurtEvent(combatEnt, info); OnCombatEntityHurt.OnNext(he as CombatEntityHurtEvent); } // the DebugHurt() method if (ConVar.Vis.attack) { if (info.PointStart != info.PointEnd) { ConsoleSystem.Broadcast("ddraw.arrow", new object[] { 60, Color.cyan, info.PointStart, info.PointEnd, 0.1 }); ConsoleSystem.Broadcast("ddraw.sphere", new object[] { 60, Color.cyan, info.HitPositionWorld, 0.05 }); } string text = String.Empty; for (int i = 0; i < info.damageTypes.types.Length; i++) { float num = info.damageTypes.types[i]; if (num != 0) { string text2 = text; text = String.Concat(new string[] { text2, " ", ((Rust.DamageType)i).ToString().PadRight(10), num.ToString("0.00"), "\r\n" }); } } string text3 = String.Concat(new object[] { "<color=lightblue>Damage:</color>".PadRight(10), info.damageTypes.Total().ToString("0.00"), "\r\n<color=lightblue>Health:</color>".PadRight(10), combatEnt.health.ToString("0.00"), " / ", (combatEnt.health - info.damageTypes.Total() > 0) ? "<color=green>" : "<color=red>", (combatEnt.health - info.damageTypes.Total()).ToString("0.00"), "</color>", "\r\n<color=lightblue>Hit Ent:</color>".PadRight(10), combatEnt, "\r\n<color=lightblue>Attacker:</color>".PadRight(10), info.Initiator, "\r\n<color=lightblue>Weapon:</color>".PadRight(10), info.Weapon, "\r\n<color=lightblue>Damages:</color>\r\n", text }); ConsoleSystem.Broadcast("ddraw.text", new object[] { 60, Color.white, info.HitPositionWorld, text3 }); } if (combatEnt.skeletonProperties) { combatEnt.skeletonProperties.ScaleDamage(info); } if (info.PointStart != Vector3.zero) { DirectionProperties[] directionProperties = (DirectionProperties[])combatEnt.GetFieldValue("propDirection"); for (int i = 0; i < directionProperties.Length; i++) { if (!(directionProperties[i].extraProtection == null)) { if (directionProperties[i].IsPointWithinRadius(combatEnt.transform, info.PointStart)) { directionProperties[i].extraProtection.Scale(info.damageTypes); } } } } combatEnt.health -= info.damageTypes.Total(); combatEnt.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); if (ConVar.Global.developer > 1) { Debug.Log(string.Concat(new object[] { "[Combat]".PadRight(10), combatEnt.gameObject.name, " hurt ", info.damageTypes.GetMajorityDamageType(), "/", info.damageTypes.Total(), " - ", combatEnt.health.ToString("0"), " health left" })); } combatEnt.lastDamage = info.damageTypes.GetMajorityDamageType(); combatEnt.lastAttacker = info.Initiator; if (combatEnt.health <= 0f) { combatEnt.Die(info); BuildingBlock bb = combatEnt.GetComponent<BuildingBlock>(); if (bb != null) { OnBuildingPartDestroyed.OnNext(new BuildingPartDestroyedEvent(bb, info)); } } } catch (Exception ex) { Logger.LogError("[Hooks] Error in CombatEntityHurt hook."); Logger.LogException(ex); } }
bool HasNeeded(BaseCombatEntity vic, HitInfo hitInfo) { if(vic == null) return false; // Stop here if victim does not exist if(hitInfo == null && metabolismTypes.Contains(vic.lastDamage.ToString()) == false) return false; // Stop here if hitInfo does not exist and death is not metabolism return true; // Else return true }
void OnEntityTakeDamage(BaseCombatEntity entity, ref HitInfo hit) { if (entity is BuildingBlock) { // Building being attacked? Which one? EventBlock event_block = entity.GetComponent<EventBlock>(); if (event_block != null) { hit.damageTypes = new Rust.DamageTypeList(); hit.HitMaterial = 0; hit.PointStart = Vector3.zero; } } if (entity.GetComponent<EventPlayerTeleporting>() != null) { hit.damageTypes = new Rust.DamageTypeList(); hit.HitMaterial = 0; hit.PointStart = Vector3.zero; entity.GetComponent<BasePlayer>().metabolism.bleeding.Reset(); } if (!EventLobby && eventPlayers.Count > 0 && entity is BasePlayer) { if (entity is BasePlayer && hit.Initiator is BasePlayer && hit.Initiator.GetComponent<EventPlayer>() != null) { OnAttackShared(hit.Initiator as BasePlayer, entity as BasePlayer, ref hit); } else if (entity is BasePlayer && !(hit.Initiator is BasePlayer) && entity.GetComponent<EventPlayer>() != null) { hit.damageTypes = new Rust.DamageTypeList(); hit.HitMaterial = 0; hit.PointStart = Vector3.zero; entity.GetComponent<BasePlayer>().metabolism.bleeding.Reset(); } } }
void OnEntityTakeDamage(BaseCombatEntity vic, HitInfo hitInfo) { if(vic == null || hitInfo == null || vic.ToPlayer() == null) return; lastHitInfo[vic.ToPlayer()] = hitInfo; }
///////////////////////////////////////// // OnEntityAttacked(BaseCombatEntity entity, HitInfo hitinfo) // Called when any entity is attacked ///////////////////////////////////////// void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitinfo) { if (entity is BasePlayer) { cachedPlayer = entity as BasePlayer; if (cachedPlayer.IsSleeping()) { if (hasTag(cachedPlayer, "sleepgod")) CancelDamage(hitinfo); } else if (hitinfo.Initiator != null) { if (hitinfo.Initiator is BasePlayer) { if (hasTag(cachedPlayer, "pvpgod")) CancelDamage(hitinfo); } else if (hasTag(cachedPlayer, "pvegod")) CancelDamage(hitinfo); } } else if (entity is BaseCombatEntity) { BaseCombatEntity block = entity as BaseCombatEntity; if (buildingZones[block] == null) return; foreach(Zone zone in buildingZones[block]) { if(zone.info.undestr != null) { CancelDamage(hitinfo); } } } else if(entity is WorldItem) { if (hitinfo != null && hitinfo.Initiator != null) { if (hitinfo.Initiator is BasePlayer) { if (hasTag(hitinfo.Initiator as BasePlayer, "undestr")) CancelDamage(hitinfo); } } } }
///////////////////////////////////////// // OnEntityDeath(BaseNetworkable basenet) // Called when any entity is spawned ///////////////////////////////////////// void OnEntityDeath(BaseCombatEntity entity, HitInfo hitinfo) { if(entity is BasePlayer) { cachedPlayer = entity as BasePlayer; if(hasTag(cachedPlayer, "nocorpse")) { timer.Once(0.1f, () => EraseCorpse(entity.transform.position)); } if(playerZones[cachedPlayer] != null) playerZones[cachedPlayer].Clear(); } }
///////////////////////////////////////// // OnEntityDeath(BaseNetworkable basenet) // Called when any entity dies ///////////////////////////////////////// private void OnEntityDeath(BaseCombatEntity entity, HitInfo hitinfo) { if (entity == null) return; var resource = entity.GetComponent<ResourceDispenser>(); if (resource != null) { HashSet<Zone> zones; if (resourceZones.TryGetValue(resource, out zones)) { foreach (var zone in zones) zone.OnEntityDeath(entity); resourceZones.Remove(resource); } } else if (entity is BasePlayer) { var player = (BasePlayer) entity; HashSet<Zone> zones; if (playerZones.TryGetValue(player, out zones)) { foreach (var zone in zones) zone.OnEntityDeath(entity); zones.Clear(); UpdateFlags(player); } } else if (entity is BaseNPC) { HashSet<Zone> zones; if (npcZones.TryGetValue((BaseNPC)entity, out zones)) { foreach (var zone in zones) zone.OnEntityDeath(entity); npcZones.Remove((BaseNPC)entity); } } else if (!(entity is LootContainer) && !(entity is BaseHelicopter)) { HashSet<Zone> zones; if (buildingZones.TryGetValue(entity, out zones)) { foreach (var zone in zones) zone.OnEntityDeath(entity); buildingZones.Remove(entity); } } else { HashSet<Zone> zones; if (otherZones.TryGetValue(entity, out zones)) { foreach (var zone in zones) zone.OnEntityDeath(entity); otherZones.Remove(entity); } } }
private object OnEntityTakeDamage(BaseCombatEntity anEntity, HitInfo aHitInfo) { if (!aHitInfo?.Weapon?.GetComponent <TaserController>()) { return(null); } aHitInfo.damageTypes.Clear(); aHitInfo.DoHitEffects = false; aHitInfo.DoDecals = false; if (aHitInfo.InitiatorPlayer && !permission.UserHasPermission(aHitInfo.InitiatorPlayer.UserIDString, PERMISSION_USETASER)) { return(true); } float theDistance = !aHitInfo.IsProjectile() ? Vector3.Distance(aHitInfo.PointStart, aHitInfo.HitPositionWorld) : aHitInfo.ProjectileDistance; if (config.TaserDistance > 0f && theDistance > config.TaserDistance) { aHitInfo.DidHit = false; return(true); } Effect.server.Run(config.PrefabShock, anEntity, aHitInfo.HitBone, aHitInfo.HitPositionLocal, aHitInfo.HitNormalLocal); aHitInfo.damageTypes.Add(DamageType.ElectricShock, config.TaserDamage); BasePlayer thePlayer = anEntity?.GetComponent <BasePlayer>(); if (thePlayer) { if (thePlayer.IsNpc) { if (aHitInfo.InitiatorPlayer && !permission.UserHasPermission(aHitInfo.InitiatorPlayer.UserIDString, PERMISSION_TASENPC)) { return(null); } if (config.InstantKillsNPCs) { thePlayer.Die(aHitInfo); return(null); } if (config.NPCBeltLocked) { thePlayer.inventory.containerBelt.SetLocked(true); } if (config.NPCWearLocked) { thePlayer.inventory.containerWear.SetLocked(true); } } ShockedController theController = thePlayer.GetComponent <ShockedController>(); if (!theController) { theController = thePlayer.gameObject.AddComponent <ShockedController>(); theController.Config = config; } NextFrame(() => theController.Shock(aHitInfo)); } return(null); }
private object OnBaseCombatEntityHurt(BaseCombatEntity entity, HitInfo info) { if (entity is BasePlayer) return null; return Interface.Oxide.CallHook("OnEntityTakeDamage", entity, info); }
private bool AiCaresAbout(BaseEntity entity) { if (entity == null) { return(false); } if (!entity.isServer) { return(false); } if (entity.EqualNetID(owner)) { return(false); } if (entity.Health() <= 0f) { return(false); } if (!IsValidSenseType(entity)) { return(false); } BaseCombatEntity baseCombatEntity = entity as BaseCombatEntity; BasePlayer basePlayer = entity as BasePlayer; if (ignoreSafeZonePlayers && basePlayer != null && basePlayer.InSafeZone()) { return(false); } if (listenRange > 0f && baseCombatEntity != null && baseCombatEntity.TimeSinceLastNoise <= 1f && baseCombatEntity.CanLastNoiseBeHeard(owner.transform.position, listenRange)) { return(true); } if (senseFriendlies && ownerSenses != null && ownerSenses.IsFriendly(entity)) { return(true); } float num = float.PositiveInfinity; if (baseCombatEntity != null && AI.accuratevisiondistance) { num = Vector3.Distance(owner.transform.position, baseCombatEntity.transform.position); if (num > maxRange) { return(false); } } if (checkVision && !IsTargetInVision(entity)) { if (!ignoreNonVisionSneakers) { return(false); } if (basePlayer != null && !basePlayer.IsNpc) { if (!AI.accuratevisiondistance) { num = Vector3.Distance(owner.transform.position, basePlayer.transform.position); } if ((basePlayer.IsDucked() && num >= 4f) || num >= 15f) { return(false); } } } if (hostileTargetsOnly && baseCombatEntity != null && !baseCombatEntity.IsHostile()) { return(false); } if (checkLOS && ownerAttack != null) { bool flag = ownerAttack.CanSeeTarget(entity); Memory.SetLOS(entity, flag); if (!flag) { return(false); } } return(true); }
private void OnEntityDeath(BaseCombatEntity entity, HitInfo hitInfo) { HookCalled("OnEntityDeath"); // TODO: Print player died // TODO: Automatically respawn admin after X time }
object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { if (entity == null) { return(null); } if (IsPointInside(new Position(entity.transform.position))) { if (entity as BasePlayer != null) { return(null); } if (hitInfo == null) { return("handled"); } BasePlayer player = hitInfo.Initiator as BasePlayer; BasePlayer targetPlayer = entity as BasePlayer; if (player != null && targetPlayer != null) { if (m_players.ContainsKey(player.userID) && m_players.ContainsKey(targetPlayer.userID) && m_players[player.userID] == m_players[targetPlayer.userID] && m_state == EventState.TeamDeathmatch) { player.health = player.health / 2; return(false); } } Signage sign = entity as Signage; if (player == null || sign == null) { return("handled"); } uint lootGetterId = sign.net.ID; if (m_lootGetterWaiting != Team.Common && (player.net.connection.authLevel > 0 || permission.UserHasPermission(player.userID.ToString(), PluginCommand))) { if (m_configData.LootGetters.ContainsKey(lootGetterId)) { player.ChatMessage(m_configData.Messages["loot_getter_was_removed"].Replace("%loot_getter", lootGetterId.ToString()).Replace("%team", m_configData.ColorByTeam[m_configData.LootGetters[lootGetterId]])); m_configData.LootGetters.Remove(lootGetterId); } else { m_configData.LootGetters[lootGetterId] = m_lootGetterWaiting; player.ChatMessage(m_configData.Messages["loot_getter_was_added"].Replace("%loot_getter", lootGetterId.ToString()).Replace("%team", m_configData.ColorByTeam[m_configData.LootGetters[lootGetterId]])); } SaveData(); return("handled"); } if (!m_configData.LootGetters.ContainsKey(lootGetterId)) { return("handled"); } if (!m_players.ContainsKey(player.userID)) { return("handled"); } Team gettetTeam = m_configData.LootGetters[lootGetterId]; Team playerTeam = m_players[player.userID]; if (gettetTeam == playerTeam || playerTeam == Team.Common) { if (!m_lootedPlayers.Contains(player.userID)) { SSNKits.Call <bool>("LoadKitToPlayer", player, m_configData.KitByTeam[playerTeam]); m_lootedPlayers.Add(player.userID); } } return("handled"); } else { return(null); } }
private object IOnBaseCombatEntityHurt(BaseCombatEntity entity, HitInfo info) { return entity is BasePlayer ? null : Interface.CallHook("OnEntityTakeDamage", entity, info); }
private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) { if (entity is BuildingBlock || entity.name.Contains("deploy") || entity.name.Contains("building")) { var player = info?.Initiator?.ToPlayer(); if (!player || !entity.OwnerID.IsSteamId()) { return(null); } if (cFile.FriendBypass.Enabled) { // Owner checks if (cFile.FriendBypass.PlayerOwner.Enabled && player.userID == entity.OwnerID) { return(null); } // Friend checks if (Friends) { var hasFriend = Friends?.Call("HasFriend", entity.OwnerID.ToString(), player.UserIDString) ?? false; if (cFile.FriendBypass.FriendsApi.Enabled && (bool)hasFriend) { return(null); } } if (Clans) { // Clan checks var targetClan = (string)Clans?.Call("GetClanOf", entity.OwnerID.ToString()); var playerClan = (string)Clans?.Call("GetClanOf", player.UserIDString); if (cFile.FriendBypass.RustIoClans.Enabled && playerClan != null && targetClan != null && targetClan == playerClan) { return(null); } } } // Prevents player from damaging after friendbypass checks if (cFile.StopAllRaiding) { PrintToChat(player, Lang("CantDamage", player.UserIDString)); return(true); } // No raid command checks if (!_canRaid) { PrintToChat(player, Lang("Cmd_CantRaid", player.UserIDString, GetFormattedTime((_cachedRaidTime.AddMinutes(_startMinutes) - DateTime.UtcNow).TotalSeconds))); return(true); } // Wipe raid checks if (cFile.WipeRaiding.Enabled && !_canWipeRaid) { PrintToChat(player, Lang("Cmd_CantRaid", player.UserIDString, GetFormattedTime((_cachedWipeTime.AddMinutes(cFile.WipeRaiding.MinsFromWipe) - DateTime.UtcNow).TotalSeconds))); return(true); } if (cFile.WipeRaiding.Enabled) { return(null); } } return(null); }
public virtual void Hurt(HitInfo info) { Assert.IsTrue(this.isServer, "This should be called serverside only"); if (this.IsDead()) { return; } using (TimeWarning.New("Hurt( HitInfo )", 50L)) { float health = this.health; this.ScaleDamage(info); if (Vector3.op_Inequality(info.PointStart, Vector3.get_zero())) { for (int index = 0; index < this.propDirection.Length; ++index) { if (!Object.op_Equality((Object)this.propDirection[index].extraProtection, (Object)null) && !this.propDirection[index].IsWeakspot(((Component)this).get_transform(), info)) { this.propDirection[index].extraProtection.Scale(info.damageTypes, 1f); } } } info.damageTypes.Scale(DamageType.Arrow, ConVar.Server.arrowdamage); info.damageTypes.Scale(DamageType.Bullet, ConVar.Server.bulletdamage); info.damageTypes.Scale(DamageType.Slash, ConVar.Server.meleedamage); info.damageTypes.Scale(DamageType.Blunt, ConVar.Server.meleedamage); info.damageTypes.Scale(DamageType.Stab, ConVar.Server.meleedamage); info.damageTypes.Scale(DamageType.Bleeding, ConVar.Server.bleedingdamage); if (Interface.CallHook("IOnBaseCombatEntityHurt", (object)this, (object)info) != null) { return; } this.DebugHurt(info); this.health = health - info.damageTypes.Total(); this.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); if (Global.developer > 1) { Debug.Log((object)("[Combat]".PadRight(10) + ((Object)((Component)this).get_gameObject()).get_name() + " hurt " + (object)info.damageTypes.GetMajorityDamageType() + "/" + (object)info.damageTypes.Total() + " - " + this.health.ToString("0") + " health left")); } this.lastDamage = info.damageTypes.GetMajorityDamageType(); this.lastAttacker = info.Initiator; if (Object.op_Inequality((Object)this.lastAttacker, (Object)null)) { BaseCombatEntity lastAttacker = this.lastAttacker as BaseCombatEntity; if (Object.op_Inequality((Object)lastAttacker, (Object)null)) { lastAttacker.lastDealtDamageTime = Time.get_time(); } } BaseCombatEntity lastAttacker1 = this.lastAttacker as BaseCombatEntity; if (this.markAttackerHostile && Object.op_Inequality((Object)lastAttacker1, (Object)null) && Object.op_Inequality((Object)lastAttacker1, (Object)this)) { lastAttacker1.MarkHostileFor(60f); } if (this.lastDamage != DamageType.Decay) { this.lastAttackedTime = Time.get_time(); if (Object.op_Inequality((Object)this.lastAttacker, (Object)null)) { Vector3 vector3 = Vector3.op_Subtraction(((Component)this.lastAttacker).get_transform().get_position(), ((Component)this).get_transform().get_position()); this.LastAttackedDir = ((Vector3) ref vector3).get_normalized(); } } if ((double)this.health <= 0.0) { this.Die(info); } BasePlayer initiatorPlayer = info.InitiatorPlayer; if (!Object.op_Implicit((Object)initiatorPlayer)) { return; } if (this.IsDead()) { initiatorPlayer.stats.combat.Log(info, health, this.health, "killed"); } else { initiatorPlayer.stats.combat.Log(info, health, this.health, (string)null); } } }
private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { if (entity == null || hitInfo == null) { return; } var buildingBlock = entity as BuildingBlock; if (buildingBlock != null) { BuildingBlock block = buildingBlock; BasePlayer attacker = hitInfo.Initiator?.ToPlayer(); if (attacker == null) { return; } object modifier; if (block.LookupPrefab().name.ToLower().Contains("foundation") && !CupboardPrivlidge(attacker, block.transform.position)) { if (IsOwner(attacker, block)) { return; } RaycastHit hit; if (ExcludeCave && Physics.SphereCast(block.transform.position, .1f, Vector3.down, out hit, 250, groundLayer) && hit.collider.name.Contains("cave_")) { return; } if (!UseDamageScaling) { hitInfo.damageTypes = new DamageTypeList(); hitInfo.DoHitEffects = false; hitInfo.HitMaterial = 0; SendReply(attacker, lang.GetMessage("NoPerm", this, attacker.UserIDString)); return; } DamageType type = hitInfo.damageTypes.GetMajorityDamageType(); if (damageList.TryGetValue(type.ToString(), out modifier)) { float mod = Convert.ToSingle(modifier); if (mod > 0.0f) { hitInfo.damageTypes.Scale(type, mod); damageGradeScaling.TryGetValue(block.grade.ToString(), out modifier); mod = Convert.ToSingle(modifier); if (Math.Abs(mod) > 0) { hitInfo.damageTypes.Scale(type, mod); return; } hitInfo.damageTypes = new DamageTypeList(); hitInfo.DoHitEffects = false; hitInfo.HitMaterial = 0; SendReply(attacker, lang.GetMessage("NoPerm", this, attacker.UserIDString)); } else { hitInfo.damageTypes = new DamageTypeList(); hitInfo.DoHitEffects = false; hitInfo.HitMaterial = 0; SendReply(attacker, lang.GetMessage("NoPerm", this, attacker.UserIDString)); } } } else if (block.LookupPrefab().name.ToLower().Contains("foundation") && CupboardPrivlidge(attacker, block.transform.position)) { if (IsOwner(attacker, block)) { return; } if (!UseDamageScaling) { hitInfo.damageTypes = new DamageTypeList(); hitInfo.DoHitEffects = false; hitInfo.HitMaterial = 0; SendReply(attacker, lang.GetMessage("NoPerm", this, attacker.UserIDString)); return; } DamageType type = hitInfo.damageTypes.GetMajorityDamageType(); if (damageList.TryGetValue(type.ToString(), out modifier)) { var mod = Convert.ToSingle(modifier); if (Math.Abs(mod) > 0) { hitInfo.damageTypes.Scale(type, mod); damageGradeScaling.TryGetValue(block.grade.ToString(), out modifier); mod = Convert.ToSingle(modifier); if (Math.Abs(mod) > 0) { hitInfo.damageTypes.Scale(type, mod); return; } hitInfo.damageTypes = new DamageTypeList(); hitInfo.DoHitEffects = false; hitInfo.HitMaterial = 0; SendReply(attacker, lang.GetMessage("NoPerm", this, attacker.UserIDString)); } else { hitInfo.damageTypes = new DamageTypeList(); hitInfo.DoHitEffects = false; hitInfo.HitMaterial = 0; SendReply(attacker, lang.GetMessage("NoPerm", this, attacker.UserIDString)); } } } } }
private object IOnBaseCombatEntityHurt(BaseCombatEntity entity, HitInfo hitInfo) { return(entity is BasePlayer ? null : Interface.CallHook("OnEntityTakeDamage", entity, hitInfo)); }
private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { //Puts("OnEntityTakeDamage() called."); //for debug purposes //if (entity == null || hitInfo == null) return; if (entity is BasePlayer && hitInfo.Initiator is BasePlayer) { //float damageScale = 1.0f; var sb = new StringBuilder(); if (entity as BasePlayer == null || hitInfo == null) return; var attackerPlayer = (BasePlayer)hitInfo.Initiator; var victimPlayer = (BasePlayer)entity; var victimID = victimPlayer.userID; var attackerID = attackerPlayer.userID; if (playerTeam.ContainsKey(victimID) && playerTeam.ContainsKey(attackerID)) { if (victimID != attackerID) { if (playerTeam[victimID] == playerTeam[attackerID]) { hitInfo.damageTypes.ScaleAll(damageScale); sb.Append("Friendly Fire!"); } } } SendReply(hitInfo.Initiator as BasePlayer, sb.ToString()); } }
private void OnRunPlayerMetabolism(PlayerMetabolism metabolism, BaseCombatEntity ownerEntity, float delta) { if (!(ownerEntity is BasePlayer)) return; if (metabolism.bleeding.value > 0 && HasPlayerFlag((BasePlayer) ownerEntity, ZoneFlags.NoBleed)) metabolism.bleeding.value = 0f; if (metabolism.oxygen.value < 1 && HasPlayerFlag((BasePlayer) ownerEntity, ZoneFlags.NoDrown)) metabolism.oxygen.value = 1; }
void OnEntityDeath(BaseCombatEntity entity, HitInfo info) { try { var attacker = info?.InitiatorPlayer; if (attacker == null) { return; } CheckEntry(attacker); if (entity is BasePlayer) { var victim = entity.ToPlayer(); if (IsPlaying(attacker)) { return; } if (IsFriend(attacker.userID, victim.userID)) { return; } if (IsClanmate(attacker.userID, victim.userID)) { return; } if (configData.Options.IgnoreSleepers && victim.IsSleeping()) { return; } var distance = Vector3.Distance(attacker.transform.position, entity.transform.position); AddDistance(attacker, CTypes.PVPKill, (int)distance); if (info.isHeadshot && configData.ActiveChallengeTypes[CTypes.Headshots.ToString()]) { AddPoints(attacker, CTypes.Headshots, 1); } var weapon = info?.Weapon?.GetItem()?.info?.shortname; if (!string.IsNullOrEmpty(weapon)) { if (bladeShortnames.Contains(weapon) && configData.ActiveChallengeTypes[CTypes.Swords.ToString()]) { AddPoints(attacker, CTypes.Swords, 1); } else if (meleeShortnames.Contains(weapon) && configData.ActiveChallengeTypes[CTypes.Melee.ToString()]) { AddPoints(attacker, CTypes.Melee, 1); } else if (weapon == "bow.hunting" && configData.ActiveChallengeTypes[CTypes.Arrows.ToString()]) { AddPoints(attacker, CTypes.Arrows, 1); } else if (weapon == "pistol.revolver" && configData.ActiveChallengeTypes[CTypes.Revolver.ToString()]) { AddPoints(attacker, CTypes.Revolver, 1); } else if (configData.ActiveChallengeTypes[CTypes.Killed.ToString()]) { AddPoints(attacker, CTypes.Killed, 1); } } } else if (entity.GetComponent <BaseNPC>() != null) { var distance = Vector3.Distance(attacker.transform.position, entity.transform.position); AddDistance(attacker, CTypes.PVEKill, (int)distance); AddPoints(attacker, CTypes.Animals, 1); } } catch { } }
private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { try { float damageScale = 1.0f; var sb = new StringBuilder(); if (entity as BasePlayer == null || hitInfo == null) return; var attackerPlayer = hitInfo.Initiator as BasePlayer; var victimPlayer = entity as BasePlayer; var victimID = victimPlayer.userID.ToString(); var attackerID = attackerPlayer.userID.ToString(); if (lookup.ContainsKey(attackerID) && lookup.ContainsKey(victimID)) { var attackerGov = lookup[attackerID]; var victimGov = lookup[victimID]; if (attackerGov == victimGov) { var attackerRank = attackerGov.Members[attackerID]; var victimRank = victimGov.Members[victimID]; damageScale = damageScaleTable[attackerRank][victimRank]; hitInfo.damageTypes.ScaleAll(damageScale); //sb.Append(attackerID + " attacked " + victimID + // " and caused " + damageScale.ToString() + " damage scale of type " + hitInfo.damageTypes.GetMajorityDamageType().ToString()); } } SendReply(hitInfo.Initiator as BasePlayer, sb.ToString()); } catch (NullReferenceException ex) { } }
void TryCopyLock(BaseCombatEntity lockableEntity, IDictionary<string, object> housedata) { var slotentity = lockableEntity.GetSlot(BaseEntity.Slot.Lock); if (slotentity != null) { if (slotentity.GetComponent<CodeLock>()) { housedata.Add("codelock", codelock.GetValue(slotentity.GetComponent<CodeLock>()).ToString()); } else if (slotentity.GetComponent<KeyLock>()) { var code = (int)keycode.GetValue(slotentity.GetComponent<KeyLock>()); if ((bool)firstKeyCreated.GetValue(slotentity.GetComponent<KeyLock>())) code |= 0x80; housedata.Add("keycode", code.ToString()); } } }
private void OnOtherExitZone(Zone zone, BaseCombatEntity entity) { otherZones[entity]?.Remove(zone); }