local factionselected = tostring(player)
local pausescriptcheck = false
Game.factionselection = true --enables mod referencing
Game.faction = {}
---------------------------------------------------------------------------------------------------------------------------------------
function Pause_faction_selector()
    if pausescriptcheck == false then
    if Map.map_name == "Small" and Game.MapIsCreated == true then OnModGameStart_faction_selector() print("Faction mod loaded") pausescriptcheck=true end
    if Map.map_name == "Standard" and Game.MapIsCreated == true then OnModGameStart_faction_selector() print("Faction mod loaded") pausescriptcheck=true end
    if Map.map_name == "Big" and Game.MapIsCreated == true then OnModGameStart_faction_selector() print("Faction mod loaded") pausescriptcheck=true end
    if Map.map_name == "Huge" and Game.MapIsCreated == true then OnModGameStart_faction_selector() print("Faction mod loaded") pausescriptcheck=true end
    end
end

function Mod_disabled() print("Factions mod disabled due to incompatibility.") end
function OnModGameStart_faction_selector()
print("Faction mod loaded")
--CHECK FOR INCOMPATIBLE MAPS
if Map.map_name == "Small" and Game.MapIsCreated == nil or Map.map_name == "Small" and Game.MapIsCreated == false then RegisterTimerEvent(Pause_faction_selector,2,true) return 0 end
if Map.map_name == "Standard" and Game.MapIsCreated == nil or Map.map_name == "Standard" and Game.MapIsCreated == false then RegisterTimerEvent(Pause_faction_selector,2,true) return 0 end
if Map.map_name == "Big" and Game.MapIsCreated == nil or Map.map_name == "Big" and Game.MapIsCreated == false then RegisterTimerEvent(Pause_faction_selector,2,true) return 0 end
if Map.map_name == "Huge" and Game.MapIsCreated == nil or Map.map_name == "Huge" and Game.MapIsCreated == false then RegisterTimerEvent(Pause_faction_selector,2,true) return 0 end
if Map.map_name == "Puzzlebox" then Mod_disabled()return 0 end
if Map.map_name == "Conscription" then Mod_disabled()return 0 end
if Map.map_name == "Varomortis" then Mod_disabled()return 0 end
if Map.map_name == "Spookhaven" then Mod_disabled()return 0 end
if Map.map_name == "KeeperTD - The Way in the Water" then Mod_disabled()return 0 end
if Map.map_name == "KeeperTD" then Mod_disabled()return 0 end
if Map.map_name == "(A)mazing Defence" then Mod_disabled()return 0 end
if Map.map_name == "Skill Your Keeper" then Mod_disabled()return 0 end
if Map.map_name == "Easter Egg" then Mod_disabled()return 0 end
if Map.map_name == "SummoneRPG" then Mod_disabled()return 0 end
if Map.map_name == "AvataRPG" then Mod_disabled()return 0 end
if Map.map_name == "Concentration: The Game" then Mod_disabled()return 0 end
if Map.map_name == "ImpWars Remake" then Mod_disabled()return 0 end
if Map.map_name == "The Impslayer" then Mod_disabled()return 0 end
if Map.map_name == "Maze Runner" then Mod_disabled()return 0 end
if Map.map_name == "The Whispering Chambers" then Mod_disabled()return 0 end
if Map.map_name == "escape from alcatraz 2023.12.5 map" then Mod_disabled()return 0 end
if Map.map_name == "Whispers of the Abyss" then Mod_disabled()return 0 end
if Map.map_name == "Slap-Slap!" then Mod_disabled()return 0 end
if Map.map_name == "Unholy Christmas!" then Mod_disabled()return 0 end
if Map.map_name == "Auto Chess" then Mod_disabled()return 0 end
if Map.map_name == "Alone in the Dark" then Mod_disabled()return 0 end
if Map.map_name == "Grave of the Avatar" then Mod_disabled()return 0 end
if Map.map_name == "Spatoween 2024" then Mod_disabled()return 0 end
if Map.map_name == "The Necromancer's Hold" then Mod_disabled()return 0 end
if Map.map_name == "Desert Tomb" then Mod_disabled()return 0 end
if Map.map_name == "Belzebub" then Mod_disabled()return 0 end
if Map.map_name == "<TEMPLATE> Skill Your Keeper" then Mod_disabled()return 0 end
if Map.map_name == "<TEMPLATE> <HERO> Skill Your Keeper" then Mod_disabled()return 0 end
if Map.map_name == "Defense of the Keepers" then Mod_disabled()return 0 end

SetMusic(0)
--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")
NewCreatureType("FLOATING_SPIRIT")
--add creaturepool
AddCreatureToPool("BARBARIAN",PLAYER0.max_creatures/5)
AddCreatureToPool("DRUID",PLAYER0.max_creatures/5)
AddCreatureToPool("DWARFA",PLAYER0.max_creatures/5)
AddCreatureToPool("FAIRY",PLAYER0.max_creatures/5)
AddCreatureToPool("GIANT",PLAYER0.max_creatures/5)
AddCreatureToPool("KNIGHT",PLAYER0.max_creatures/5)
AddCreatureToPool("MONK",PLAYER0.max_creatures/5)
AddCreatureToPool("SAMURAI",PLAYER0.max_creatures/5)
AddCreatureToPool("THIEF",PLAYER0.max_creatures/5)
AddCreatureToPool("TIME_MAGE",PLAYER0.max_creatures/5)
AddCreatureToPool("WITCH",PLAYER0.max_creatures/5)
AddCreatureToPool("WIZARD",PLAYER0.max_creatures/5)
AddCreatureToPool("ARCHER",PLAYER0.max_creatures/5)
AddCreatureToPool("BUG",PLAYER0.max_creatures/5)
AddCreatureToPool("FLY",PLAYER0.max_creatures/5)
AddCreatureToPool("SPIDER",PLAYER0.max_creatures/5)
AddCreatureToPool("BILE_DEMON",PLAYER0.max_creatures/5)
AddCreatureToPool("DARK_MISTRESS",PLAYER0.max_creatures/5)
AddCreatureToPool("DEMONSPAWN",PLAYER0.max_creatures/5)
AddCreatureToPool("DRAGON",PLAYER0.max_creatures/5)
AddCreatureToPool("HELL_HOUND",PLAYER0.max_creatures/5)
AddCreatureToPool("MAIDEN",PLAYER0.max_creatures/5)
AddCreatureToPool("ORC",PLAYER0.max_creatures/5)
AddCreatureToPool("SORCEROR",PLAYER0.max_creatures/5)
AddCreatureToPool("TENTACLE",PLAYER0.max_creatures/5)
AddCreatureToPool("TROLL",PLAYER0.max_creatures/5)

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
--print(Map.map_name)
TutorialFlashButton(3,0)
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 Factionmusic(player,power_kind,power_level,stl_x,stl_y,thing,is_free)
if player.type == "Computer" then return 0 end
--------------------------------------KEEPER/HEROES
if Game.faction[player] == 1 or Game.faction[player] == 2 then
local setfactionmusic = math.random(1,8)
if setfactionmusic == 1 then SetMusic("DK_Alpha1.ogg") end
if setfactionmusic == 2 then SetMusic("DK_Alpha2.ogg") end
if setfactionmusic == 3 then SetMusic("DK_Alpha3.ogg") end
if setfactionmusic == 4 then SetMusic("DK_ConstructionTime.ogg") end
if setfactionmusic == 5 then SetMusic("DK_DownDeep.ogg") end
if setfactionmusic == 6 then SetMusic("DK_GhostlyWaterways.ogg") end
if setfactionmusic == 7 then SetMusic("DK_MysticalTunnels.ogg") end
if setfactionmusic == 8 then SetMusic("DK_SoftFlute.ogg") end
end
--------------------------------------DK2 KEEPER/HEROES
if Game.faction[player] == 3 or Game.faction[player] == 4 then
local setfactionmusic = math.random(1,3)
if setfactionmusic == 1 then SetMusic("DK2_Fortification.ogg") end
if setfactionmusic == 2 then SetMusic("DK2_Malevolence.ogg") end
if setfactionmusic == 3 then SetMusic("DK2_Skirmish.ogg") end
end
--------------------------------------SILENT HILL
if Game.faction[player] == 5 then
local setfactionmusic = math.random(1,4)
if setfactionmusic == 1 then SetMusic("SH_Nightmare.ogg") end
if setfactionmusic == 2 then SetMusic("SH_TheLabyrinth.ogg") end
if setfactionmusic == 3 then SetMusic("SH_thePest.ogg") end
if setfactionmusic == 4 then SetMusic("SH_TownWest.ogg") end
end
--------------------------------------CULTIST
if Game.faction[player] == 6 then
local setfactionmusic = math.random(1,5)
if setfactionmusic == 1 then SetMusic("CULT_Tyranny.ogg") end
if setfactionmusic == 2 then SetMusic("CULT_BloodRitual.ogg") end
if setfactionmusic == 3 then SetMusic("CULT_Domination.ogg") end
if setfactionmusic == 4 then SetMusic("CULT_Invasion.ogg") end
if setfactionmusic == 5 then SetMusic("CULT_Subjugation.ogg") end
end
--------------------------------------
return 0
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
if Game.shrobbie == true then if Game.faction[player] == 5 and player.SH_ROBBIE<1 and player.money<500 then player:add_gold(1) end end

--REMOVE IMP SPELL IF 20
if Game.faction[player] == 1 and player.IMP>19                                      then MagicAvailable(player,"POWER_IMP",false,false) end
if Game.faction[player] == 1 and player.IMP<20                                      then MagicAvailable(player,"POWER_IMP",true,true) end
if Game.faction[player] == 2 and player.TUNNELLER>19                                then MagicAvailable(player,"POWER_IMP",false,false) end
if Game.faction[player] == 2 and player.TUNNELLER<20                                then MagicAvailable(player,"POWER_IMP",true,true) end
if Game.shrobbie == true then if Game.faction[player] == 5 and player.SH_ROBBIE>19  then MagicAvailable(player,"POWER_IMP",false,false) end end
if Game.shrobbie == true then if Game.faction[player] == 5 and player.SH_ROBBIE<20  then MagicAvailable(player,"POWER_IMP",true,true) end 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
        if Game.faction[player] == 5 then if Game.shrobbie == true then AddCreatureToLevel(player,"SH_ROBBIE",c.pos,1,0,"JUMP") end  end
        c:delete()
        end
    end
end
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
function Remove_base_content(player)
--REMOVE ROOM AVAILABILITY
RoomAvailable("ALL_PLAYERS","TREASURE",0,false)
RoomAvailable("ALL_PLAYERS","RESEARCH",0,false)
RoomAvailable("ALL_PLAYERS","PRISON",0,false)
RoomAvailable("ALL_PLAYERS","TORTURE",0,false)
RoomAvailable("ALL_PLAYERS","TRAINING",0,false)
RoomAvailable("ALL_PLAYERS","WORKSHOP",0,false)
RoomAvailable("ALL_PLAYERS","SCAVENGER",0,false)
RoomAvailable("ALL_PLAYERS","TEMPLE",0,false)
RoomAvailable("ALL_PLAYERS","GRAVEYARD",0,false)
RoomAvailable("ALL_PLAYERS","BARRACKS",0,false)
RoomAvailable("ALL_PLAYERS","GARDEN",0,false)
RoomAvailable("ALL_PLAYERS","LAIR",0,false)
RoomAvailable("ALL_PLAYERS","BRIDGE",0,false)
RoomAvailable("ALL_PLAYERS","GUARD_POST",0,false)
--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","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)
CreatureAvailable("ALL_PLAYERS","SCAVENGER_NERVE",false,0)
end
--SILENT HILL STUFF
if Game.shrobbie == 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 if Game.texturepack== true then Texture_pack_function(player) end Add_base_content(player) Switch_heart(player) Factionmusic(player) SetHandGraphic(player,"KEEPER_HAND")
SetDigger(player,"IMP")
CreatureAvailable(player,"BUG",true,0)
CreatureAvailable(player,"FLY",true,0)
CreatureAvailable(player,"SPIDER",true,0)
CreatureAvailable(player,"BILE_DEMON",true,0)
CreatureAvailable(player,"DARK_MISTRESS",true,0)
CreatureAvailable(player,"DEMONSPAWN",true,0)
CreatureAvailable(player,"DRAGON",true,0)
CreatureAvailable(player,"HELL_HOUND",true,0)
CreatureAvailable(player,"MAIDEN",true,0)
CreatureAvailable(player,"ORC",true,0)
CreatureAvailable(player,"SORCEROR",true,0)
CreatureAvailable(player,"TENTACLE",true,0)
CreatureAvailable(player,"TROLL",true,0)
--CHECK CREATURE MODS
if Game.torturer == true then       CreatureAvailable(player,"TORTURER",true,0) end
if Game.scavengereye == true then   CreatureAvailable(player,"SCAVENGER_EYE",true,0) 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 if Game.texturepack== true then Texture_pack_function(player) end Add_base_content(player) Switch_heart(player) Factionmusic(player) SetHandGraphic(player,"HEROES_HAND")
SetDigger(player,"TUNNELLER")
CreatureAvailable(player,"BARBARIAN",true,0)
CreatureAvailable(player,"DRUID",true,0)
CreatureAvailable(player,"DWARFA",true,0)
CreatureAvailable(player,"FAIRY",true,0)
CreatureAvailable(player,"GIANT",true,0)
CreatureAvailable(player,"KNIGHT",true,0)
CreatureAvailable(player,"MONK",true,0)
CreatureAvailable(player,"SAMURAI",true,0)
CreatureAvailable(player,"THIEF",true,0)
CreatureAvailable(player,"TIME_MAGE",true,0)
CreatureAvailable(player,"WITCH",true,0)
CreatureAvailable(player,"WIZARD",true,0)
CreatureAvailable(player,"ARCHER",true,0)
--CHECK CREATURE MODS
if Game.torturer == true then       CreatureAvailable(player,"TORTURER",true,0) end
if Game.scavengereye == true then   CreatureAvailable(player,"SCAVENGER_EYE",true,0) end
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 if Game.texturepack== true then Texture_pack_function(player) end Add_base_content(player) Switch_heart(player) Factionmusic(player) SetHandGraphic(player,"KEEPER_HAND")
--CHECK CREATURE MODS
if Game.torturer == true then       CreatureAvailable(player,"TORTURER",true,0) end
if Game.scavengereye == true then   CreatureAvailable(player,"SCAVENGER_EYE",true,0) end
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 if Game.texturepack== true then Texture_pack_function(player) end Add_base_content(player) Switch_heart(player) Factionmusic(player) SetHandGraphic(player,"")
--CHECK CREATURE MODS
if Game.torturer == true then       CreatureAvailable(player,"TORTURER",true,0) end
if Game.scavengereye == true then   CreatureAvailable(player,"SCAVENGER_EYE",true,0) end
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 if Game.texturepack== true then Texture_pack_function(player) end Add_base_content(player) Switch_heart(player) Factionmusic(player) SetHandGraphic(player,"SILENTHILL_HAND")
if Game.shrobbie == true then       SetDigger(player,"SH_ROBBIE") end
if Game.torturer == true then       CreatureAvailable(player,"TORTURER",true,0) end
if Game.scavengereye == true then   CreatureAvailable(player,"SCAVENGER_EYE",true,0) end
if Game.shschism == true then       CreatureAvailable(player,"SH_SCHISM",true,0) end
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 if Game.texturepack== true then Texture_pack_function(player) end Add_base_content(player) Switch_heart(player) Factionmusic(player) SetHandGraphic(player,"CULTIST_HAND")
if Game.torturer == true then       CreatureAvailable(player,"TORTURER",true,0) end
if Game.scavengereye == true then   CreatureAvailable(player,"SCAVENGER_EYE",true,0) end
return 0
end









