Exemple #1
0
        private static bool SetVar(string command, Variable[] vars, bool quiet, bool force)
        {
            if (vars.Length < 1)
            {
                throw new RunTimeError("Usage: setvar ('variable') [timeout]");
            }

            string varname = vars[0].AsString();

            ScriptVariables.ScriptVariable variable = ScriptVariables.GetVariable(varname);

            if (variable == null)
            {
                World.Player.SendMessage(Config.GetInt("SysColor"), $"'{varname}' not found, creating new variable");

                variable = new ScriptVariables.ScriptVariable(varname, new TargetInfo());

                ScriptVariables.ScriptVariableList.Add(variable);

                ScriptVariables.RegisterVariable(varname);

                ScriptManager.RedrawScriptVariables();
            }

            Interpreter.Timeout(vars.Length == 2 ? vars[1].AsUInt() : 30000, () => { return(true); });


            if (!ScriptManager.SetVariableActive)
            {
                variable.SetTarget();
                ScriptManager.SetVariableActive = true;

                return(false);
            }

            if (variable.TargetWasSet)
            {
                Interpreter.ClearTimeout();
                ScriptManager.SetVariableActive = false;
                return(true);
            }

            return(false);
        }