I maked script, that show message part by part with timeline (e.g., it can be used in something like subtitles).
It provide function MessagePrompt(message, timings).
E.g.
require "scriptbank/common"
function zone_main(e)
MessagePrompt("line1\nline2\nline2", {5,5,5})
Destroy(e)
end
will show every line (line1,line2,line3) for 5 seconds.
At first, it need all-time existsing entity (I used trigger) with attached script:
require "scriptbank/common"
function message_timer_init(e)
g_MessageTimer = e
end
function message_timer_main(e)
MessagePromptContinue()
end
In "scriptbank/common.lua" i have next code:
--
-- Split string by divider
--
function Explode(div,str)
if (div=='') then return false end
local pos,arr = 0,{}
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1))
pos = sp + 1
end
table.insert(arr,string.sub(str,pos))
return arr
end
messagePromptLines = {} -- stores exploded message parts
messagePromptTimings = {} -- times "timeline"
messageCurrent = 1 -- part for showing
--
-- Show your message
--
function MessagePrompt(message, timings)
messagePromptLines = Explode("\n", message)
messagePromptTimings = timings
messageCurrent = 1
MessagePromptContinue()
end
--
-- Inner function, that show message parts
--
function MessagePromptContinue()
-- If not all parts of message showed now
if messageCurrent <= #messagePromptLines then
-- get information about next part
local text = messagePromptLines[messageCurrent]
local duration = messagePromptTimings[messageCurrent]
-- creating timer
local entity = aEntity:new(g_MessageTimer)
local timer = aTimer.for_e(entity, duration)
-- if timer not started (message part not shown)
if not timer:running() then
timer:start() -- start it
PromptDuration(text, duration*1000) -- show message part
end
-- if timer runned, but
if timer:running() and timer:left()==0 then
messageCurrent = messageCurrent + 1 -- go to next part
timer:stop() -- stop timer
end
end
end
Also, it's need
Avram's FPSC:R Toolkit