void AddZone(BasePlayer player, string[] args, Methods method, bool onlyAmount = false, bool hasMethod = true) { Zone zone = new Zone(args[1]); zone.Method = method; int offset = 2; if (onlyAmount) { zone.Amount = int.Parse(args[2]); offset++; } else { if (hasMethod) { offset++; } if (IsDigitsOnly(args[3])) { zone.Amount = int.Parse(args[3]); offset++; } } string cmd = ""; for (int i = offset; i < args.Length; i++) { cmd += args[i] + " "; } zone.Add(cmd.Substring(0, cmd.Length - 1)); data.Add(zone); SaveData(); PrintToChat(player, Lang("Added")); }
// TODO void ExecuteZone(Zone zone, BasePlayer player) { bool addPlayer = false; bool addOne = false; switch (zone.Method) { case Methods.Always: if (zone.Amount != -1) { if (zone.Amount != zone.Players.Count) { addPlayer = true; } else { return; } } break; case Methods.PerPlayer: { if (zone.Amount != -1) { if (zone.Players.Count > 0) { bool found = false; foreach (ZonePlayer zp in zone.Players) { if (zp.UserId == player.userID) { found = true; if (zp.Count == zone.Amount) { return; } else { zp.Count++; } break; } } if (!found) { addPlayer = true; addOne = true; } } else { addPlayer = true; addOne = true; } } else { if (zone.Players.Count > 0) { foreach (ZonePlayer zp in zone.Players) { if (zp.UserId == player.userID) { return; } } addPlayer = true; } else { addPlayer = true; } } } break; case Methods.PerDay: // TODO: per day break; case Methods.PerGameDay: // TODO: per game day break; } if (addPlayer) { zone.Add(new ZonePlayer { UserId = player.userID, Count = addOne ? 1 : 0 }); } foreach (string s in zone.Commands) { string command = s.Replace("$player.id", player.userID.ToString()) .Replace("$player.name", player.displayName) .Replace("$player.xyz", player.transform.position.x + " " + player.transform.position.y + " " + player.transform.position.z) .Replace("$player.x", player.transform.position.x.ToString()) .Replace("$player.y", player.transform.position.y.ToString()) .Replace("$player.z", player.transform.position.z.ToString()); if (command.StartsWith("sayto", StringComparison.CurrentCultureIgnoreCase)) { PrintToChat(player, command.Substring(6)); } rust.RunServerCommand(command); } }