|
Poo Bear Pod Team


Joined: 14 Oct 2002 Posts: 4121 Location: Sheffield, UK

|
Posted: Thu Dec 20, 2007 9:59 am Post subject: h1r1 - the first room |
|
|
Here is the lua script for the first room in the game
Note - x = room width (left=0 to right), y = room height (bottom=0 to top), z = room length (front=0 to back). You can work out coordinates using the editor by selecting a single square tile and moving it around the room and reading off the coordinates displayed.
Code: |
-- asimov is frozen, effect plays on his head, he wakes up, hel tells him to get to work,
-- player gets control
-- definitions - these are unchanging "names" for the different states this room can get in
INTRO_EFFECT = 0
START_CONV = 1
WAIT_CONV_FINISH = 2
DOWNLOAD = 3
-- globabls - these values will be set when we enter the room and then we'll change
-- them as things happen, if we leave the room and walk back in they'll reset to these values again
g_timer = 0
g_state = DOWNLOAD
--a function called sequence is always called if we're new to the room
--it will keep being called over and over while we are in the room
function sequence()
if( g_state == DOWNLOAD ) then
--stop him and wait a tiny bit
closeDoor( 0, true ) -- close the door straight away, do it instantly
overrideAsimov( true ) -- stop the player moving around
-- grab a dummy robot in the room and make it walk from xz1->xz2->xz3 and back again
sendMessage( "h1r1dummy", "SYSTEM", "WANDER", "2,0,7,0,7,8" )
g_state = INTRO_EFFECT -- switch to the next state next time this function runs
g_timer = getTime() -- setup a timer
elseif( g_state == INTRO_EFFECT ) then
if( not timerExpired( 500, g_timer ) ) then
return false -- wait around a bit, no rush
end
--play an effect on his head
Asimov = getDynamicObject( "PLAYER" ) -- grab the player object
x, y, z = getDisplayPos( Asimov ) -- work out where it is
y = y + 0.85 -- go above it slightly
launchEffectSimple( x, y, z, "asimov_brain_download" ) -- play a little sparkly effect
g_state = START_CONV
g_timer = getTime()
elseif( g_state == START_CONV ) then
-- wait for the effect to finish
if( not timerExpired( 3000, g_timer ) ) then
return false
end
-- play a conversation
name = "T01_asimov_wakeup"
playConversation( name )
g_state = WAIT_CONV_FINISH
elseif( g_state == WAIT_CONV_FINISH ) then
-- when the conversation finishes release asimov
if( isConversationActive() ) then
return false
end
overrideAsimov( false )
openDoor( 0, false ) -- open the door slowly
return true
end
return false
end
-- when sequence returns true the game remembers and then starts calling
-- completed instead, use this to keep things tidy after the room is finished with
function completed()
if( g_state == DOWNLOAD ) then -- remember our state variable will reset when we leave and come back
-- getKeyVal and saveKeyVal are a way for scripts to save bits of text permanently
-- and let other scripts check them later. In this case we are checking for some major event happening
-- later in the game that means all the robots should have gone
if( getKeyVal( "z1r17" ) == "main_objective" ) then
sendMessage( "h1r1dummy", "SYSTEM", "DISABLE", "" ) -- stop that dummy robot doing stuff
sendMessage( "h1r1dummy", "SYSTEM", "SHOW", "FALSE" ) -- make it vanish
else
sendMessage( "h1r1dummy", "SYSTEM", "WANDER", "2,0,7,0,7,8" ) -- otherwise make sure it keeps wandering about
end
openDoor( 0, true ) -- make sur ethe door stays open, do it fast
-- put us into any other state just so we stop running this bit of code
g_state = INTRO_EFFECT
end
return true
end |
Does this help anyone or just add to the confusion  |
|
|