I have some problems in making the tables.. or sth like that.
My working code looks like:
I wanna do the thing that @Deicide666ra said:Code:using System.Collections.Generic; using System.Reflection; using System; using System.Data; using UnityEngine; using Oxide.Core;namespace Oxide.Plugins { [Info("Mind Freeze", "PaiN", "1.2.0", ResourceId = 1198)] [Description("Allows you to freeze players with a legit way.")] public class MindFreeze : RustPlugin { void Loaded() { if (!permission.PermissionExists("canmindfreeze")) permission.RegisterPermission("canmindfreeze", this); //LoadDefaultConfig(); Maybe gonna add this later. } private Timer timerrepeat; [ChatCommand("freeze")] void cmdFreeze(BasePlayer player, string cmd, string[] args) { string steamId = player.userID.ToString(); if (permission.UserHasPermission(steamId, "canmindfreeze")) { var target = BasePlayer.Find(args[0]); var position = target.transform.position; var configPos = new Vector3(position.x, position.y , position.z); if(Vector3.Distance(target.transform.position, configPos) < 1) { var timerrepeat = timer.Repeat(1, 0, () => target.ClientRPCPlayer(null, target, "ForcePositionTo", new object[] { configPos })); player.TransformChanged(); } } else SendReply(player, "You do not have permission to use this command!"); } [ChatCommand("unfreeze")]//I will find another way to unfreeze but for now i cant think another way to do it. void cmdUnFreeze(BasePlayer player, string command, string[] args) { timerrepeat.Destroy(); } public void Unloaded() { timerrepeat.Destroy(); } }}
If it's the same message you send to everyone, simply have a of targets (List<BasePlayer>()) (global) that you add/remove players to/from. In the timer function loop through them and send the msg.
As its my first time making this thing i do not fully understand his reply.
What i tried:
In void Loaded i added:
but then ?Code:List<BasePlayer> isFreezed = new List<BasePlayer>;
Learning about tables in C#
Discussion in 'Rust Development' started by PaiN, Jul 4, 2015.
-
Make that list global (outside a function)... I would rename the list to frozenPlayers for clarity.
Then you can do:
frozenPlayers.Add(playerIwannaFreeze);
if (frozenPlayers.Contains(playerImLookingFor))
{
// here you know your player is in the list
}
frozenPlayers.Remove(playerIwannaUnfreeze);
If you want to send a message or do an action on all frozen players:
foreach(var player in frozenPlayers)
{
player.ChatMessage("Sup popsicle!");
}
If you want to clear the list:
frozenPlayers.Clear();
Read documentation on List for more info on what you can do. Some of these functions are LINQ (Contains) and there are a ton of other things you can do with LINQ (sort, exclude a list of players, merge lists, etc). -
I just realised that C# is giving some non-sense errors..
So i'm getting errors like "Unexpected symbol "void" " xD after the chatcommand but i get this because of :
Everytime that i move it then it *makes* other lines to give me an error ? Dunno how to explain it..Code:List<BasePlayer> frozenPlayers = new List<BasePlayer>
My code:
Code:using System.Collections.Generic; using System.Reflection; using System; using System.Data; using UnityEngine; using Oxide.Core;namespace Oxide.Plugins { [Info("Mind Freeze", "PaiN", "1.2.0", ResourceId = 1198)] [Description("Allows you to freeze players with a legit way.")] class MindFreeze : RustPlugin { void Loaded() { if (!permission.PermissionExists("canmindfreeze")) permission.RegisterPermission("canmindfreeze", this); //LoadDefaultConfig(); Maybe gonna add this later. } List<BasePlayer> frozenPlayers = new List<BasePlayer> private Timer timerrepeat; [ChatCommand("freeze")] void cmdFreeze(BasePlayer player, string cmd, string[] args) { var target = BasePlayer.Find(args[0]); frozenPlayers.Add(target); if (frozenPlayers.Contains(target)) { var position = target.transform.position; var configPos = new Vector3(position.x, position.y , position.z); if(Vector3.Distance(target.transform.position, configPos) < 1) { var timerrepeat = timer.Repeat(1, 0, () => target.ClientRPCPlayer(null, target, "ForcePositionTo", new object[] { configPos })); target.TransformChanged(); } } } [ChatCommand("unfreeze")] void cmdUnFreeze(BasePlayer player, string command, string[] args) { var target = BasePlayer.Find(args[0]); if (frozenPlayers.Contains(target)) { frozenPlayers.Remove(target); } } [ChatCommand("unfreezeall")] void cmdUnFreezeAll(BasePlayer player, string command, string[] args) { frozenPlayers.Clear(); } void Unloaded() { timerrepeat.Destroy(); frozenPlayers.Clear(); } }} -
Your line wasn't complete, try this:
List<BasePlayer> frozenPlayers =new List<BasePlayer>(); -
Everything works except of http://oxidemod.org/threads/multiline-timers-c.10007/
Last edited by a moderator: Jul 4, 2015
