---------------------------------------------------------------------------------------------
function createQuestRescueGateKeeper()
	--local randomgatekeeper = math.random(1,3)
	randomgatekeeper = math.random(1,3)
	
	
	if randomgatekeeper == 1 then
		Logic.SetEntityName(Logic.CreateEntity(Entities.PU_Scout, GetPosition("gatekeeper1").X, GetPosition("gatekeeper1").Y, 270, 5),"gateKeeper")
	elseif randomgatekeeper == 2 then
		Logic.SetEntityName(Logic.CreateEntity(Entities.PU_Scout, GetPosition("gatekeeper2").X, GetPosition("gatekeeper2").Y, 225, 5),"gateKeeper")
		local Kepper = GetID("keyKeeper")
		local firstguard = GetID("guard1")
		--local secondguard = GetID("guard2")
		Logic.SetEntityName(Kepper, nil)
		Logic.SetEntityName(firstguard, "keyKeeper")
		--Logic.SetEntityName(secondguard, _entityName)
		Logic.SetEntityName(Kepper, "guard1")
	else
		Logic.SetEntityName(Logic.CreateEntity(Entities.PU_Scout, GetPosition("gatekeeper3").X, GetPosition("gatekeeper3").Y, 315, 5),"gateKeeper")
		local Kepper = GetID("keyKeeper")
		--local firstguard = GetID("guard1")
		local secondguard = GetID("guard2")
		Logic.SetEntityName(Kepper, nil)
		--Logic.SetEntityName(firstguard, "keyKeeper")
		Logic.SetEntityName(secondguard, "keyKeeper")
		Logic.SetEntityName(Kepper, "guard2")
	end

    StartSimpleJob("controlRescueGateKeeper",randomgatekeeper)

    end
---------------------------------------------------------------------------------------------
function controlRescueGateKeeper(_gatekeepernumber)

    for i = 1,6,1 do

        local name = "gateTower".._gatekeepernumber..i

        if IsDead(name) == false then

            return false

            end

        end

    if (_gatekeepernumber == 1 and IsDead(armyCamp2) == false) or  (_gatekeepernumber == 2 and IsDead(thirdcamp) == false) or (_gatekeepernumber == 3 and IsDead(armyCamp3) == false)  then

        return false

        end

    --DestroyNPC(npcKeyKeeper)
	NPCKeyKapperSwap = true

    DestroyEntity("jail".._gatekeepernumber)

    --Move("gateKeeper","keyKeeper",1000)

    createBriefingKeyKeeper_GateKeeperIsOnTheWay()

    createBriefingGateKeeper()

    return true

    end
