Hello,
WARNING: I am French: I translated this tutorial Google translation; sorry if this tutorial has some translation errors.
I have a script designed to display an image and a sound (eg someone who reads a text) over a period of X seconds (depends on the sounds).
I helped myself script door.lua.
However, not being an expert in this LUA he can half the script is useless =P
So if you want to improve you are welcome ^^
How it work?
1 - Copy the code below and paste it into a text file with name "book.lua" :
CAUTION: Do not put in your code "< br >" tags !!!
livre2_pressed = 0
function book_init(e)
LoadImages("book",0)
end
function book_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 250 then
if g_Entity[e]['activated'] == 0 then
if g_Entity[e]['haskey'] == -1 then
SetActivated(e,1)
else
if g_Entity[e]['haskey'] == 1 then
Prompt("Press E to read the book")
if g_KeyPressE == 1 then
SetActivated(e,1)
end
else
Prompt("...")
end
end
else
if g_Entity[e]['activated'] == 1 then
Prompt("Press E to read the book")
if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and livre2_pressed == 0 then
g_Entity[e]['animating'] = 1
SetActivated(e,2)
ActivateIfUsed(e)
SetImagePosition(50,50)
ShowImage(0)
PlaySound(e,0)
FreezePlayer(0)
StartTimer(e)
livre2_pressed = 1
end
else
if g_Entity[e]['activated'] == 2 then
-- Timer... (ex : 8000 = 8 seconds)
if GetTimer(e)>8000 then
--HideImage(0)
Prompt("This book has already been read...")
HideImage(0)
UnFreezePlayer(0)
end
if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and livre2_pressed == 0 then
g_Entity[e]['animating'] = 1
SetActivated(e,1)
livre2_pressed = 1
end
end
end
end
end
if g_KeyPressE == 0 then
livre2_pressed = 0
end
end
Consider changing the following line :
It determines the time the Timer (example: 8000 = 8 seconds 50000 = 50 seconds, etc.)
2 - In "GameGuru\Files\scriptbank\images\" create a new folder called "book". Design your image (such as an open book) and save it in "GameGuru\Files\scriptbank\images\book\" and name it "000.png"
The image should not exceed 1024X768.
3 - Record yourself reading your text on the image and save your sounds under "GameGuru\FIles\AudioBank\music\" and name your file, for example "book_read.wav."
4 - In GameGuru: place a 3D object (book or other) and turn it into Dynamics. Associate the script "book.lua" and sounds "book_read.wav."
5 - In the game when you press the "E" key on your keyboard the 000.png image will be displayed along with the sounds associated with the object. During this time the player has more control over the game (it's Freeze). When the Timer happen by itself the number in the script "book.lua" then the image will remove and the player will again shake (UnFreeze). Then the message that the book has been read will be displayed.
I hope that you enjoy it and share feel free to improve it because there's work ... x'D
Good development at all!