---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
local factionselected = tostring(player)
Game.faction = {}

function OnModGameStart_faction_selector()
    --print(Map.map_name)
Game.factionselection = true --enables mod referencing

if Game.Hearts_added_mod ~= 1 then return 0 end--Check if hearts loaded
TutorialFlashButton(3,0)

--CHECK FOR INCOMPATIBLE MAPS
if Map.map_name == "Small" then return 0 end
if Map.map_name == "Standard" then return 0 end
if Map.map_name == "Big" then return 0 end
if Map.map_name == "Huge" then return 0 end
if Map.map_name == "Puzzlebox" then return 0 end
if Map.map_name == "Conscription" then return 0 end
if Map.map_name == "Varomortis" then return 0 end
if Map.map_name == "Spookhaven" then return 0 end
if Map.map_name == "KeeperTD - The Way in the Water" then return 0 end
if Map.map_name == "KeeperTD" then return 0 end
if Map.map_name == "(A)mazing Defence" then return 0 end
if Map.map_name == "Skill Your Keeper" then return 0 end
if Map.map_name == "Easter Egg" then return 0 end
if Map.map_name == "SummoneRPG" then return 0 end
if Map.map_name == "AvataRPG" then return 0 end
if Map.map_name == "Concentration: The Game" then return 0 end
if Map.map_name == "ImpWars Remake" then return 0 end
if Map.map_name == "The Impslayer" then return 0 end
if Map.map_name == "Maze Runner" then return 0 end
if Map.map_name == "The Whispering Chambers" then return 0 end
if Map.map_name == "escape from alcatraz 2023.12.5 map" then return 0 end
if Map.map_name == "Whispers of the Abyss" then return 0 end
if Map.map_name == "Slap-Slap!" then return 0 end
if Map.map_name == "Unholy Christmas!" then return 0 end
if Map.map_name == "Auto Chess" then return 0 end
if Map.map_name == "Alone in the Dark" then return 0 end
if Map.map_name == "Grave of the Avatar" then return 0 end
if Map.map_name == "Spatoween 2024" then return 0 end
if Map.map_name == "The Necromancer's Hold" then return 0 end
if Map.map_name == "Desert Tomb" then return 0 end
if Map.map_name == "Belzebub" then return 0 end
if Map.map_name == "<TEMPLATE> Skill Your Keeper" then return 0 end
if Map.map_name == "<TEMPLATE> <HERO> Skill Your Keeper" then return 0 end
if Map.map_name == "Defense of the Keepers" then return 0 end

--add base creatures incase some were left out from the map
NewCreatureType("GHOST")NewCreatureType("HORNY")NewCreatureType("IMP")NewCreatureType("SKELETON")NewCreatureType("SPIDERLING")NewCreatureType("VAMPIRE")NewCreatureType("BUG")NewCreatureType("FLY")NewCreatureType("SPIDER")NewCreatureType("BILE_DEMON")NewCreatureType("DARK_MISTRESS")NewCreatureType("DEMONSPAWN")NewCreatureType("DRAGON")NewCreatureType("HELL_HOUND")NewCreatureType("MAIDEN")NewCreatureType("ORC")NewCreatureType("SORCEROR")NewCreatureType("TENTACLE")NewCreatureType("TROLL")NewCreatureType("BIRD")NewCreatureType("AVATAR")NewCreatureType("TUNNELLER")NewCreatureType("BARBARIAN")NewCreatureType("DRUID")NewCreatureType("DWARFA")NewCreatureType("FAIRY")NewCreatureType("GIANT")NewCreatureType("KNIGHT")NewCreatureType("MONK")NewCreatureType("SAMURAI")NewCreatureType("THIEF")NewCreatureType("TIME_MAGE")NewCreatureType("WITCH")NewCreatureType("WIZARD")NewCreatureType("ARCHER")

Remove_base_content()
MagicAvailable("ALL_PLAYERS","COMPUTER_FACTION_SELECTOR",true,true)
MagicAvailable("ALL_PLAYERS","FACTION_KEEPER",true,true)
--MagicAvailable("ALL_PLAYERS","FACTION_SILENTHILL",true,true)
MagicAvailable("ALL_PLAYERS","FACTION_HEROES",true,true)
--MagicAvailable("ALL_PLAYERS","FACTION_DK2KEEPER",true,true)
--MagicAvailable("ALL_PLAYERS","FACTION_DK2HEROES",true,true)
MagicAvailable("ALL_PLAYERS","FACTION_CULTISTS",true,true)

Remove_hearts()
if PLAYER0.type == "Computer" then RunDKScriptCommand("USE_POWER(PLAYER0,COMPUTER_FACTION_SELECTOR,1)") end
if PLAYER1.type == "Computer" then RunDKScriptCommand("USE_POWER(PLAYER1,COMPUTER_FACTION_SELECTOR,1)") end
if PLAYER2.type == "Computer" then RunDKScriptCommand("USE_POWER(PLAYER2,COMPUTER_FACTION_SELECTOR,1)") end
if PLAYER3.type == "Computer" then RunDKScriptCommand("USE_POWER(PLAYER3,COMPUTER_FACTION_SELECTOR,1)") end
if PLAYER4.type == "Computer" then RunDKScriptCommand("USE_POWER(PLAYER4,COMPUTER_FACTION_SELECTOR,1)") end
if PLAYER5.type == "Computer" then RunDKScriptCommand("USE_POWER(PLAYER5,COMPUTER_FACTION_SELECTOR,1)") end
if PLAYER6.type == "Computer" then RunDKScriptCommand("USE_POWER(PLAYER6,COMPUTER_FACTION_SELECTOR,1)") end
end
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
function Computer_faction_selector_function(player,power_kind,power_level,stl_x,stl_y,thing,is_free)
local computer_factions = math.random(1,2)
if computer_factions == 1 then  Keeper_faction_selected(player)end
if computer_factions == 2 then  Heroes_faction_selected(player)end
if computer_factions == 3 then  Dk2keeper_faction_selected(player)end
if computer_factions == 4 then  Dk2heroes_faction_selected(player)end
if computer_factions == 5 then  Silenthill_faction_selected(player)end
if computer_factions == 6 then  Cultist_faction_selected(player)end
return 0
end
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
function Remove_hearts()
     for _, obj in ipairs(GetThingsOfClass("Object")) do
        if obj.model == "SOUL_CONTAINER" then
        obj.pos = {x=0,y=0,z=0}
        end
    end

    for _, room in ipairs(GetRoomsOfType("DUNGEON_HEART")) do
        for _, slab in ipairs(room.slabs) do ChangeSlabType(slab.slb_x,slab.slb_y,"BLANK_HEART_SLAB") --print("changing HEART_PEDESTAL slab")
            if #GetRoomsOfType("DUNGEON_HEART") == 0 then print("All HEART_PEDESTAL slabs are changed")
            return 0
            end
        end
    end
end
----------------------------
function Switch_heart(player)
    for _, room in ipairs(GetRoomsOfType("BLANK_DUNGEON_HEART_ROOM")) do
        if room.owner == player then
            for _, slab in ipairs(room.slabs) do
            if Game.faction[player] == 1 then ChangeSlabType(slab.slb_x,slab.slb_y,"KEEPER_HEART_SLAB")end
            if Game.faction[player] == 2 then ChangeSlabType(slab.slb_x,slab.slb_y,"HEROES_HEART_SLAB")end
            if Game.faction[player] == 3 then ChangeSlabType(slab.slb_x,slab.slb_y,"DK2_KEEPER_HEART_SLAB")end
            if Game.faction[player] == 4 then ChangeSlabType(slab.slb_x,slab.slb_y,"DK2_HEROES_HEART_SLAB")end
            if Game.faction[player] == 5 then ChangeSlabType(slab.slb_x,slab.slb_y,"SILENTHILL_HEART_SLAB")end
			if Game.faction[player] == 6 then ChangeSlabType(slab.slb_x,slab.slb_y,"CULTIST_HEART_SLAB")end
            end
        end

                if #GetRoomsOfType("BLANK_DUNGEON_HEART_ROOM") == 0 then print("All hearts have been selected")
                    for _, obj in ipairs(GetThingsOfClass("Object")) do
                        if obj.model == "SOUL_CONTAINER"  and obj.health > 0 then 
                        --obj:delete()
                        obj.health = 0
                        end
                    end
                return 0
                end

    end
end
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
function Impchecker(eventData, triggerData)
local player = triggerData.player

--FIRST IMP ALWAYS FREE
if Game.faction[player] == 1 and player.IMP<1       and player.money<500 then player:add_gold(1) end
if Game.faction[player] == 2 and player.TUNNELLER<1 and player.money<500 then player:add_gold(1) end

--REMOVE IMP SPELL IF 20
if player.IMP>19 or player.TUNNELLER>19 then MagicAvailable(player,"POWER_IMP",false,false)else MagicAvailable(player,"POWER_IMP",true,true) end

    for _, c in ipairs(GetCreaturesOfPlayer(player)) do
        if Game.faction[player] == 1 then return 0 end
        if c.model == "IMP" then
        if Game.faction[player] == 2 then AddCreatureToLevel(player,"TUNNELLER",c.pos,1,0,"JUMP")end
        c:delete()
        end
    end
end
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
function Remove_base_content(player)
--REMOVE ROOM AVAILABILITY
RoomAvailable("ALL_PLAYERS","TREASURE",0)RoomAvailable("ALL_PLAYERS","RESEARCH",0)RoomAvailable("ALL_PLAYERS","PRISON",0)RoomAvailable("ALL_PLAYERS","TORTURE",0)RoomAvailable("ALL_PLAYERS","TRAINING",0)RoomAvailable("ALL_PLAYERS","WORKSHOP",0)RoomAvailable("ALL_PLAYERS","SCAVENGER",0)RoomAvailable("ALL_PLAYERS","TEMPLE",0)RoomAvailable("ALL_PLAYERS","GRAVEYARD",0)RoomAvailable("ALL_PLAYERS","BARRACKS",0)RoomAvailable("ALL_PLAYERS","GARDEN",0)RoomAvailable("ALL_PLAYERS","LAIR",0)RoomAvailable("ALL_PLAYERS","BRIDGE",0)RoomAvailable("ALL_PLAYERS","GUARD_POST",0)
--REMOVE MAGIC AVAILABILITY
MagicAvailable("ALL_PLAYERS","POWER_POSSESS",false,false)           RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_POSSESS,PanelTabIndex,1)")MagicAvailable("ALL_PLAYERS","POWER_IMP",false,false)               RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_IMP,PanelTabIndex,2)")MagicAvailable("ALL_PLAYERS","POWER_OBEY",false,false)              RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_OBEY,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_SIGHT",false,false)             RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_SIGHT,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_CALL_TO_ARMS",false,false)      RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_CALL_TO_ARMS,PanelTabIndex,3)")MagicAvailable("ALL_PLAYERS","POWER_CAVE_IN",false,false)           RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_CAVE_IN,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_HEAL_CREATURE",false,false)     RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_HEAL_CREATURE,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_HOLD_AUDIENCE",false,false)     RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_HOLD_AUDIENCE,PanelTabIndex,4)")MagicAvailable("ALL_PLAYERS","POWER_LIGHTNING",false,false)         RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_LIGHTNING,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_SPEED",false,false)             RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_SPEED,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_PROTECT",false,false)           RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_PROTECT,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_CONCEAL",false,false)           RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_CONCEAL,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_DISEASE",false,false)           RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_DISEASE,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_CHICKEN",false,false)           RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_CHICKEN,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_DESTROY_WALLS",false,false)     RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_DESTROY_WALLS,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_TIME_BOMB",false,false)         RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_TIME_BOMB,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_ARMAGEDDON",false,false)        RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_ARMAGEDDON,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_REBOUND",false,false)           RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_REBOUND,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_FREEZE",false,false)            RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_FREEZE,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_SLOW",false,false)              RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_SLOW,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_FLIGHT",false,false)            RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_FLIGHT,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_VISION",false,false)            RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_VISION,PanelTabIndex,0)")MagicAvailable("ALL_PLAYERS","POWER_TUNNELLER",false,false)         RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_TUNNELLER,PanelTabIndex,0)")
--REMOVE TRAPS AVAILABILITY
TrapAvailable("ALL_PLAYERS","BOULDER",false,0)          RunDKScriptCommand("SET_TRAP_CONFIGURATION(BOULDER,PanelTabIndex,0)")TrapAvailable("ALL_PLAYERS","ALARM",false,0)            RunDKScriptCommand("SET_TRAP_CONFIGURATION(ALARM,PanelTabIndex,0)")TrapAvailable("ALL_PLAYERS","POISON_GAS",false,0)       RunDKScriptCommand("SET_TRAP_CONFIGURATION(POISON_GAS,PanelTabIndex,0)")TrapAvailable("ALL_PLAYERS","LIGHTNING",false,0)        RunDKScriptCommand("SET_TRAP_CONFIGURATION(LIGHTNING,PanelTabIndex,0)")TrapAvailable("ALL_PLAYERS","WORD_OF_POWER",false,0)    RunDKScriptCommand("SET_TRAP_CONFIGURATION(WORD_OF_POWER,PanelTabIndex,0)")TrapAvailable("ALL_PLAYERS","LAVA",false,0)             RunDKScriptCommand("SET_TRAP_CONFIGURATION(LAVA,PanelTabIndex,0)")TrapAvailable("ALL_PLAYERS","TNT",false,0)              RunDKScriptCommand("SET_TRAP_CONFIGURATION(TNT,PanelTabIndex,0)")TrapAvailable("ALL_PLAYERS","SENTRY",false,0)           RunDKScriptCommand("SET_TRAP_CONFIGURATION(SENTRY,PanelTabIndex,0)")TrapAvailable("ALL_PLAYERS","BALLISTA",false,0)         RunDKScriptCommand("SET_TRAP_CONFIGURATION(BALLISTA,PanelTabIndex,0)")
--REMOVE DOOR AVAILABILITY
DoorAvailable("ALL_PLAYERS","WOOD",false,0)     RunDKScriptCommand("SET_DOOR_CONFIGURATION(WOOD,PanelTabIndex,0)")DoorAvailable("ALL_PLAYERS","BRACED",false,0)   RunDKScriptCommand("SET_DOOR_CONFIGURATION(BRACED,PanelTabIndex,0)")DoorAvailable("ALL_PLAYERS","STEEL",false,0)    RunDKScriptCommand("SET_DOOR_CONFIGURATION(STEEL,PanelTabIndex,0)")DoorAvailable("ALL_PLAYERS","MAGIC",false,0)    RunDKScriptCommand("SET_DOOR_CONFIGURATION(MAGIC,PanelTabIndex,0)")DoorAvailable("ALL_PLAYERS","SECRET",false,0)   RunDKScriptCommand("SET_DOOR_CONFIGURATION(SECRET,PanelTabIndex,0)")DoorAvailable("ALL_PLAYERS","MIDAS",false,0)    RunDKScriptCommand("SET_DOOR_CONFIGURATION(MIDAS,PanelTabIndex,0)")
--REMOVE CREATURE AVAILABILITY
CreatureAvailable("ALL_PLAYERS","FLY",false,0)CreatureAvailable("ALL_PLAYERS","BARBARIAN",false,0)CreatureAvailable("ALL_PLAYERS","BILE_DEMON",false,0)CreatureAvailable("ALL_PLAYERS","BIRD",false,0)CreatureAvailable("ALL_PLAYERS","BUG",false,0)CreatureAvailable("ALL_PLAYERS","DARK_MISTRESS",false,0)CreatureAvailable("ALL_PLAYERS","DEMONSPAWN",false,0)CreatureAvailable("ALL_PLAYERS","DRAGON",false,0)CreatureAvailable("ALL_PLAYERS","DRUID",false,0)CreatureAvailable("ALL_PLAYERS","DWARFA",false,0)CreatureAvailable("ALL_PLAYERS","FAIRY",false,0)CreatureAvailable("ALL_PLAYERS","FLOATING_SPIRIT",false,0)CreatureAvailable("ALL_PLAYERS","GHOST",false,0)CreatureAvailable("ALL_PLAYERS","GIANT",false,0)CreatureAvailable("ALL_PLAYERS","HELL_HOUND",false,0)CreatureAvailable("ALL_PLAYERS","HORNY",false,0)CreatureAvailable("ALL_PLAYERS","IMP",false,0)CreatureAvailable("ALL_PLAYERS","KNIGHT",false,0)CreatureAvailable("ALL_PLAYERS","MAIDEN",false,0)CreatureAvailable("ALL_PLAYERS","MONK",false,0)CreatureAvailable("ALL_PLAYERS","ORC",false,0)CreatureAvailable("ALL_PLAYERS","SAMURAI",false,0)CreatureAvailable("ALL_PLAYERS","SKELETON",false,0)CreatureAvailable("ALL_PLAYERS","SORCEROR",false,0)CreatureAvailable("ALL_PLAYERS","SPIDER",false,0)CreatureAvailable("ALL_PLAYERS","SPIDERLING",false,0)CreatureAvailable("ALL_PLAYERS","TENTACLE",false,0)CreatureAvailable("ALL_PLAYERS","THIEF",false,0)CreatureAvailable("ALL_PLAYERS","TIME_MAGE",false,0)CreatureAvailable("ALL_PLAYERS","TROLL",false,0)CreatureAvailable("ALL_PLAYERS","TUNNELLER",false,0)CreatureAvailable("ALL_PLAYERS","VAMPIRE",false,0)CreatureAvailable("ALL_PLAYERS","WITCH",false,0)CreatureAvailable("ALL_PLAYERS","WIZARD",false,0)CreatureAvailable("ALL_PLAYERS","ARCHER",false,0)CreatureAvailable("ALL_PLAYERS","AVATAR",false,0)
--CHECK CREATURE MODS
if Game.torturer == true then           CreatureAvailable("ALL_PLAYERS","TORTURER",false,0)end
if Game.scavengereye == true then       CreatureAvailable("ALL_PLAYERS","SCAVENGER_EYE",false,0)end
--SILENT HILL STUFF
if Game.shschism == true then           CreatureAvailable("ALL_PLAYERS","SH_ROBBIE",false,0)end
if Game.shschism == true then           CreatureAvailable("ALL_PLAYERS","SH_SCHISM",false,0)end
end
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
function Add_base_content(player)

local trigger = RegisterTimerEvent(Impchecker,2,true)
trigger.triggerData.player = player

--REMOVE FACTIONS
MagicAvailable(player,"COMPUTER_FACTION_SELECTOR",false,false)MagicAvailable(player,"FACTION_KEEPER",false,false)MagicAvailable(player,"FACTION_SILENTHILL",false,false)MagicAvailable(player,"FACTION_HEROES",false,false)MagicAvailable(player,"FACTION_DK2KEEPER",false,false)MagicAvailable(player,"FACTION_DK2HEROES",false,false)MagicAvailable(player,"FACTION_CULTISTS",false,false)
--ADD ROOMS
RoomAvailable(player,"TREASURE",1,true)RoomAvailable(player,"RESEARCH",1,true)RoomAvailable(player,"PRISON",1,false)RoomAvailable(player,"TORTURE",1,false)RoomAvailable(player,"TRAINING",1,true)RoomAvailable(player,"WORKSHOP",1,false)RoomAvailable(player,"SCAVENGER",1,false)RoomAvailable(player,"TEMPLE",1,false)RoomAvailable(player,"GRAVEYARD",1,false)RoomAvailable(player,"BARRACKS",1,false)RoomAvailable(player,"GARDEN",1,true)RoomAvailable(player,"LAIR",1,true)RoomAvailable(player,"BRIDGE",1,false)RoomAvailable(player,"GUARD_POST",1,false)
--ADD MAGIC
MagicAvailable(player,"POWER_POSSESS",true,true)
MagicAvailable(player,"POWER_IMP",true,true)
MagicAvailable(player,"POWER_CALL_TO_ARMS",true,false)
MagicAvailable(player,"POWER_HOLD_AUDIENCE",true,false)

MagicAvailable(player,"POWER_SIGHT",true,false)         RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_SIGHT,PanelTabIndex,5)")
MagicAvailable(player,"POWER_HEAL_CREATURE",true,false) RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_HEAL_CREATURE,PanelTabIndex,6)")
MagicAvailable(player,"POWER_CAVE_IN",true,false)       RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_CAVE_IN,PanelTabIndex,7)")
MagicAvailable(player,"POWER_LIGHTNING",true,false)     RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_LIGHTNING,PanelTabIndex,8)")
MagicAvailable(player,"POWER_DESTROY_WALLS",true,false) RunDKScriptCommand("SET_POWER_CONFIGURATION(POWER_DESTROY_WALLS,PanelTabIndex,9)")
--ADD TRAPS/DOORS
DoorAvailable(player,"WOOD",true,0)             RunDKScriptCommand("SET_DOOR_CONFIGURATION(WOOD,PanelTabIndex,1)")
DoorAvailable(player,"STEEL",true,0)            RunDKScriptCommand("SET_DOOR_CONFIGURATION(STEEL,PanelTabIndex,2)")
DoorAvailable(player,"MAGIC",true,0)            RunDKScriptCommand("SET_DOOR_CONFIGURATION(MAGIC,PanelTabIndex,3)")
DoorAvailable(player,"MIDAS",true,0)            RunDKScriptCommand("SET_DOOR_CONFIGURATION(MIDAS,PanelTabIndex,4)")
TrapAvailable(player,"POISON_GAS",true,0)       RunDKScriptCommand("SET_TRAP_CONFIGURATION(POISON_GAS,PanelTabIndex,5)")
TrapAvailable(player,"LIGHTNING",true,0)        RunDKScriptCommand("SET_TRAP_CONFIGURATION(LIGHTNING,PanelTabIndex,6)")
TrapAvailable(player,"WORD_OF_POWER",true,0)    RunDKScriptCommand("SET_TRAP_CONFIGURATION(WORD_OF_POWER,PanelTabIndex,7)")
TrapAvailable(player,"SENTRY",true,0)           RunDKScriptCommand("SET_TRAP_CONFIGURATION(SENTRY,PanelTabIndex,8)")
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function Keeper_faction_selected(player,power_kind,power_level,stl_x,stl_y,thing,is_free)
local factionselected = tostring(player)    if Game[factionselected] ~= nil then  QuickPlayerInformation(20,player,"You cannot select another faction.") return 0 end      Game[factionselected] = true
Game.faction[player] = 1 Game.disable_texture_mod = 1 Texture_pack_function(player) Add_base_content(player) Switch_heart(player) SetHandGraphic(player,"KEEPER_HAND")
SetDigger(player,"IMP")
CreatureAvailable(player,"BUG",true,0)             AddCreatureToPool("BUG",player.max_creatures/5)
CreatureAvailable(player,"FLY",true,0)             AddCreatureToPool("FLY",player.max_creatures/5)
CreatureAvailable(player,"SPIDER",true,0)          AddCreatureToPool("SPIDER",player.max_creatures/5)
CreatureAvailable(player,"BILE_DEMON",true,0)      AddCreatureToPool("BILE_DEMON",player.max_creatures/5)
CreatureAvailable(player,"DARK_MISTRESS",true,0)   AddCreatureToPool("DARK_MISTRESS",player.max_creatures/5)
CreatureAvailable(player,"DEMONSPAWN",true,0)      AddCreatureToPool("DEMONSPAWN",player.max_creatures/5)
CreatureAvailable(player,"DRAGON",true,0)          AddCreatureToPool("DRAGON",player.max_creatures/5)
CreatureAvailable(player,"HELL_HOUND",true,0)      AddCreatureToPool("HELL_HOUND",player.max_creatures/5)
CreatureAvailable(player,"MAIDEN",true,0)          AddCreatureToPool("MAIDEN",player.max_creatures/5)
CreatureAvailable(player,"ORC",true,0)             AddCreatureToPool("ORC",player.max_creatures/5)
CreatureAvailable(player,"SORCEROR",true,0)        AddCreatureToPool("SORCEROR",player.max_creatures/5)
CreatureAvailable(player,"TENTACLE",true,0)        AddCreatureToPool("TENTACLE",player.max_creatures/5)
CreatureAvailable(player,"TROLL",true,0)           AddCreatureToPool("TROLL",player.max_creatures/5)
--CHECK CREATURE MODS
if Game.torturer == true then       CreatureAvailable(player,"TORTURER",true,0)        AddCreatureToPool("TORTURER",player.max_creatures/5)end
if Game.scavengereye == true then   CreatureAvailable(player,"SCAVENGER_EYE",true,0)   AddCreatureToPool("SCAVENGER_EYE",player.max_creatures/5)end
return 0
end
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
function Heroes_faction_selected(player,power_kind,power_level,stl_x,stl_y,thing,is_free)
local factionselected = tostring(player)    if Game[factionselected] ~= nil then  QuickPlayerInformation(20,player,"You cannot select another faction.") return 0 end      Game[factionselected] = true
Game.faction[player] = 2 Game.disable_texture_mod = 1 Texture_pack_function(player) Add_base_content(player) Switch_heart(player) SetHandGraphic(player,"HEROES_HAND")
SetDigger(player,"TUNNELLER")
CreatureAvailable(player,"BARBARIAN",true,0)     AddCreatureToPool("BARBARIAN",player.max_creatures/5)
CreatureAvailable(player,"DRUID",true,0)         AddCreatureToPool("DRUID",player.max_creatures/5)
CreatureAvailable(player,"DWARFA",true,0)        AddCreatureToPool("DWARFA",player.max_creatures/5)
CreatureAvailable(player,"FAIRY",true,0)         AddCreatureToPool("FAIRY",player.max_creatures/5)
CreatureAvailable(player,"GIANT",true,0)         AddCreatureToPool("GIANT",player.max_creatures/5)
CreatureAvailable(player,"KNIGHT",true,0)        AddCreatureToPool("KNIGHT",player.max_creatures/5)
CreatureAvailable(player,"MONK",true,0)          AddCreatureToPool("MONK",player.max_creatures/5)
CreatureAvailable(player,"SAMURAI",true,0)       AddCreatureToPool("SAMURAI",player.max_creatures/5)
CreatureAvailable(player,"THIEF",true,0)         AddCreatureToPool("THIEF",player.max_creatures/5)
CreatureAvailable(player,"TIME_MAGE",true,0)     AddCreatureToPool("TIME_MAGE",player.max_creatures/5)
CreatureAvailable(player,"WITCH",true,0)         AddCreatureToPool("WITCH",player.max_creatures/5)
CreatureAvailable(player,"WIZARD",true,0)        AddCreatureToPool("WIZARD",player.max_creatures/5)
CreatureAvailable(player,"ARCHER",true,0)        AddCreatureToPool("ARCHER",player.max_creatures/5)
return 0
end
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
function Dk2keeper_faction_selected(player,power_kind,power_level,stl_x,stl_y,thing,is_free)
local factionselected = tostring(player)    if Game[factionselected] ~= nil then  QuickPlayerInformation(20,player,"You cannot select another faction.") return 0 end      Game[factionselected] = true
Game.faction[player] = 3 Game.disable_texture_mod = 1 Texture_pack_function(player) Add_base_content(player) Switch_heart(player) SetHandGraphic(player,"")

return 0
end
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
function Dk2heroes_faction_selected(player,power_kind,power_level,stl_x,stl_y,thing,is_free)
local factionselected = tostring(player)    if Game[factionselected] ~= nil then  QuickPlayerInformation(20,player,"You cannot select another faction.") return 0 end      Game[factionselected] = true
Game.faction[player] = 4 Game.disable_texture_mod = 1 Texture_pack_function(player) Add_base_content(player) Switch_heart(player) SetHandGraphic(player,"")

return 0
end
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
function Silenthill_faction_selected(player,power_kind,power_level,stl_x,stl_y,thing,is_free)
local factionselected = tostring(player)    if Game[factionselected] ~= nil then  QuickPlayerInformation(20,player,"You cannot select another faction.") return 0 end      Game[factionselected] = true
Game.faction[player] = 5 Game.disable_texture_mod = 1 Texture_pack_function(player) Add_base_content(player) Switch_heart(player) SetHandGraphic(player,"")

return 0
end
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
function Cultist_faction_selected(player,power_kind,power_level,stl_x,stl_y,thing,is_free)
local factionselected = tostring(player)    if Game[factionselected] ~= nil then  QuickPlayerInformation(20,player,"You cannot select another faction.") return 0 end      Game[factionselected] = true
Game.faction[player] = 6 Game.disable_texture_mod = 1 Texture_pack_function(player) Add_base_content(player) Switch_heart(player) SetHandGraphic(player,"CULTIST_HAND")

return 0
end









