private void TeleportHome(BasePlayer player, string name) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null) { return; } // Check if home exists if (!playerHomes[player.userID].ContainsKey(name)) { player.ChatMessage($"<color=#d00>Error</color> the home with the name \"{name}\" does not exists."); return; } // Check for the cooldown int cooldown = pdata.HasCooldown("teleport_home"); if (cooldown > 0) { player.ChatMessage($"<color=#d00>Error</color> teleport cooldown {Helper.TimeFormat.Long(cooldown)}."); return; } TeleportHomeStart(player, playerHomes[player.userID][name], 10); }
public static void AddFriend(BasePlayer player, ulong friendUid, int friendId, Action <int> callback = null) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null) { callback?.Invoke(-1); return; } Database.Query(Database.Build("SELECT * FROM friends WHERE user_id=@0 AND with_user_id=@1 LIMIT 1;", pdata.id, friendId), records => { if (records.Count == 1) { callback?.Invoke(0); return; } if (friends.ContainsKey(player.userID)) { friends[player.userID].Add(friendUid); } else { friends.Add(player.userID, new HashSet <ulong> { friendUid }); } plug.Puts($"[{pdata.id}:{player.UserIDString}] added [{friendId}:{friendUid}] to their friendlist."); Database.Insert(Database.Build("INSERT INTO friends (user_id, with_user_id) VALUES (@0, @1);", pdata.id, friendId), callback); }); }
private void OnChatCommandTpr(BasePlayer player, string command, string[] args) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null) { return; } string syntax = "/tpr \"name\" <color=#999>Requests a teleport to player</color>"; if (args.Length < 1) { player.ChatMessage(syntax); CreateTprUI(player, BasePlayer.activePlayerList); return; } List <BasePlayer> players = Helper.SearchOnlinePlayers(args[0]); if (players.Count == 0) { player.ChatMessage($"<color=#d00>Error</color> no players found."); return; } if (players.Count > 1) { player.ChatMessage($"<color=#d00>Error</color> found multiple players, please be more specific."); return; } TeleportRequest(player, players[0]); }
private void SavePlayer(BasePlayer player, Action callback = null) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null || !skills.ContainsKey(player.userID)) { return; } foreach (var skill in SkillList.all) { Database.Query(Database.Build("SELECT id FROM skills WHERE user_id=@0 AND skill=@1 LIMIT 1;", pdata.id, skill.code), records => { if (records.Count == 0) { Database.Insert(Database.Build("INSERT INTO skills (user_id, skill, level, xp) VALUES (@0, @1, @2, @3);", pdata.id, skill.code, skills[player.userID].GetLevel(skill.code), skills[player.userID].GetXp(skill.code))); } else { Database.NonQuery(Database.Build("UPDATE skills SET level=@0, xp=@1 WHERE user_id=@2 AND skill=@3 LIMIT 1;", skills[player.userID].GetLevel(skill.code), skills[player.userID].GetXp(skill.code), pdata.id, skill.code)); } }); } }
private void BuyItem(BasePlayer player, string key) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null || !items.ContainsKey(key)) { return; } ShopItem item = items[key]; pdata.LoadRewardPoints(points => { if (item.price > points) { UpdateStatusUI(player, "<color=#B70E30>Not enough Reward Points</color> visit https://rust.gamelimits.com/ to buy Reward Points."); return; } pdata.GiveRewardPoints(-item.price, $"Bought {item.name} from the shop", newPoints => { string[] commands = item.command.Split('|'); foreach (string command in commands) { Helper.ExecuteCommand(player, command); } UpdateStatusUI(player, $"<color=#0E84B7>Bought</color> {item.name}"); }); }); }
private void OnConsoleCommandCinfo(ConsoleSystem.Arg arg) { if (arg.Connection == null || arg.Connection.player == null || !arg.HasArgs()) { return; } BasePlayer player = (BasePlayer)arg.Connection.player; PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null) { return; } switch (arg.GetString(0)) { case "close": DestroyUI(player); break; case "page": UpdatePageUI(player, arg.GetString(1, "welcome")); break; case "settings": pdata.SetSetting(arg.GetString(1), arg.GetString(2)); UpdateSettingsUI(player); break; } }
public static void RemoveFriend(BasePlayer player, ulong friendUid, int friendId, Action <int> callback = null) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null) { callback?.Invoke(-1); return; } Database.Query(Database.Build("SELECT * FROM friends WHERE user_id=@0 AND with_user_id=@1 LIMIT 1;", pdata.id, friendId), records => { if (records.Count == 0) { callback?.Invoke(0); return; } if (friends.ContainsKey(player.userID)) { friends[player.userID].Remove(friendUid); } if (friends.ContainsKey(player.userID) && friends[player.userID].Count == 0) { friends.Remove(player.userID); } // Remove from their turrets foreach (AutoTurret turret in UnityEngine.Object.FindObjectsOfType <AutoTurret>()) { if (turret.OwnerID == player.userID) { turret.authorizedPlayers.RemoveAll(u => u.userid == friendUid); } } // Remove from their codelocks foreach (CodeLock codeLock in UnityEngine.Object.FindObjectsOfType <CodeLock>()) { BaseEntity entity = codeLock.GetParentEntity(); if (entity == null || entity.OwnerID != player.userID) { continue; } codeLock.whitelistPlayers.RemoveAll(u => u == friendUid); } plug.Puts($"[{pdata.id}:{player.UserIDString}] removed [{friendId}:{friendUid}] from their friendlist."); Database.Delete(Database.Build("DELETE FROM friends WHERE user_id=@0 AND with_user_id=@1 LIMIT 1;", pdata.id, friendId), callback); }); }
private void TeleportHomeStart(BasePlayer player, Vector3 position, int countdown = 0) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || position == null || pdata == null) { return; } // Check if the teleport from location is valid string teleportFrom = CanTeleportFrom(player); if (teleportFrom != null) { player.ChatMessage($"<color=#d00>Error</color> you cannot teleport from your current location ({teleportFrom})."); return; } // Check if the teleport destination is valid string teleportTo = CanTeleportToPosition(player, position); if (teleportTo != null) { player.ChatMessage($"<color=#d00>Error</color> you cannot teleport to your home ({teleportTo})."); return; } // When there is a countdown timer, intialize a timer and notification timer if (countdown > 0) { Notifications.AddTimedNotification(player, "teleport_home", "Teleport Home", countdown, "0.3 0.3 0.3 1"); timer.Once(countdown, () => TeleportHomeStart(player, position)); return; } // Remove the notification timer Notifications.RemoveTimedNotification(player, "teleport_home"); // Set the cooldown for the teleport int cooldownDuration = 60 * 20; if (Helper.HasMinimumVipRank(pdata, "vip")) { cooldownDuration = 60 * 5; } // Set the cooldown timer pdata.AddCooldown("teleport_home", cooldownDuration); // Execute the teleportation ExecuteTeleport(player, position); }
private void SavePlayer(BasePlayer player) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null || !timeInfo.ContainsKey(player.userID)) { return; } TimeInfo ti = timeInfo[player.userID]; Database.NonQuery(Database.Build("UPDATE users SET playtime=@0, afktime=@1, rewardtime=@2 WHERE id=@3 LIMIT 1;", ti.playTime, ti.afkTime, ti.rewardTime, pdata.id)); }
public static void GetFriends(BasePlayer player, Action <List <FriendItem> > callback, bool includeNonFriends = false) { PlayerData.PData pdata = PlayerData.Get(player); List <FriendItem> friendList = new List <FriendItem>(); if (player == null || pdata == null) { callback?.Invoke(friendList); return; } Database.Query(Database.Build("SELECT users.display_name AS display_name, users.steam_id AS uid FROM friends LEFT JOIN users ON friends.with_user_id = users.id WHERE friends.user_id = @0;", pdata.id), records => { foreach (var record in records) { ulong uid = Convert.ToUInt64(record["uid"]); friendList.Add(new FriendItem() { userId = uid, displayName = Convert.ToString(record["display_name"]), isFriend = true, isOnline = PlayerData.datas.ContainsKey(uid), }); } if (includeNonFriends) { foreach (BasePlayer p in BasePlayer.activePlayerList) { if (p != null && p != player && !HasFriend(player.userID, p.userID)) { friendList.Add(new FriendItem() { userId = p.userID, displayName = p.displayName, isFriend = false, isOnline = false, }); } } } callback?.Invoke(friendList); }); }
private void AddHome(BasePlayer player, string name) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null) { return; } if (playerHomes[player.userID].ContainsKey(name)) { player.ChatMessage($"<color=#d00>Error</color> the home with the name \"{name}\" already exists."); return; } string teleportFrom = CanTeleportFrom(player); if (teleportFrom != null) { player.ChatMessage($"<color=#d00>Error</color> cannot create homepoint ({teleportFrom})."); return; } if (!Helper.HasMinimumVipRank(pdata, "vip") && playerHomes[player.userID].Count >= 1) { player.ChatMessage($"<color=#d00>Error</color> unable to set your home here, you have reached the maximum of 1 home!"); return; } else if (Helper.HasMinimumVipRank(pdata, "vip") && playerHomes[player.userID].Count >= 3) { player.ChatMessage($"<color=#d00>Error</color> unable to set your home here, you have reached the maximum of 3 homes!"); return; } playerHomes[player.userID].Add(name, player.transform.position); Database.Insert(Database.Build("INSERT INTO homes (user_id, name, x, y, z) VALUES (@0, @1, @2, @3, @4);", pdata.id, name, player.transform.position.x, player.transform.position.y, player.transform.position.z)); player.ChatMessage($"Your home \"{name}\" has been added."); }
private void OnChatCommandAdmin(BasePlayer player, string command, string[] args) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null || !pdata.admin) { return; } if (adminEnabled.Contains(player)) { StopAdmin(player); } else { StartAdmin(player); } }
private void LoadPlayer(BasePlayer player) { if (player == null) { return; } PlayerData.PData pdata = PlayerData.Get(player); if (pdata == null) { Puts($"Loading for [{player.UserIDString}] has been delayed, waiting for the PlayerData plugin"); timer.Once(1f, () => LoadPlayer(player)); return; } // Remove the old homes first UnloadPlayer(player); Database.Query(Database.Build("SELECT * FROM skills WHERE user_id = @0;", pdata.id), records => { PlayerSkill pskill = new PlayerSkill(); string info = $"Player skills for [{pdata.id}:{player.UserIDString}]:\n"; foreach (var record in records) { string skill = Convert.ToString(record["skill"]); int xp = Convert.ToInt32(record["xp"]); int level = Convert.ToInt32(record["level"]); pskill.SetLevel(skill, level); pskill.SetXp(skill, xp); info += $"{skill}: Lv. {level} / Xp. {xp}\n"; } skills.Add(player.userID, pskill); // Puts(info.TrimEnd('\n')); CreateUI(player); }); }
public void UpdateStatusUI(BasePlayer player, string message) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null) { return; } Helper.UI.Destroy(player, "ui_shop_status"); CuiElementContainer container = Helper.UI.Container("ui_shop_status", "1 1 1 0.01", "0 0", "0.999 0.04", false, "ui_shop"); Helper.UI.Label(ref container, "ui_shop_status", "1 1 1 1", $"You have <color=#0E84B7>{pdata.rewardPoints}</color> Reward Points", 12, "0.01 0", "1 1", TextAnchor.MiddleLeft); Helper.UI.Label(ref container, "ui_shop_status", "1 1 1 1", message, 12, "0 0", "0.99 1", TextAnchor.MiddleRight); Helper.UI.Add(player, container); }
private void Tick() { foreach (BasePlayer player in BasePlayer.activePlayerList) { if (player == null || !timeInfo.ContainsKey(player.userID) || PlayerData.Get(player) == null) { continue; } TimeInfo ti = timeInfo[player.userID]; // Update the time int time = Helper.Timestamp(); int diffTime = time - ti.lastTime; ti.lastTime = time; // Update the position Vector3 position = player.transform.position; Vector3 diffPosition = position - ti.lastPosition; ti.lastPosition = position; // Apply the tick times if (diffPosition.magnitude > 0.5f) { ti.playTime += diffTime; } else { ti.afkTime += diffTime; } if ((ti.playTime + ti.afkTime) - ti.rewardTime > ti.rewardInterval) { ti.rewardTime = (ti.playTime + ti.afkTime); Reward(player); } SavePlayer(player); } timer.Once(60f, () => Tick()); }
private void CreateUI(BasePlayer player, CarController controller) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null || pdata.displayCarHud == false) { return; } DestroyUI(player); // Create the main container CuiElementContainer container = Helper.UI.Container("ui_car", "0 0 0 .5", "0.01 0.06", "0.24 0.09"); // Display the container Helper.UI.Add(player, container); UpdateUI(player, controller); //CuiElementContainer container2 = Helper.UI.Container("ui_car2", "1 0 0 .99", "0.01 0.02", "0.25 0.05"); // REFERENCE //Helper.UI.Add(player, container2); }
private void DeleteHome(BasePlayer player, string name) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null) { return; } if (!playerHomes[player.userID].ContainsKey(name)) { player.ChatMessage($"<color=#d00>Error</color> the home with the name \"{name}\" doest not exists."); return; } playerHomes[player.userID].Remove(name); Database.Delete(Database.Build("DELETE FROM homes WHERE user_id=@0 AND name=@1 LIMIT 1;", pdata.id, name)); player.ChatMessage($"Your home \"{name}\" has been removed."); }
private void UpdateUI(BasePlayer player, CarController controller) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null || pdata.displayCarHud == false) { return; } Helper.UI.Destroy(player, "ui_car_container"); CuiElementContainer container = Helper.UI.Container("ui_car_container", "0 0 0 .5", "0 0.005", "1 0.94", false, "ui_car"); Helper.UI.Label(ref container, "ui_car_container", "1 1 1 1", "Health", 12, "0.02 0", "1 1", TextAnchor.MiddleLeft); // Health Helper.UI.Panel(ref container, "ui_car_container", "0.57 0.21 0.11 1", "0.2 0.25", "0.98 0.75", false, "ui_car_container_hp"); Helper.UI.Panel(ref container, "ui_car_container_hp", "0.41 0.5 0.25 1", "0 0", (controller.car.health / controller.car.MaxHealth()) + " 0.92"); Helper.UI.Add(player, container); }
private object OnPlayerChat(ConsoleSystem.Arg args) { BasePlayer player = (BasePlayer)args.Connection.player; PlayerData.PData pdata = PlayerData.Get(player); if (player == null) { return(null); } // The player data has to be loaded in order to send chat messages if (pdata == null) { player.ChatMessage("<color=#D00>Error</color> chat muted until your player data has been loaded!"); return(false); } // Player tags string tags = ""; if (Helper.HasMinimumVipRank(pdata, "vip")) { tags += "<color=#88B71B>[VIP]</color> "; } // Compose the player message string message = string.Join(" ", args.Args); // Broadcast to ingame chat BroadcastChat($"{tags}<color=#32AADD>{player.displayName}</color> {message}", player.userID); // Broadcast to server console Puts($"[ingame] [{player.displayName}] {message}"); // Store the chatmessage into the database Database.Insert(Database.Build("INSERT INTO chatlogs (user_id, display_name, message) VALUES (@0, @1, @2);", pdata.id, player.displayName, message)); return(false); }
private static void UpdatePlayer(BasePlayer player, bool force = false) { if (force) { Helper.UI.Destroy(player, "ui_notifications_times"); } if (timedNotifications.ContainsKey(player)) { if (!force) { Helper.UI.Destroy(player, "ui_notifications_times"); } PlayerData.PData pdata = PlayerData.Get(player); int currentTimestamp = Helper.Timestamp(); if (pdata.displayTimedNotifications) { // Render notifications CuiElementContainer container = Helper.UI.Container("ui_notifications_times", "0 0 0 0", "0.85 0.4", "0.990 0.85", false, "Hud"); int index = 0; foreach (var notification in timedNotifications[player]) { BuildNotificationBlock(ref container, index++, notification.Value); } Helper.UI.Add(player, container); } // Remove expired timers foreach (var notification in timedNotifications[player].Where(k => k.Value.expires <= currentTimestamp).ToList()) { timedNotifications[player].Remove(notification.Key); } } }
private void LoadPlayer(BasePlayer player) { if (player == null) { return; } PlayerData.PData pdata = PlayerData.Get(player); if (pdata == null) { Puts($"Loading for [{player.UserIDString}] has been delayed, waiting for the PlayerData plugin"); timer.Once(1f, () => LoadPlayer(player)); return; } // Remove the old data first UnloadPlayer(player); Database.Query(Database.Build("SELECT * FROM users WHERE id = @0 LIMIT 1;", pdata.id), records => { if (records.Count == 0) { Puts($"Could not load the player times for [{pdata.id}:{player.UserIDString}]"); return; } timeInfo.Add(player.userID, new TimeInfo() { playTime = Convert.ToInt32(records[0]["playtime"]), afkTime = Convert.ToInt32(records[0]["afktime"]), rewardTime = Convert.ToInt32(records[0]["rewardtime"]), lastTime = Helper.Timestamp(), lastPosition = player.transform.position, }); Puts($"Loaded [{pdata.id}:{player.UserIDString}] playtime: {Helper.TimeFormat.Short(Convert.ToInt32(records[0]["playtime"]))}, afktime: {Helper.TimeFormat.Short(Convert.ToInt32(records[0]["afktime"]))}"); }); }
private void UpdateUI(BasePlayer player, Skill skill) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null || !skills.ContainsKey(player.userID)) { return; } int percent = GetExperiencePercent(player, skill); int level = (int)skills[player.userID].GetLevel(skill.code); string panel = $"ui_skills_{skill.code}"; var val = 1 / (float)SkillList.all.Length; var min = 1 - (val * skill.index) + .017; var max = 2 - (1 - (val * (1 - skill.index))) - .017; Helper.UI.Destroy(player, panel); CuiElementContainer container = Helper.UI.Container(panel, "0.8 0.8 0.8 0.03", "0 " + min.ToString("0.####"), "1 " + max.ToString("0.####"), false, "ui_skills"); // XP Bar Helper.UI.Panel(ref container, panel, "0.2 0.2 0.2 0.3", "0.235 0.12", "0.97 0.85", false, $"{panel}_bar"); // XP Bar Progression Helper.UI.Panel(ref container, $"{panel}_bar", skill.color, "0 0", (percent / 100.0) + " 0.95"); // XP Bar Text Helper.UI.Label(ref container, $"{panel}_bar", "0.74 0.76 0.78 1", skill.name, 11, "0.05 0", "1 1"); // XP Bar Percent Helper.UI.Label(ref container, $"{panel}_bar", "0.74 0.76 0.78 1", $"{percent}%", 10, "0.025 0", "1 1", TextAnchor.MiddleRight); // Level Helper.UI.Label(ref container, panel, "0.74 0.76 0.78 1", $"Lv. {level}", 11, "0.025 0", "1.5 1", TextAnchor.MiddleLeft); Helper.UI.Add(player, container); }
private void TeleportRequestAccept(BasePlayer player) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null) { return; } TPR tpr = FindTPR(null, player); // Check if there are any pending requests if (tpr == null) { player.ChatMessage($"<color=#d00>Error</color> there are no pending requests."); return; } TeleportRequestStart(tpr.player, tpr.target, 10); pendingTeleportRequests.Remove(tpr); }
private void LoadPlayerHomes(BasePlayer player) { if (player == null) { return; } PlayerData.PData pdata = PlayerData.Get(player); if (pdata == null) { Puts($"Loading homes for [{player.UserIDString}] has been delayed, waiting for the PlayerData plugin"); timer.Once(1f, () => LoadPlayerHomes(player)); return; } // Remove the old homes first UnloadPlayerHomes(player); Database.Query(Database.Build("SELECT * FROM homes WHERE user_id = @0;", pdata.id), records => { Dictionary <string, Vector3> homes = new Dictionary <string, Vector3>(); foreach (var record in records) { homes.Add(Convert.ToString(record["name"]), new Vector3( Convert.ToSingle(record["x"]), Convert.ToSingle(record["y"]), Convert.ToSingle(record["z"]))); } playerHomes.Add(player.userID, homes); Puts($"Loaded {records.Count} home(s) for [{pdata.id}:{player.UserIDString}]"); }); }
private void Reward(BasePlayer player) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null || !timeInfo.ContainsKey(player.userID)) { return; } int rewardPoints = 2; if (Helper.HasMinimumVipRank(pdata, "vip")) { rewardPoints = 10; } pdata.GiveRewardPoints(rewardPoints, $"You have been rewarded {rewardPoints} RP for playing on this server.", points => { player.ChatMessage($"You have been rewarded <color=#0E84B7>{rewardPoints} RP</color> for playing on this server.\n" + $"You have <color=#0E84B7>{points} Reward Points (RP)</color>. Type /s to spend them in the shop"); Puts($"[{pdata.id}:{player.UserIDString}] has been rewarded {rewardPoints} RP for playing on this server (total: {points} RP)"); }); }
private void OnConsoleCommand(ConsoleSystem.Arg arg) { if (arg.Connection == null || arg.Connection.player == null || !arg.HasArgs()) { return; } BasePlayer player = (BasePlayer)arg.Connection.player; PlayerData.PData pdata = PlayerData.Get(player); if (pdata == null) { return; } switch (arg.GetString(0)) { case "index": GetFriends(player, players => UpdateUI(player, players, arg.GetInt(1)), true); break; case "close": DestroyUI(player); break; case "add": DestroyUI(player); Database.Query(Database.Build("SELECT * FROM users WHERE steam_id=@0 LIMIT 1;", arg.GetUInt64(1)), records => { if (records.Count == 0) { return; } int foundUser = Convert.ToInt32(records[0]["id"]); ulong foundUserId = Convert.ToUInt64(records[0]["steam_id"]); if (foundUser == pdata.id) { player.ChatMessage("You cannot add yourself to your friendlist."); return; } AddFriend(player, foundUserId, foundUser, result => { if (result > 0) { player.ChatMessage($"{records[0]["display_name"]} added to your friendlist."); } else if (result == 0) { player.ChatMessage($"{records[0]["display_name"]} is already in your friends list."); } else { player.ChatMessage($"Something went wrong (error code: {result})"); } }); }); break; case "remove": DestroyUI(player); Database.Query(Database.Build("SELECT * FROM users WHERE steam_id=@0 LIMIT 1;", arg.GetUInt64(1)), records => { if (records.Count == 0) { return; } int foundUser = Convert.ToInt32(records[0]["id"]); ulong foundUserId = Convert.ToUInt64(records[0]["steam_id"]); if (foundUser == pdata.id) { player.ChatMessage("You cannot remove yourself from your friendlist."); return; } RemoveFriend(player, foundUserId, foundUser, result => { if (result > 0) { player.ChatMessage($"{records[0]["display_name"]} removed from your friendlist."); } else if (result == 0) { player.ChatMessage($"{records[0]["display_name"]} is not in your friendlist."); } else { player.ChatMessage($"Something went wrong (error code: {result})"); } }); }); break; } }
private void OnChatCommandFriend(BasePlayer player, string command, string[] args) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || pdata == null) { return; } // Check the syntax string syntax = "/friend list <color=#999>Shows a list of your friends</color>\n" + "/friend add \"name\" <color=#999>Add a friend to your friendlist</color>\n" + "/friend remove \"name\" <color=#999>Removes a friend from your friendlist</color>"; if (args.Length < 1 || args.Length == 1 && !(args[0].ToLower() == "list")) { GetFriends(player, players => CreateUI(player, players), true); SendReply(player, syntax); return; } switch (args[0].ToLower()) { case "list": Database.Query(Database.Build("SELECT users.display_name AS display_name, users.steam_id AS uid FROM friends LEFT JOIN users ON friends.with_user_id = users.id WHERE friends.user_id = @0;", pdata.id), records => { if (records.Count == 0) { player.ChatMessage("You dont have any friends, you can add them with /friend add \"name\""); return; } string list = ""; foreach (var record in records) { ulong uid = Convert.ToUInt64(record["uid"]); if (PlayerData.Get(uid) == null) { list += $"- {record["display_name"]} <color=#999>(offline)</color>\n"; } else { list += $"- {record["display_name"]} <color=#0D0>(online)</color>\n"; } } player.ChatMessage(list.TrimEnd('\n')); }); break; case "add": Database.Query(Database.Build("SELECT * FROM users WHERE display_name LIKE @0;", $"%{args[1]}%"), records => { if (records.Count == 0) { player.ChatMessage("Player \"{args[1]}\" not found"); return; } if (records.Count > 1) { player.ChatMessage($"Found multiple players with \"{args[1]}\", please be more specific."); return; } int foundUser = Convert.ToInt32(records[0]["id"]); ulong foundUserId = Convert.ToUInt64(records[0]["steam_id"]); if (foundUser == pdata.id) { player.ChatMessage("You cannot add yourself to your friendlist."); return; } AddFriend(player, foundUserId, foundUser, result => { if (result > 0) { player.ChatMessage($"{records[0]["display_name"]} added to your friendlist."); } else if (result == 0) { player.ChatMessage($"{records[0]["display_name"]} is already in your friends list."); } else { player.ChatMessage($"Something went wrong (error code: {result})"); } }); }); break; case "remove": Database.Query(Database.Build("SELECT * FROM users WHERE display_name LIKE @0;", $"%{args[1]}%"), records => { if (records.Count == 0) { player.ChatMessage("Player \"{args[1]}\" not found"); return; } if (records.Count > 1) { player.ChatMessage($"Found multiple players with \"{args[1]}\", please be more specific."); return; } int foundUser = Convert.ToInt32(records[0]["id"]); ulong foundUserId = Convert.ToUInt64(records[0]["steam_id"]); if (foundUser == pdata.id) { player.ChatMessage("You cannot remove yourself from your friendlist."); return; } RemoveFriend(player, foundUserId, foundUser, result => { if (result > 0) { player.ChatMessage($"{records[0]["display_name"]} removed from your friendlist."); } else if (result == 0) { player.ChatMessage($"{records[0]["display_name"]} is not in your friendlist."); } else { player.ChatMessage($"Something went wrong (error code: {result})"); } }); }); break; default: player.ChatMessage(syntax); break; } }
private void TeleportRequestStart(BasePlayer player, BasePlayer target, int countdown = 0) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || target == null || pdata == null) { return; } // Check if the player can teleport from the current location string canTeleportFrom = CanTeleportFrom(player); if (canTeleportFrom != null) { player.ChatMessage($"<color=#d00>Error</color> you cannot teleport from your current location ({canTeleportFrom})."); return; } // Check if the player can teleport to the target location string canTeleportToPosition = CanTeleportToPosition(player, target.transform.position); if (canTeleportToPosition != null) { player.ChatMessage($"<color=#d00>Error</color> you cannot teleport to {target.displayName} ({canTeleportFrom})."); return; } // Check if the player can teleport to the target itself string canTeleportToPlayer = CanTeleportToPlayer(player, target, false); if (canTeleportToPlayer != null) { player.ChatMessage($"<color=#d00>Error</color> you cannot teleport to {target.displayName} ({canTeleportToPlayer})."); return; } // When there is a countdown timer, intialize a timer and notification timer if (countdown > 0) { Notifications.AddTimedNotification(player, "teleport_tpr", "Teleporting", countdown, "0.3 0.3 0.3 1"); Notifications.AddTimedNotification(target, "teleport_tpr", "Teleporting", countdown, "0.3 0.3 0.3 1"); timer.Once(countdown, () => TeleportRequestStart(player, target)); return; } // Remove the notification timer Notifications.RemoveTimedNotification(player, "teleport_tpr"); Notifications.RemoveTimedNotification(target, "teleport_tpr"); // Set the cooldown for the teleport int cooldownDuration = 60 * 20; if (Helper.HasMinimumVipRank(pdata, "vip")) { cooldownDuration = 60 * 5; } // Set the cooldown timer pdata.AddCooldown("teleport_tpr", cooldownDuration); // Execute the teleportation ExecuteTeleport(player, target.transform.position); }
private void TeleportRequest(BasePlayer player, BasePlayer target) { PlayerData.PData pdata = PlayerData.Get(player); if (player == null || target == null || pdata == null) { return; } // Check for the cooldown int cooldown = pdata.HasCooldown("teleport_tpr"); if (cooldown > 0) { player.ChatMessage($"<color=#d00>Error</color> teleport to player cooldown {Helper.TimeFormat.Long(cooldown)}."); return; } // Check if the player can teleport from the current location string canTeleportFrom = CanTeleportFrom(player); if (canTeleportFrom != null) { player.ChatMessage($"<color=#d00>Error</color> you cannot teleport from your current location ({canTeleportFrom})."); return; } // Check if the player can teleport to the target location string canTeleportToPosition = CanTeleportToPosition(player, target.transform.position); if (canTeleportToPosition != null) { player.ChatMessage($"<color=#d00>Error</color> you cannot teleport to {target.displayName} ({canTeleportFrom})."); return; } // Check if the player can teleport to the target itself string canTeleportToPlayer = CanTeleportToPlayer(player, target); if (canTeleportToPlayer != null) { player.ChatMessage($"<color=#d00>Error</color> you cannot teleport to {target.displayName} ({canTeleportToPlayer})."); return; } player.ChatMessage($"Teleport request sent to {target.displayName}. Type /tpc to cancel the teleport request."); target.ChatMessage($"Teleport request from {player.displayName}. Type /tpa to accept the teleport request. Or type /tpc to cancel the teleport request."); pendingTeleportRequests.Add(new TPR() { player = player, target = target, }); timer.Once(30f, () => { TPR tpr = FindTPR(player, target); if (tpr != null) { if (tpr.player != null) { player.ChatMessage($"Teleport request timed out."); } if (tpr.target != null) { target.ChatMessage($"Teleport request timed out."); } pendingTeleportRequests.Remove(tpr); } }); }
private void OnChatCommandHome(BasePlayer player, string command, string[] args) { if (player == null || PlayerData.Get(player) == null) { return; } string syntax = "/home \"name\" <color=#999>Start the teleport to your home</color>\n" + "/home list <color=#999>Shows a list of your homes</color>\n" + "/home add \"name\" <color=#999>Add a home to your homelist</color>\n" + "/home remove \"name\" <color=#999>Removes a home from your homelist</color>"; if (args.Length < 1) { CreateHomeUI(player); player.ChatMessage(syntax); return; } switch (args[0]) { case "list": if (playerHomes[player.userID].Count == 0) { player.ChatMessage("You dont have any homes, you can add them with /home add \"name\""); return; } string homeList = "Your home(s):\n"; foreach (var home in playerHomes[player.userID]) { homeList += $" - {home.Key}\n"; } player.ChatMessage(homeList.TrimEnd('\n')); return; case "add": if (args.Length != 2) { player.ChatMessage(syntax); return; } AddHome(player, args[1]); return; case "remove": if (args.Length != 2) { player.ChatMessage(syntax); return; } DeleteHome(player, args[1]); return; } if (args.Length != 1) { player.ChatMessage(syntax); return; } TeleportHome(player, args[0]); }