private void OnPlayerConnected(PlayerSession session) { if (!players.ContainsKey(session)) { players.Add(session, new PlayerInfo(session)); } }
void OnEntityTakeDamage(BaseEntity entity, HitInfo info) { var victim = entity?.ToPlayer(); var attacker = info?.Initiator?.ToPlayer(); if (victim == null || attacker == null) return; if (victim == attacker) return; if (info.IsProjectile()) return; if (!permission.UserHasPermission(attacker.UserIDString, permMugging)) return; if (permission.UserHasPermission(victim.UserIDString, permProtection)) return; if (InNoLootZone(victim, attacker) || IsFriend(victim, attacker) || IsClanmate(victim, attacker)) return; if (!cooldowns.ContainsKey(attacker.UserIDString)) cooldowns.Add(attacker.UserIDString, 0f); if (usageCooldown != 0 && cooldowns[attacker.UserIDString] + usageCooldown > Interface.Oxide.Now) { PrintToChat(attacker, Lang("Cooldown", attacker.UserIDString)); return; } if (itemStealing) StealItem(victim, attacker); if (moneyStealing) StealMoney(victim, attacker); if (pointStealing) StealPoints(victim, attacker); cooldowns[attacker.UserIDString] = Interface.Oxide.Now; }
Boolean addonday(Action <int> act, String str) { if (!(onday.ContainsKey(str))) { Puts("onday hook added!"); onday[str] = (act); } return(!(onday.ContainsKey(str))); }
private void OnEntityKill(BaseNetworkable networkable) { Signage signage = networkable.GetComponent <Signage>(); if (signage != null) { if (signRegisteredSkulls.ContainsKey(signage)) { signRegisteredSkulls.Remove(signage); } } }
public Panel(Hash <string, object> data) { if (data.ContainsKey(nameof(Image))) { Image = new PanelImage((Hash <string, object>)data[nameof(Image)]); } if (data.ContainsKey(nameof(Text))) { Text = new PanelText((Hash <string, object>)data[nameof(Text)]); } }
private void OnServerInitialized() { permission.RegisterPermission(permDamageProtection, this); permission.RegisterPermission(permLootProtection, this); permission.RegisterPermission(permNoDamageDelay, this); permission.RegisterPermission(permNoLootDelay, this); foreach (BasePlayer sleeper in BasePlayer.sleepingPlayerList) { if (!sleepers.ContainsKey(sleeper.UserIDString)) { sleepers.Add(sleeper.UserIDString, Timestamp); } } }
bool IsAllowed(IPlayer player, string command, string[] args) { // Check if player has permission or is the server console if (!permission.UserHasPermission(player.Id, permUse) && player.Id != "server_console") { // Send not allowed message to player player.Reply(Lang("NotAllowed", player.Id, command)); return(false); } // Check if no arguments are given or if command is "healall" if (args.Length == 0 && command != "healall") { // Send command usage message to player player.Reply(Lang("CommandUsage", player.Id, command)); return(false); } // Check if player doesn't have a cooldown, add if so if (!cooldowns.ContainsKey(player.Id)) { cooldowns.Add(player.Id, 0f); } // Check if player has no cooldown, allow if so if (cooldown == 0 || !(cooldowns[player.Id] + cooldown > Interface.Oxide.Now)) { return(true); } // Send cooldown message to player player.Reply(Lang("Cooldown", player.Id, command)); return(false); }
void OnItemAddedToContainer(ItemContainer container, Item item) { if (container.playerOwner is BasePlayer) { if (onlinePlayers.ContainsKey(container.playerOwner)) { BasePlayer owner = container.playerOwner; if (containers.ContainsKey(container)) { if (SalvageItem(owner, item)) { item.Remove(0f); item.RemoveFromContainer(); } else { ShowNotification(owner, GetMsg("Recycle: Invalid", owner)); if (!owner.inventory.containerMain.IsFull()) { item.MoveToContainer(owner.inventory.containerMain); } else if (!owner.inventory.containerBelt.IsFull()) { item.MoveToContainer(owner.inventory.containerBelt); } } } } } }
void OnPlayerLootEnd(PlayerLoot inventory) { BasePlayer player; if ((player = inventory.GetComponent <BasePlayer> ()) == null) { return; } if (onlinePlayers.ContainsKey(player) && onlinePlayers [player].View != null) { if (onlinePlayers [player].View == inventory.entitySource) { CloseBank(player, (StorageContainer)inventory.entitySource); } } }
void OnPlayerDisconnected(BasePlayer player, string reason) { if (XPToAddTimers.ContainsKey(player)) { XPToAddTimers[player].Destroy(); } XPToAddTimers[player].Destroy(); Timers[player].Destroy(); Timers.Remove(player); }
private void UnregisterPanel(PanelRegistration panel) { if (!_registeredPanels.ContainsKey(panel.Name)) { return; } _registeredPanels.Remove(panel.Name); string panelUiName = GetPanelUiName(panel.Name); foreach (BasePlayer player in BasePlayer.activePlayerList) { CuiHelper.DestroyUi(player, panelUiName); } _hiddenPanels[panel.Name] = null; RecalculatePositions(panel.Dock); DrawDock(BasePlayer.activePlayerList); }
void ResetPlayer(string id) { if (posTimer.ContainsKey(id)) { posTimer[id].Destroy(); posTimer.Remove(id); } if (lastPosition.ContainsKey(id)) { lastPosition.Remove(id); } }
void ResetPlayer(string userId) { if (afkTimer.ContainsKey(userId)) { afkTimer[userId].Destroy(); afkTimer.Remove(userId); } if (lastPosition.ContainsKey(userId)) { lastPosition.Remove(userId); } }
public void AddPlayed(string eventType, string eventName) { if (!gamesPlayed.ContainsKey($"({eventType}) {eventName}")) { gamesPlayed.Add($"({eventType}) {eventName}", 1); } else { gamesPlayed[$"({eventType}) {eventName}"] += 1; } CalculateScore(); }
void UpdateSleepers() { foreach (var sleeper in BasePlayer.sleepingPlayerList) { if (!sleepers.ContainsKey(sleeper.UserIDString)) { sleepers.Add(sleeper.UserIDString, Timestamp); } else { sleepers.Remove(sleeper.UserIDString); } } }
private void AddDependency(CompilablePlugin plugin) { if (plugin.IsLoading || plugins.Contains(plugin) || queuedPlugins.Contains(plugin)) { return; } var compiledDependency = plugin.CompiledAssembly; if (compiledDependency != null && !compiledDependency.IsOutdated()) { // The dependency already has a compiled assembly which is up to date referencedPlugins.Add(plugin.Name); if (!references.ContainsKey(compiledDependency.Name)) { references[compiledDependency.Name] = new CompilerFile(compiledDependency.Name, compiledDependency.RawAssembly); } } else { // The dependency needs to be compiled Add(plugin); } }
void SetPlayerData(string userid, string key, Dictionary <string, object> data) { if (!playersData.ContainsKey(userid)) { LoadPlayer(userid); } Dictionary <string, Dictionary <string, object> > profile = playersData[userid]; if (!profile.ContainsKey(key)) { profile.Add(key, data); } else { profile[key] = data; } playersData[userid] = profile; if (!changedPlayersData.Contains(userid)) { changedPlayersData.Add(userid); } }
void SlapCommand(IPlayer player, string command, string[] args) { if (!player.HasPermission(permUse)) { player.Reply(Lang("NotAllowed", player.Id, command)); return; } if (args.Length == 0) { player.Reply(Lang("CommandUsage", player.Id, command)); return; } if (player.Id != "server_console") { if (!cooldowns.ContainsKey(player.Id)) { cooldowns.Add(player.Id, 0f); } if (cooldown != 0 && cooldowns[player.Id] + cooldown > Interface.Oxide.Now) { player.Reply(Lang("Cooldown", player.Id)); return; } } var target = players.FindPlayer(args[0]); if (target == null || !target.IsConnected) { player.Reply(Lang("PlayerNotFound", player.Id, args[0])); return; } timer.Repeat(0.6f, args.Length == 2 ? Convert.ToInt32(args[1]) : 1, () => SlapPlayer(target)); if (!target.Equals(player)) { player.Reply(Lang("PlayerSlapped", player.Id, target.Name.Sanitize())); } target.Message(slappedBy ? Lang("YouGotSlappedBy", target.Id, player.Name.Sanitize()) : Lang("YouGotSlapped", target.Id)); cooldowns[player.Id] = Interface.Oxide.Now; }
private UiPosition GetDockUiPosition(DockPosition pos, string dockName) { float startPos = 0f; float endPos = 0f; if (_panelPositions.ContainsKey(dockName)) { DockData dock = _pluginConfig.Docks[dockName]; ICollection <float> panels = _panelPositions[dockName].Values; if (panels.Count != 0) { startPos = panels.Min(pp => pp) - dock.DockPadding.Left; endPos = panels.Max(pp => pp) + dock.DockPadding.Right; endPos += _registeredPanels.Values.Where(p => p.Dock == dockName).OrderBy(p => p.Order).Last()?.Width ?? 0; } } return(new UiPosition(startPos, pos.StartYPos, endPos - startPos, pos.Height)); }
private void PopupMessage(BasePlayer player, string msg) { var element = UI.CreateElementContainer(UIPopup, UI.Color("#2a2a2a", 0.98f), "0.33 0.45", "0.67 0.6"); UI.CreatePanel(ref element, UIPopup, UI.Color("#696969", 0.4f), "0.01 0.04", "0.99 0.96"); UI.CreateLabel(ref element, UIPopup, $"{UI.Color("#2a2a2a", 0.9f)}{msg}</color>", 22, "0 0", "1 1"); if (popupMessages.ContainsKey(player.userID)) { CuiHelper.DestroyUi(player, UIPopup); popupMessages[player.userID].Destroy(); popupMessages.Remove(player.userID); } CuiHelper.AddUi(player, element); popupMessages.Add(player.userID, timer.In(3.5f, () => { CuiHelper.DestroyUi(player, UIPopup); popupMessages.Remove(player.userID); })); }
private void DispenserRate(ConsoleSystem.Arg arg) { if (arg.Player() != null && !arg.Player().IsAdmin) { arg.ReplyWith(NotAllowed); return; } if (!arg.HasArgs(2)) { arg.ReplyWith(InvalidArgumentsDispenser); return; } if (!validDispensers.ContainsKey(arg.GetString(0).ToLower())) { arg.ReplyWith(string.Format(InvalidDispenser, arg.GetString(0))); return; } var dispenser = validDispensers[arg.GetString(0).ToLower()].ToString("G"); var modifier = arg.GetFloat(1, -1); if (modifier < 0) { arg.ReplyWith(InvalidModifier); return; } if (GatherDispenserModifiers.ContainsKey(dispenser)) { GatherDispenserModifiers[dispenser] = modifier; } else { GatherDispenserModifiers.Add(dispenser, modifier); } SetConfigValue("Options", "GatherDispenserModifiers", GatherDispenserModifiers); arg.ReplyWith(string.Format(ModifyDispenser, dispenser, modifier)); }
//SKIP void Init() { storedData = Interface.GetMod().DataFileSystem.ReadObject <StoredData>("DateCore"); foreach (BasePlayer ply in BasePlayer.activePlayerList) { if (!Timers.ContainsKey(ply)) { Timer tm = timer.Repeat(5f, 0, () => { String msg = "Current serverdate(rust-days): " + storedData.rustdayyear + "(" + storedData.rustdaystr + ") - " + storedData.rustmonth + "(" + storedData.rustmonthstring + ") - " + storedData.rustyear; DestroyGui(ply); LoadMsgGui(msg, ply); }); Timers.Add(ply, tm); } } Puts("##DateCore##"); Puts("Initiating cores and registering timers"); Load(); timer.Repeat(1, 0, () => { try { if (storedData.day == 0) { if (Math.Floor(TOD_Sky.Instance.Cycle.Hour) == 12) { storedData.day = 1; storedData.rustday = storedData.rustday + 1; storedData.rustdayyear = storedData.rustdayyear + 1; storedData.rustdayweek = storedData.rustdayweek + 1; rustday(); decimal dec = storedData.rustday / 7; storedData.rustweek = int.Parse(Math.Floor(dec).ToString()); if (storedData.rustdayweek == 8) { storedData.rustdayweek = 1; } if (storedData.rustdayweek == 1) { storedData.rustdaystr = "Monday"; } if (storedData.rustdayweek == 2) { storedData.rustdaystr = "Tuesday"; } if (storedData.rustdayweek == 3) { storedData.rustdaystr = "Wednesday"; } if (storedData.rustdayweek == 4) { storedData.rustdaystr = "Thursday"; } if (storedData.rustdayweek == 5) { storedData.rustdaystr = "Friday"; } if (storedData.rustdayweek == 6) { storedData.rustdaystr = "Saturday"; } if (storedData.rustdayweek == 7) { storedData.rustdaystr = "Sunday"; } if (storedData.rustdayyear == 365) { storedData.rustdayyear = 0; storedData.rustyear = storedData.rustyear + 1; rustyear(); } if ((storedData.rustyear / 4).ToString().Contains(".") == false) { if (storedData.rustdayyear == 0) { storedData.rustmonthstring = Months[0]; storedData.rustmonth = 1; rustmonth(); } if (storedData.rustdayyear - 31 + 1 == 1) { storedData.rustmonthstring = Months[1]; storedData.rustmonth = 2; rustmonth(); } if (storedData.rustdayyear - 31 - 28 + 1 == 1) { storedData.rustmonthstring = Months[2]; storedData.rustmonth = 3; rustmonth(); } if (storedData.rustdayyear - 31 - 28 - 31 + 1 == 1) { storedData.rustmonthstring = Months[3]; storedData.rustmonth = 4; rustmonth(); } if (storedData.rustdayyear - 31 - 28 - 31 - 30 + 1 == 1) { storedData.rustmonthstring = Months[4]; storedData.rustmonth = 5; rustmonth(); } if (storedData.rustdayyear - 31 - 28 - 31 - 30 - 31 + 1 == 1) { storedData.rustmonthstring = Months[5]; storedData.rustmonth = 6; rustmonth(); } if (storedData.rustdayyear - 31 - 28 - 31 - 30 - 31 - 30 + 1 == 1) { storedData.rustmonthstring = Months[6]; storedData.rustmonth = 7; rustmonth(); } if (storedData.rustdayyear - 31 - 28 - 31 - 30 - 31 - 30 - 31 + 1 == 1) { storedData.rustmonthstring = Months[7]; storedData.rustmonth = 8; rustmonth(); } if (storedData.rustdayyear - 31 - 28 - 31 - 30 - 31 - 30 - 31 - 31 + 1 == 1) { storedData.rustmonthstring = Months[8]; storedData.rustmonth = 9; rustmonth(); } if (storedData.rustdayyear - 31 - 28 - 31 - 30 - 31 - 30 - 31 - 31 - 30 + 1 == 1) { storedData.rustmonthstring = Months[9]; storedData.rustmonth = 10; rustmonth(); } if (storedData.rustdayyear - 31 - 28 - 31 - 30 - 31 - 30 - 31 - 31 - 30 - 31 + 1 == 1) { storedData.rustmonthstring = Months[10]; storedData.rustmonth = 11; rustmonth(); } if (storedData.rustdayyear - 31 - 28 - 31 - 30 - 31 - 30 - 31 - 31 - 30 - 31 - 30 + 1 == 1) { storedData.rustmonthstring = Months[11]; storedData.rustmonth = 12; rustmonth(); } } else { if (storedData.rustdayyear == 0) { storedData.rustmonthstring = Months[0]; storedData.rustmonth = 1; rustmonth(); } if (storedData.rustdayyear - 31 + 1 == 1) { storedData.rustmonthstring = Months[1]; storedData.rustmonth = 2; rustmonth(); } if (storedData.rustdayyear - 31 - 29 + 1 == 1) { storedData.rustmonthstring = Months[2]; storedData.rustmonth = 3; rustmonth(); } if (storedData.rustdayyear - 31 - 29 - 31 + 1 == 1) { storedData.rustmonthstring = Months[3]; storedData.rustmonth = 4; rustmonth(); } if (storedData.rustdayyear - 31 - 29 - 31 - 30 + 1 == 1) { storedData.rustmonthstring = Months[4]; storedData.rustmonth = 5; rustmonth(); } if (storedData.rustdayyear - 31 - 29 - 31 - 30 - 31 + 1 == 1) { storedData.rustmonthstring = Months[5]; storedData.rustmonth = 6; rustmonth(); } if (storedData.rustdayyear - 31 - 29 - 31 - 30 - 31 - 30 + 1 == 1) { storedData.rustmonthstring = Months[6]; storedData.rustmonth = 7; rustmonth(); } if (storedData.rustdayyear - 31 - 29 - 31 - 30 - 31 - 30 - 31 + 1 == 1) { storedData.rustmonthstring = Months[7]; storedData.rustmonth = 8; rustmonth(); } if (storedData.rustdayyear - 31 - 29 - 31 - 30 - 31 - 30 - 31 - 31 + 1 == 1) { storedData.rustmonthstring = Months[8]; storedData.rustmonth = 9; rustmonth(); } if (storedData.rustdayyear - 31 - 29 - 31 - 30 - 31 - 30 - 31 - 31 - 30 + 1 == 1) { storedData.rustmonthstring = Months[9]; storedData.rustmonth = 10; rustmonth(); } if (storedData.rustdayyear - 31 - 29 - 31 - 30 - 31 - 30 - 31 - 31 - 30 - 31 + 1 == 1) { storedData.rustmonthstring = Months[10]; storedData.rustmonth = 11; rustmonth(); } if (storedData.rustdayyear - 31 - 29 - 31 - 30 - 31 - 30 - 31 - 31 - 30 - 31 - 30 + 1 == 1) { storedData.rustmonthstring = Months[11]; storedData.rustmonth = 12; rustmonth(); } } Interface.GetMod().DataFileSystem.WriteObject <StoredData>("DateCore", storedData); } } else { if (Math.Floor(TOD_Sky.Instance.Cycle.Hour) == 0) { storedData.day = 0; } } Interface.GetMod().DataFileSystem.WriteObject <StoredData>("DateCore", storedData); } catch { } }); Puts("Done bootingup DateCore!"); }
private void HealCommand(IPlayer player, string command, string[] args) { var amount = 0f; if (args.Length > 0) { float.TryParse(args[0], out amount); } if (amount > config.MaxAmount || amount.Equals(0f)) { amount = config.MaxAmount; } IPlayer target; if (args.Length >= 2) { target = FindPlayer(args[1], player); } else if (args.Length == 1) { target = players.FindPlayer(args[0]); } else { target = player; } // TODO: Show message and return if server is trying to heal self if (target == null) { return; } if ((Equals(target, player) && !player.HasPermission(permSelf)) || !player.HasPermission(permOthers)) { Message(player, "NotAllowed", command); return; } if (args.Length == 0 && target.IsServer) { Message(player, "CommandUsage", command); return; } if (target.IsServer || !target.IsConnected) { var name = args.Length >= 2 ? args[1] : args.Length == 1 ? args[0] : ""; Message(player, "PlayerNotFound", name); return; } if (!player.IsServer) { if (!cooldowns.ContainsKey(player.Id)) { cooldowns.Add(player.Id, 0f); } if (config.Cooldown != 0 && cooldowns[player.Id] + config.Cooldown > Interface.Oxide.Now) { Message(player, "Cooldown", command); return; } } if (amount > config.MaxAmount || amount.Equals(0)) { amount = config.MaxAmount; } Heal(target, amount); cooldowns[player.Id] = Interface.Oxide.Now; Message(target, "YouWereHealed", amount); if (!Equals(target, player)) { Message(player, "PlayerWasHealed", target.Name.Sanitize(), amount); } }
private void OnEntityTakeDamage(BaseEntity entity, HitInfo info) { var victim = entity.ToPlayer(); var attacker = info?.Initiator?.ToPlayer(); // Check if victim and attacker are invalid or equal if (victim == null || attacker == null || victim.Equals(attacker)) { return; } // Check if victim or attacker is an NPCPlayer (ie. murderer) if (entity is NPCPlayer || info.Initiator is NPCPlayer) { return; } // Check if victim or attacker is an NPCPlayerApex (ie. scientist) if (entity is NPCPlayerApex || info.Initiator is NPCPlayerApex) { return; } // Check if victim or attacker is a manually spawned BasePlayer if (victim.Connection == null || attacker.Connection == null) { return; } // Make sure player isn't using ranged weapons if (info.IsProjectile()) { return; } // Check if victim is protected from being mugged if (permission.UserHasPermission(victim.UserIDString, permProtection)) { return; } // Check if attacker is allowed to mug if (!permission.UserHasPermission(attacker.UserIDString, permMugging)) { return; } // Check if victim or attacker are in a loot zone, are friends, or share a clan if (InNoLootZone(victim, attacker) || IsFriend(victim, attacker) || IsClanmate(victim, attacker)) { return; } // Check for a cooldown and set one if it doesn't exist if (!cooldowns.ContainsKey(attacker.UserIDString)) { cooldowns.Add(attacker.UserIDString, 0f); } if (config.UsageCooldown != 0 && cooldowns[attacker.UserIDString] + config.UsageCooldown > Interface.Oxide.Now) { Player.Reply(attacker, Lang("Cooldown", attacker.UserIDString)); return; } // Check if config options are enabled for stealing if (config.ItemStealing) { StealItem(victim, attacker); } if (config.MoneyStealing) { StealMoney(victim, attacker); } if (config.PointStealing) { StealPoints(victim, attacker); } // Set time for next cooldown check cooldowns[attacker.UserIDString] = Interface.Oxide.Now; }
private void HealCommand(IPlayer player, string command, string[] args) { float amount; if (args.Length > 0) { float.TryParse(args[0], out amount); } if (amount > maxAmount || amount.Equals(0)) { amount = maxAmount; } IPlayer target; if (args.Length >= 2) { target = players.FindPlayer(args[1]); // TODO: Use FindPlayers and and handle multiple players } else if (args.Length == 1) { target = players.FindPlayer(args[0]); } else { target = player; } if ((Equals(target, player) && !player.HasPermission(permSelf)) || !player.HasPermission(permOthers)) { Reply(player, "NotAllowed", player.Id, command); return; } if (args.Length == 0 && target.Id == "server_console") { Reply(player, "CommandUsage", player.Id, command); return; } if (target.Id == "server_console" || !target.IsConnected) { var name = args.Length >= 2 ? args[1] : args.Length == 1 ? args[0] : ""; Reply(player, "PlayerNotFound", player.Id, name); return; } if (player.Id != "server_console") { if (!cooldowns.ContainsKey(player.Id)) { cooldowns.Add(player.Id, 0f); } if (cooldown != 0 && cooldowns[player.Id] + cooldown > Interface.Oxide.Now) { Reply(player, "Cooldown", player.Id, command); return; } } if (amount > maxAmount || amount.Equals(0)) { amount = maxAmount; } Heal(target, amount); cooldowns[player.Id] = Interface.Oxide.Now; Reply(target, "YouWereHealed", player.Id, amount); // TODO: Only show amount to max health if (!Equals(target, player)) { Reply(player, "PlayerWasHealed", player.Id, target.Name.Sanitize(), amount); } }
bool IsGod(string id) => gods.ContainsKey(id);