CASTING_SPELL = nil --AddLUACSFolder("spellminigames") local Folder = GM.Folder:gsub("gamemodes/","").."/gamemode/hud/games" --A table of spells to functions? Spells = { ["Fireball"] = { ["file"] = "connectthedots.lua", ["minigame"] = "Cast", ["interupt"] = "AddDots", ["draw"] = "Draw", ["difficulty"] = 1, }, } Games = {} function loadgames() includedfiles = {} print("Looking for what minigames we need...") for k,v in pairs(Spells) do local filename = v["file"] if (includedfiles[filename] == nil) then print("Spell " .. k .. " depends on " .. filename) includedfiles[filename] = true end end Game = {} print("Loading in minigames") for k,v in pairs(includedfiles) do AddCSLuaFile(Folder .. "/" .. k) Game = {} include(Folder .. "/" .. k) Games[k] = Game end print("Resolveing minigame names") for k,v in pairs(Spells) do local mgname = v["minigame"] local mginame = v["interupt"] local mgdname = v["draw"] for i,j in pairs(Games) do if i == v["file"] then print("Resolved " .. k) local castfunc = j[mgname] local drawfunc = j[mgdname] local interuptfunc = j[mginame] if(castfunc) then v["minigame"] = castfunc else print("Spell " .. k .. " does not have a cast func! This may be an error!") end if(drawfunc) then v["draw"] = drawfunc else print("Spell " .. k .. " does not have a draw func! This may be an error!") end if(interuptfunc) then v["interupt"] = interuptfunc else print("Spell " .. k .. " does not have an interupt func! This may be an error!") end end end end end hook.Add("Initialize","Loadspells",function() loadgames() end) concommand.Add("reloadgames",function(ply,cmd,args) loadgames() end) function StartMinigame(spell) print("starting " .. spell) if not spell then return end --If we're already casting, and are told to cast again do someting. if CASTING_SPELL != nil then CASTING_SPELL["interupt"](CASTING_SPELL) return end if Spells[spell] then CASTING_SPELL = Spells[spell] Spells[spell]["minigame"](CASTING_SPELL, Spells[spell]["difficulty"]) else print("Could not find spell " .. spell) end end function DrawSpellOverlay() if(CASTING_SPELL) then CASTING_SPELL["draw"](CASTING_SPELL) if(CASTING_SPELL.Score != nil) then finishedcasting(CASTING_SPELL.Score) CASTING_SPELL = nil end end end concommand.Add("startminigame",function(ply,cmd,args) print("Starting " .. args[1]) StartMinigame(args[1]) end)