1. So i want to repeat a multi-line function with a timer. Somehow it doesnt work .. maybe i dont know the proper way.. trying for 20mins to figure it out. in lua it was easier :p

    Code:
            var timerrepeat = timer.Repeat(1, 0, ()
            {
                foreach(BasePlayer current in frozenPlayers)
                { 
                    var position = current.transform.position;
                    var configPos = new Vector3(position.x, position.y , position.z);
                    if(Vector3.Distance(current.transform.position, configPos) < 1)
                    {
                        current.ClientRPCPlayer(null, current, "ForcePositionTo", new object[] { configPos });
                        current.TransformChanged();
                    }
                }
            )
    
     
  2. Code:
    var timerrepeat = timer.Repeat(1, 0, () => {
        foreach(BasePlayer current in frozenPlayers) {
            var position = current.transform.position;
            var configPos = new Vector3(position.x, position.y, position.z);
            if(Vector3.Distance(current.transform.position, configPos) < 1) {
                current.ClientRPCPlayer(null, current, "ForcePositionTo", new object[] { configPos });
                current.TransformChanged();
            }
        }
    });
     
  3. Error:
    http://screenshot.sh/mMdc6MOsyP0Cs

    Code:
    Code:
                timer.Repeat(1, 0, () => {
           
                foreach(BasePlayer current in frozenPlayers) {
               
                    var position = current.transform.position;
                    var configPos = new Vector3(position.x, position.y, position.z);
                    if(Vector3.Distance(current.transform.position, configPos) < 1)
                    {
                   
                    var timer = timer.Repeat(1, 0, () => current.ClientRPCPlayer(null, current, "ForcePositionTo", new object[] { configPos }));
                        current.TransformChanged();
                   
                    }
                }
            });
     
  4. Are you sure that the error is inside this code block? Check the line number
     
  5. yep its the last line that i gave u above
    the "});"
     
  6. The code block that I posted has properly matching brackets, it must be something outside of it affecting it.
     
  7. I will just give u all the 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 timer;
           
            [ChatCommand("freeze")]
            void cmdFreeze(BasePlayer player, string cmd, string[] args)
            {
                var target = BasePlayer.Find(args[0]);
                frozenPlayers.Add(target);
            }
       
           
            [ChatCommand("unfreeze")]
            void cmdUnFreeze(BasePlayer player, string cmd, string[] args)
            {
                var target = BasePlayer.Find(args[0]);
                if (frozenPlayers.Contains(target)) 
                {
                    frozenPlayers.Remove(target);
                }
                       
            }
           
            [ChatCommand("unfreezeall")]
            void cmdUnFreezeAll(BasePlayer player, string cmd, string[] args)
            {
                frozenPlayers.Clear();       
            }
           
       
                timer.Repeat(1, 0, () => {
           
                foreach(BasePlayer current in frozenPlayers) {
               
                    var position = current.transform.position;
                    var configPos = new Vector3(position.x, position.y, position.z);
                    if(Vector3.Distance(current.transform.position, configPos) < 1)
                    {
                   
                    var timer = timer.Repeat(1, 0, () => current.ClientRPCPlayer(null, current, "ForcePositionTo", new object[] { configPos }));
                        current.TransformChanged();
                   
                    }
                }
            });
           
         
             void Unloaded()
            {
                timer.Destroy(); 
                frozenPlayers.Clear();
            }
        }}
    
     
  8. All you have done is placed the timer in the general class directory... it isn't in any method, the error has nothing to do with brackets, you have to put it in a proper method.
     
  9. I'm probably dumb.. these timers are so annoying ;/

    I did something.. but errorhttp://screenshot.sh/ouZ3pWKSCuSnS
    here is 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.
            Timer();
            }
               
           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);
            }
       
           
            [ChatCommand("unfreeze")]
            void cmdUnFreeze(BasePlayer player, string cmd, string[] args)
            {
                var target = BasePlayer.Find(args[0]);
                if (frozenPlayers.Contains(target)) 
                {
                    frozenPlayers.Remove(target);
                }
                       
            }
           
            [ChatCommand("unfreezeall")]
            void cmdUnFreezeAll(BasePlayer player, string cmd, string[] args)
            {
                frozenPlayers.Clear();       
            }
           
            void Timer(BasePlayer player, string cmd, string[] args)
            {
                    timer.Repeat(1, 0, () => {
           
                    foreach(BasePlayer current in frozenPlayers) {
               
                    var position = current.transform.position;
                    var configPos = new Vector3(position.x, position.y, position.z);
                    if(Vector3.Distance(current.transform.position, configPos) < 1)
                    {
                   
                        var timerrepeat = timer.Repeat(1, 0, () => current.ClientRPCPlayer(null, current, "ForcePositionTo", new object[] { configPos }));
                        current.TransformChanged();
                   
                    }
                }
            }
        }); //Error line.. but its probably not from this
           
         
             void Unloaded()
            {
                timerepeat.Destroy(); 
                frozenPlayers.Clear();
            }
        }}
    
     
  10. I think it would be much simpler if you made a function for the timer. Right now you're creating a new anonymous function with () => and you're simply mixing your brackets.
    [DOUBLEPOST=1436038846][/DOUBLEPOST]
    Code:
        // your version fixed:
        void Timer(BasePlayer player, string cmd, string[] args)
        {
            timer.Repeat(1, 0, () =>
                {
                    foreach (BasePlayer current in frozenPlayers)
                    {                    var position = current.transform.position;
                        var configPos = new Vector3(position.x, position.y, position.z);
                        if (Vector3.Distance(current.transform.position, configPos) < 1)
                        {                        var timerrepeat = timer.Repeat(1, 0, () => current.ClientRPCPlayer(null, current, "ForcePositionTo", new object[] { configPos }));
                            current.TransformChanged();                    }
                    }
                }
            );
        }    // Version that avoids the confusion
        void Timer(BasePlayer player, string cmd, string[] args)
        {
            timer.Repeat(1, 0, OnTimer);
        }    void OnTimer()
        {
            foreach (BasePlayer current in frozenPlayers)
            {            var position = current.transform.position;
                var configPos = new Vector3(position.x, position.y, position.z);
                if (Vector3.Distance(current.transform.position, configPos) < 1)
                {                var timerrepeat = timer.Repeat(1, 0, () => current.ClientRPCPlayer(null, current, "ForcePositionTo", new object[] { configPos }));
                    current.TransformChanged();            }
            }
        }
    
     
  11. Well the code works.

    Freeze = Works
    Unfreeze = No

    Ehh what to do .. the unfreeze command is good but doesnt working thats what i dont like in coding :p

    my current 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
        {
            private Timer timerrepeat;
            void Loaded()
            {
            if (!permission.PermissionExists("canmindfreeze")) permission.RegisterPermission("canmindfreeze", this);
                //LoadDefaultConfig(); Maybe gonna add this later. 
            TimerStart();
            }
               
           List<BasePlayer> frozenPlayers = new List<BasePlayer>();  
             
           
            [ChatCommand("freeze")]
            void cmdFreeze(BasePlayer player, string cmd, string[] args)
            {
                var target = BasePlayer.Find(args[0]);
                frozenPlayers.Add(target);
            }
       
           
            [ChatCommand("unfreeze")]
            void cmdUnFreeze(BasePlayer player, string cmd, string[] args)
            {
                var target = BasePlayer.Find(args[0]);                frozenPlayers.Remove(target);
                       
            }
           
            [ChatCommand("unfreezeall")]
            void cmdUnFreezeAll(BasePlayer player, string cmd, string[] args)
            {
                frozenPlayers.Clear();       
            }
           
            void TimerStart()
            {
            timer.Repeat(5, 0, OnTimer);
            }    void OnTimer()
        {
            foreach (BasePlayer current in frozenPlayers)
            {            var position = current.transform.position;
                var configPos = new Vector3(position.x, position.y, position.z);
                if (Vector3.Distance(current.transform.position, configPos) < 1)
                {                var timerrepeat = timer.Repeat(1, 0, () => current.ClientRPCPlayer(null, current, "ForcePositionTo", new object[] { configPos }));
                    current.TransformChanged();            }
            }
        }
           
         
             void Unloaded()
            {
                timerrepeat.Destroy(); 
                frozenPlayers.Clear();
            }
        }}
    
     
  12. OK I looked a little more closely at your code.

    You don't need to start a new timer for forcePositionTo, simply call current.ClientRPCPlayer directly. What you are doing with your current code is that every 5 seconds, you start a new timer for every frozen player that brings them back to their position. All you want is to bring them back to their position once every second, so change your main timer to 1 second (the one that calls "OnTimer") and remove the other timer.

    This will make it so that every 1 second, OnTimer will be called and that function will simply loop through frozenPlayers and bring them back to their position. As soon as you .Remove them from the frozenPlayer list, they'll be free to move (unless you added them several times -- a list allows that -- you might want to check the list before adding to make sure you're not adding a player multiple times).

    Also, you should clean up the code a bit. No need to have the function TimerStart, just put it's line of code straight into ServerInitialized. Make sure you KEEP that timer as well and on the unload of the plugin, you'll want to destroy it.

    Finally, dunno if it's because you aren't finished or I misunderstand how permissions work, but I have a feeling you are not checking for permissions currently (only registering a permission type).
     
  13. Okay so your post just made me to think better.. about the permission yes yes i know i will add it later.. i will make a cleanup also before posting an update.. Thank you so much.. only some people are so helpfull like you.

    And you said about checking the list.. ? Where is it ?
     
  14. C# is a very powerful language but it can definitely be confusing until you got some good experience with it. Most of my experience is with C++ so the transition wasn't so bad for me (C++ is a lot worse than C# in terms of complexity), but I can totally understand having trouble if you're coming from LUA or other "simple" scripting languages.
     
  15. Also i wanted to explain why i had 2 timers..
    The first calls the OnTimer.
    THE SECOND:
    So without the second timer the first timer every 1 sec saves the position that the player is on right now(So if i dont have the timer there and the freezed target runs it will save the position that he is running every 1 sec and will just rollback him just a bit). What do i need to do ? Probably save the position in the /freeze functions. But how..
     
  16. Your first timer will Repeat and call new Timers again and again...
    + Some Lua <-> C# analogies:
    Code:
    C#:
    ...
    var timerrepeat = ...Lua:
    ...
    local timerrepeat = ...
    ---------------------------------------------------------
    
    You just create new local var and not use your 'private Timer timerrepeat;' var.
    Also it's not a table of timers, it's variable that contain only one timer. (you need to use List<Timer> or HashSet<Timer> or Timer[])
    + If u want to unfreeze 1 player then you need to use Dictionary<ulong, Timer> (in lua: local table[steam] = timer), google for more info.