Milkbottle Posted April 30, 2022 Posted April 30, 2022 (edited) Hey, i am new to Ragemp coding and i am trying to get this code to work. At the Moment i need to type /freeze [Player Name] [true/false] but I want that i can type /freeze [ID] [true/false] [Command("freeze", "/freeze a player ")] public void CMD_FreezePlayer(Player player,Player target, bool freezestatus) { Accounts account = player.GetData<Accounts>(Accounts.Account_Key); if (!account.IsPlayerAdmin((int)Accounts.AdminRanks.Supporter)) { player.SendNotification("~r~You are not an Admin"); return; } NAPI.ClientEvent.TriggerClientEvent(target, "PlayerFreeze", freezestatus); string freezeText = (freezestatus) ? "freezed" : "unfreezed"; NAPI.Util.ConsoleOutput(player.Name + " has " + target.Name + " freezed/entfreezed " + freezestatus); } Edited April 30, 2022 by Milkbottle
Kopra Posted May 1, 2022 Posted May 1, 2022 public static Player GetPlayerByNameOrId(string value) { // If value is number, we look in pool by ID if (int.TryParse(value, out int targetId)) { return NAPI.Pools.GetAllPlayers().FirstOrDefault(X => X.Id == targetId); } // If value is not a number, we look by players name else { return NAPI.Pools.GetAllPlayers().FirstOrDefault(X => X.Name.Contains(value)); } } [Command("freeze", "/freeze a player ")] public void CMD_FreezePlayer(Player player, string targetValue, bool freezestatus) { Accounts account = player.GetData<Accounts>(Accounts.Account_Key); if (!account.IsPlayerAdmin((int)Accounts.AdminRanks.Supporter)) { player.SendNotification("~r~You are not an Admin"); return; } Player target = GetPlayerByNameOrId(targetValue); if (target == null) { player.SendNotification("~r~Target not found"); return; } NAPI.ClientEvent.TriggerClientEvent(target, "PlayerFreeze", freezestatus); string freezeText = (freezestatus) ? "freezed" : "unfreezed"; NAPI.Util.ConsoleOutput(player.Name + " has " + target.Name + " freezed/entfreezed " + freezestatus); } This should work, only thing I see here that may be problematic is you may get exception when using INT in argument where it expect string.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now