there's a guide on steam for basic scripting, i suggest you check that first
http://steamcommunity.com/sharedfiles/filedetails/?id=398177770
after that you will want to get a clear idea of what you want to achieve and then start putting it into script (lua is nice for this because you can literally write it out in a series of 'if' statements and it should be all you need)
so let's go through it
Quote: "the game starts and i can not leave the house before i haven't asnwered a cell phone. the cell phone is on a table and ringing until i pick it up and a sound (bla bla bla) comes and then i can leave the building.
i want the player to solve a puzzle before he can go thru the next door. i would like "rescue 5 hostages" before i can proceed. is it possible to save 5 (or less) people until i am allowed to walk thru the door?"
firstly to block the player leaving the house you need a door or some obstacle right?
so make a script for the door and set in it
--check to see if the phone has been answered
if phone answered == 2 then
end
now this script doesnt do anything yet so we need to decide what happens when the phone has been answered -> 'unlock'
so we will need the main part of the door script for this
--check player wants to open or close the door
if GetInKey() == "e" and pressed == 0 then
--if door is closed open it
if g_Entity[e]['activated'] == 0 then
SetActivated(e,1)
SetAnimation(0)
PlayAnimation(e)
--if door is open then close it
elseif g_Entity[e]['activated'] == 1 then
SetActivated(e,0)
SetAnimation(1)
PlayAnimation(e)
end
--set input to 1 so it only triggers once per press
pressed = 1
end
--reset input so we can press/interact again
if GetScancode() == 0 then
pressed = 0
end
combine this like so
(i've called mine phone_door.lua
--global declarations here for
--user interaction
pressed = 0
--checking the phone state
phone_answered = 0
function phone_door_init(e)
SetActivated(e,0)
end
function phone_door_main(e)
--check to see if the phone has been answered
if phone_answered == 2 then
--check player wants to open or close the door
if GetInKey() == "e" and pressed == 0 then
--if door is closed open it
if g_Entity[e]['activated'] == 0 then
SetActivated(e,1)
SetAnimation(0)
PlayAnimation(e)
elseif g_Entity[e]['activated'] == 1 then
SetActivated(e,0)
SetAnimation(1)
PlayAnimation(e)
end
--set input to 1 so it only triggers once per press
pressed = 1
end
end
--reset input so we can press/interact again
if GetScancode() == 0 then
pressed = 0
end
end
now we require the phone script so...
1. first we need to make the phone ring
2. then we need to check the player is near the phone
3. then we need to check the player has pressed to answer it
4. then we need to check the call has been played (the sound)
5. then we unlock the door
i'll call mine phone.lua
--this script only declaration for
--how long the phone call sound should play (worked out in seconds and multiplied by 1000 to fit GG timers - so 5000 is 5seconds )
local call_duration = 5000
function phone_init(e)
end
function phone_main(e)
--check phone is ringing
if phone_answered == 0 then
LoopSound(e,0) --set the ringing tone as sound 0
--check player is near the phone (change 100 here to distance you require)
if GetPlayerDistance(e) < 100 then
--and has pressed to answer it
if GetInKey() == "e" and pressed == 0 then
--update input
pressed = 1
--stop the ringing as we have answered the phone
StartTimer(e)
StopSound(e,0)
--update phone state to call playing
phone_answered = 1
end
end
elseif phone_answered == 1 then
--check call is playing
if GetTimer(e) < call_duration then
LoopSound(e,1) --set sound of actual call to slot 1 (voice etc)
--if call duration reached then update to next step
else
--stop the sound
StopSound(e,1)
--update the phone state to it's final stage (unlocks the door)
phone_answered = 2
end
end
end
for the next puzzle it's basically the same thing but you will be using different variables
-mainly 1 global for number of hostages saved rather than the phone_answered
give it a go and i'll help if you get stuck
life\'s one big game
windows vista ultimate
i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11