Dream sequence - sleep - help

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
kelly1111
Posts: 349
Joined: Sun Jan 20, 2013 6:28 pm

Dream sequence - sleep - help

Post by kelly1111 »

I was wondering how to pull this of. Or if anyone has something similar writen in script.
I want the players to experience some sort of dream (this can be a text box telling them something or a cuttscene) when they choose to sleep (after a certain point ingame)
When they wake up I want them to be teleported to another place. How would I start doing this?

I have absolutely no clue on how to script it.
User avatar
THOM
Posts: 1281
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Dream sequence - sleep - help

Post by THOM »

There are
PartyComponent.onRest(self)
and
PartyComponent.onWakeUp(self)

I think you can trigger with this a counter (if you want your Event at a random choosen moment) or a script that asks for a certain spot the party ist resting or a certain level...
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Dream sequence - sleep - help

Post by akroma222 »

Yes I did something similar in Labyrinth of Lies
From memory - Spoilers - if you were at position A (anywhere) + did these things:
SpoilerShow
ate a Dozing Cap, then quickly cast Preservation, then made the Party Rest
You would wake up in a secret level, Dreamfields.
You were stuck there until you made the Party Rest again, which would wake you back up in the position A
Ive cut and paste the code from the in dungeon script for you (source files are available so you can load it up yourself too)
Sorry but I dont have the time to rewrite in LoG2 format

dreamscapeScript (position level 1, 19x, y1)
SpoilerShow

Code: Select all

function dreamscapeEntry()
	if not teleCheck.canTeleport() then return false end

	if party.level == 16 then
		hudPrint("You are already in the Dreamfields... ")
		return
	end
	
	if dreamblocker then dreamblocker:destroy() end
	if talismanblocker then talismanblocker:destroy() end

	local d = findEntity("dreamEntrytimer")
	local p = timers:find("timer_preservation")
	local i = timers:find("timer_isolation")
	
	if (d ~= nil and p:isActivated() == true) and (i ~= nil and i:isActivated() == true) then
		blinkgateScript.severGate()
		spawn("blocker", party.level, party.x, party.y, party.facing, "dreamblocker")
		    :activate()
		party:wakeUp(false)
		party:setPosition(2, 1, 2, 16)
		playSoundAt("teleport",party.level,party.x,party.y,0)
		party:playScreenEffect("cold_glow_bless")
		hudPrint("You have entered the Dream Fields... ")
	else
		hudPrint("You can't seem to shift over to the dreaming world...")
	end
	if d then d:destroy() end
end
		
function frostcapsleep(item, champion)
	if timers:find("frostcapsleeptimer") ~= nil then
		timers:find("frostcapsleeptimer"):destroy()
	end
	hudPrint("The frozen mushroom makes you all feel very drowsy....")
	timers:create("frostcapsleeptimer")
        :setTimerInterval(8)
		:setConstant()
        :addConnector("activate", "dreamscapeScript", "sleepCap")
		:activate()
	return true
end

function sleepCap(t)
	t:destroy()
	
	local d = timers:find("dreamEntrytimer")
	if d then d:destroy() end
	
	local p = timers:find("timer_preservation")
	local i = timers:find("timer_isolation")
	
	hudPrint("The frozen mushroom puts you all into a deep sleep....")
	if p == nil or i == nil then
		party:rest()
	else
		spawn("timer", party.level, party.x, party.y, party.facing, "dreamEntrytimer")
       		:setTimerInterval(5)
        	:addConnector("activate", "dreamscapeScript", "dreamscapeEntry")
			:activate()
		party:rest()
	end
end

function returnfromDream()
	if party.level == 16 and not wakeTimer then
		if talismanblocker then
			spawn("timer", party.level, party.x, party.y, party.facing, "wakeTimer")
	       		:setTimerInterval(5)
	        	:addConnector("activate", "dreamscapeScript", "wake1")
				:activate()
		elseif dreamblocker then
			spawn("timer", party.level, party.x, party.y, party.facing, "wakeTimer")
	       		:setTimerInterval(5)
	        	:addConnector("activate", "dreamscapeScript", "wake2")
				:activate()
		end
	end
	return true
end

-- so canceling sleep doesn't screw everything up
function onWakeUp()
	if dreamEntryTimer then dreamEntryTimer:destroy() end
	if wakeTimer then wakeTimer:destroy() end
end
		
function wake1()
	if party.level == 16 then
		local t = findEntity("talismanblocker")
		if not t then return end
		party:wakeUp(false)
		party:setPosition(t.x, t.y, t.facing, t.level)
		playSound("teleport")
		party:playScreenEffect("cold_glow_bless")
		hudPrint("You awaken back into the Labyrinth...")
		t:destroy()
	end
end


function wake2()
	if party.level == 16 then
		local b = findEntity("dreamblocker")
		if not b then return end
		party:wakeUp(false)
		party:setPosition(b.x, b.y, b.facing, b.level)
		playSound("teleport")
		party:playScreenEffect("cold_glow_bless")
		hudPrint("You awaken back into the Labyrinth...")
		b:destroy()
	end
end
	
function dreamweaverEntry(item, champion)
	if not teleCheck.canTeleport() then return false end
	if party.level == 16 then
		hudPrint("You cannot invoke the Talisman to enter The Dreamfields if you are already here...")
	else
		blinkgateScript.severGate()
		if talismanblocker then talismanblocker:destroy() end
		spawn("blocker", party.level, party.x, party.y, party.facing, "talismanblocker")
	   		:activate()
		party:setPosition(4, 25, 2, 16)
		playSoundAt("teleport",party.level,party.x,party.y,0)
		party:playScreenEffect("cold_glow_bless")
		hudPrint("The Dreamweavers return again...")
	end
	return false
end

function severGate()
	local b = talismanblocker or dreamblocker
	if b then
		party:setPosition(b.x, b.y, b.facing, b.level)
		b:destroy()
		hudPrint("You are jolted back to the waking world.")
	end
end
also minmay wrote some fixer scripts (found on level 1 also) - timers 31x,16y - but I dont think we need timers now with LoG2 modding
and also teleCheck 31x, 19y - which stops some teleporting loop hole abuse
SpoilerShow

Code: Select all

-- this is a silly workaround to prevent getting yourself stuck in
-- the shadowgate maze or locking yourself out of the ending
function canTeleport()
	-- teleporting while falling down a pit on the upper level is
	-- bad; they will end up on the teleport position on the next
	-- level. needless to say, there are tons of ways to abuse this
	-- or simply get stuck in a wall, so we prevent it.
	-- teleporting after falling into the new level is okay, though
	-- (and not prevented)
	if falling() then
		hudPrint("You can't teleport while falling down a pit!")
		return false
	end
	if shadowgateTimer_1:isActivated() or
	shadowgateTimer_2:isActivated() or
	shadowgateTimer_3:isActivated() or
	shadowgateTimer_4:isActivated() then
		hudPrint("A mysterious force suppresses your teleportation magic inside the Shadowgate maze.")
		return false
	end
	if party.level == 1 then
		hudPrint("The dimensional rifts on this level prevent your teleportation magic.")
		return false
	end
	if party.level == 15 and party.x >=6 and ((party.x <= 11 and party.y <=5) or (party.x <= 14 and party.y <=3)) then
		hudPrint("Some malevolent force prevents you from teleporting out of the hive!")
		return false
	end
	return true
end

function falling()
	for i in fix.newEntitiesAt(party.level,party.x,party.y) do
		if i.class == "Pit" then
			if i:isOpen() then
				return true
			else
				break
			end
		end
	end
	return false
end
Hope this helps (and isnt too confusing lol)
Akroma
User avatar
LordGarth
Posts: 500
Joined: Mon Jun 18, 2012 5:07 pm
Location: Colorado USA

Re: Dream sequence - sleep - help

Post by LordGarth »

Could a dream script be activated when the party is awake and used for cinematics.

Just a thought

LordGarth
Dungeon Master and DOOM will live forever.
Post Reply