My attempt a making menu like chat script
-- LUA Script - precede every function and global member with lowercase name of script
function chat_init(e)
textlines = {}
textlines[] = {
name = "Hello, how are you today?",
description = "Fine, thank you."
}
textlines[1] = {
name = "Nice weather, is not it?",
description = "Only if you like rain."
}
textlines[2] = {
name = "You are standing in my way.",
description = "That is your problem."
}
textlines[3] = {
name = "Anything new?",
description = "Nope"
}
textlines[4] = {
name = "See you later.",
description = "... Aligator."
}
selected_line = 0
chosen_line = nil
textsize = 2
end
function chat_main(e)
if g_Entity[e]['plrinzone']==1 then
if chosen_line == nil then
offset = 100 - ((#textlines*2)+1+10)
for showline = 0,#textlines,1 do
PromptTextSize(2)
textsize = 2
if showline == math.floor(selected_line) then
PromptTextSize(3)
textsize = 3
end
offset = offset + textsize
TextCenterOnX(50,offset, textsize, textlines[showline].name)
end
key = GetInKey()
if key == "n" then
selected_line = selected_line - 0.05
key = nil
end
if key == "m" then
selected_line = selected_line + 0.05
key = nil
end
if key == "b" then
chosen_line = math.floor(selected_line)
key = nil
end
if selected_line < 0 then
selected_line = 0
end
if selected_line > #textlines then
selected_line = #textlines
end
--PromptTextSize(5)
--Prompt("selected_line: " .. math.floor(selected_line,10) .. " ")
else
PromptTextSize(5)
Prompt("Reply: " .. textlines[chosen_line].description .." " )
end
end
end
use M and N keys to move trough options and use B to select.
I am still puzzled by the coordinates for placing text on screen. Is a screen alway 100x100?
Things to improve:
- have different background image on selecting a current line
- wish there was a onafterkeypressed instead of now pressed not its a bit fidly
- have different colored fonts to show selection
- change to another lua script to continue a different topic
- add a chatglobal.lua and have config vars and functions for display and getting selection there so only textlines are in the lua that is attached to the entity.