public List <LuaParam> CallLuaFunctionForReturn(Player player, Actor target, string funcName, bool optional, params object[] args)
        {
            //Need a seperate case for NPCs cause that child/parent thing.
            if (target is Npc)
            {
                return(CallLuaFunctionNpcForReturn(player, (Npc)target, funcName, optional, args));
            }

            object[] args2 = new object[args.Length + (player == null ? 1 : 2)];
            Array.Copy(args, 0, args2, (player == null ? 1 : 2), args.Length);
            if (player != null)
            {
                args2[0] = player;
                args2[1] = target;
            }
            else
            {
                args2[0] = target;
            }

            string    luaPath = GetScriptPath(target);
            LuaScript script  = LoadScript(luaPath);

            if (script != null)
            {
                if (!script.Globals.Get(funcName).IsNil())
                {
                    //Run Script
                    DynValue        result  = script.Call(script.Globals[funcName], args2);
                    List <LuaParam> lparams = LuaUtils.CreateLuaParamList(result);
                    return(lparams);
                }
                else
                {
                    if (!optional)
                    {
                        SendError(player, String.Format("Could not find function '{0}' for actor {1}.", funcName, target.GetName()));
                    }
                }
            }
            else
            {
                if (!optional)
                {
                    SendError(player, String.Format("Could not find script for actor {0}.", target.GetName()));
                }
            }
            return(null);
        }
        public List <LuaParam> CallLuaFunctionForReturn(string path, string funcName, bool optional, params object[] args)
        {
            string    luaPath = path;
            LuaScript script  = LoadScript(luaPath);

            if (script != null)
            {
                if (!script.Globals.Get(funcName).IsNil())
                {
                    //Run Script
                    DynValue        result  = script.Call(script.Globals[funcName], args);
                    List <LuaParam> lparams = LuaUtils.CreateLuaParamList(result);
                    return(lparams);
                }
            }
            return(null);
        }
        private List <LuaParam> CallLuaFunctionNpcForReturn(Player player, Npc target, string funcName, bool optional, params object[] args)
        {
            object[] args2 = new object[args.Length + (player == null ? 1 : 2)];
            Array.Copy(args, 0, args2, (player == null ? 1 : 2), args.Length);
            if (player != null)
            {
                args2[0] = player;
                args2[1] = target;
            }
            else
            {
                args2[0] = target;
            }

            LuaScript parent = null, child = null;

            if (File.Exists("./scripts/base/" + target.classPath + ".lua"))
            {
                parent = LuaEngine.LoadScript("./scripts/base/" + target.classPath + ".lua");
            }

            Area area = target.zone;

            if (area is PrivateArea)
            {
                if (File.Exists(String.Format("./scripts/unique/{0}/privatearea/{1}_{2}/{3}/{4}.lua", area.zoneName, ((PrivateArea)area).GetPrivateAreaName(), ((PrivateArea)area).GetPrivateAreaType(), target.className, target.GetUniqueId())))
                {
                    child = LuaEngine.LoadScript(String.Format("./scripts/unique/{0}/privatearea/{1}_{2}/{3}/{4}.lua", area.zoneName, ((PrivateArea)area).GetPrivateAreaName(), ((PrivateArea)area).GetPrivateAreaType(), target.className, target.GetUniqueId()));
                }
            }
            else
            {
                if (File.Exists(String.Format("./scripts/unique/{0}/{1}/{2}.lua", area.zoneName, target.className, target.GetUniqueId())))
                {
                    child = LuaEngine.LoadScript(String.Format("./scripts/unique/{0}/{1}/{2}.lua", area.zoneName, target.className, target.GetUniqueId()));
                }
            }

            if (parent == null && child == null)
            {
                LuaEngine.SendError(player, String.Format("ERROR: Could not find script for actor {0}.", target.GetName()));
            }

            //Run Script
            DynValue result;

            if (child != null && child.Globals[funcName] != null)
            {
                result = child.Call(child.Globals[funcName], args2);
            }
            else if (parent != null && parent.Globals[funcName] != null)
            {
                result = parent.Call(parent.Globals[funcName], args2);
            }
            else
            {
                return(null);
            }

            List <LuaParam> lparams = LuaUtils.CreateLuaParamList(result);

            return(lparams);
        }