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, }, ["Gateway"] = { ["file"] = "rubickscircle.lua", ["minigame"] = "Cast", ["interupt"] = "AddItem", ["draw"] = "Draw", ["difficulty"] = 1, }, } Games = {} function loadgames() includedfiles = {} Games = {} 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 print("Loaded game:") PrintTable(Game,1) end print("Resolveing minigame names") print("All games:") PrintTable(Games,1) print("All spells:") PrintTable(Spells) local needefunctions = {"minigame","draw","interupt"} for k,v in pairs(Spells) do local spell = v print("Resolveing spell:") PrintTable(Spells) local gametab = Games[v["file"]] if not gametab then print("Coudln't find " .. v["file"] .. " in games") end for i,j in pairs(gametab) do local issimple = false for l,m in pairs(spell) do print("Checking if ",m,"is",i) if(m == i) then print("Overloading " .. m) spell[l] = j issimple = true break end end if not issimple then spell[i] = j end end --[[ local mgname = v["minigame"] local mginame = v["interupt"] local mgdname = v["draw"] for i,j in pairs(Games) do if i == v["file"] then for l,m in pairs(j) do Spells[k][l] = m print("Resolved " .. k) local castfunc = j[mgname] local drawfunc = j[mgdname] local interuptfunc = j[mginame] if(castfunc) then Spells[k]["minigame"] = castfunc else print("Spell " .. k .. " does not have a cast func! This may be an error!") end if(drawfunc) then Spells[k]["draw"] = drawfunc else print("Spell " .. k .. " does not have a draw func! This may be an error!") end if(interuptfunc) then Spells[k]["interupt"] = interuptfunc else print("Spell " .. k .. " does not have an interupt func! This may be an error!") end end end Spells[k] = j end ]]-- end print("After resolveing:") PrintTable(Spells) 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] CASTING_SPELL["minigame"](CASTING_SPELL, CASTING_SPELL["difficulty"]) else print("Could not find spell " .. spell) end end function DrawSpellOverlay() if(CASTING_SPELL) then print("Calling casting_spell's draw...") 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)