Here's a branching conversation script. I haven't included any notations, but it's pretty easy to follow. The reason I chose keys "m" and "n" to make choices was because 1 & 2 are used to switch weapons and "a" is used to strafe left.
I wanted to include sound, but the PlaySound command didn't work as I wanted it to, so I left it out.
local convo = {}
local timer = {}
local timed = {}
local started = {}
local response = {}
function conversation_init(e)
Include("ai_cover.lua")
convo[e] = 0
timer[e] = 0
timed[e] = 0
started[e] = 0
response[e] = 0
end
function conversation_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist < 150 then
RotateToPlayer(e)
if convo[e] == 0 then
PromptDuration("Masked man : Hello, what can I do for you?",2000)
if timer[e] == 0 then
timed[e] = GetTimer(e)
timer[e] = 1
end
if GetTimer(e) > timed[e] + 3000 then
convo[e] = 1
timer[e] = 0
end
end
if convo[e] == 1 then
TextCenterOnX(50,84,3,"m- not much, you seem fairly useless")
TextCenterOnX(50,87,3,"n- ooh, all sorts of things!")
if g_InKey == "m" then
convo[e] = 100
timer[e] = 0
timed[e] = 0
response[e] = 1
elseif g_InKey == "n" then
convo[e] = 100
timer[e] = 0
timed[e] = 0
response[e] = 2
end
end
if convo[e] == 21 then
TextCenterOnX(50,84,3,"m- I may be rude, but your face looks like a monkey climbing down your shirt head first")
TextCenterOnX(50,87,3,"n -Sorry, I can't help myself")
if timer[e] == 0 then
timed[e] = GetTimer(e)
timer[e] = 1
end
if GetTimer(e) > timed[e] + 500 then
if g_InKey == "m" then
convo[e] = 100
timer[e] = 0
timed[e] = 0
response[e] = 3
elseif g_InKey == "n" then
convo[e] = 100
timer[e] = 0
timed[e] = 0
response[e] = 4
end
end
end
if convo[e] == 22 then
TextCenterOnX(50,84,3,"m- Could you give me some money?")
TextCenterOnX(50,87,3,"n- Could you scratch my back for me?")
if timer[e] == 0 then
timed[e] = GetTimer(e)
timer[e] = 1
end
if GetTimer(e) > timed[e] + 500 then
if g_InKey == "m" then
convo[e] = 100
timer[e] = 0
timed[e] = 0
response[e] = 5
elseif g_InKey == "n" then
convo[e] = 100
timer[e] = 0
timed[e] = 0
response[e] = 6
end
end
end
if response[e] == 1 then
PromptDuration("Masked man : Well now, that's very rude!",3000)
if timer[e] == 0 then
timed[e] = GetTimer(e)
timer[e] = 1
end
if GetTimer(e) - timed[e] > 3000 then
convo[e] = 21
response[e] = 0
end
end
if response[e] == 2 then
PromptDuration("Masked man : What sort of thing would you like me to do?",3000)
if timer[e] == 0 then
timed[e] = GetTimer(e)
timer[e] = 1
end
if GetTimer(e) - timed[e] > 3000 then
convo[e] = 22
response[e] = 0
end
end
if response[e] == 3 then
PromptDuration("Masked man : I'm afraid I'm going to have to kill you",3000)
if timer[e] == 0 then
timed[e] = GetTimer(e)
timer[e] = 1
end
if GetTimer(e) - timed[e] > 2000 then
SwitchScript(e,"ai_cover")
response[e] = 0
end
end
if response[e] == 4 then
PromptDuration("Masked man : Okay then, goodbye", 3000)
response[e] = 0
end
if response[e] == 5 then
PromptDuration("Masked man : I don't like beggars, be off with you!", 3000)
response[e] = 0
end
if response[e] == 6 then
PromptDuration("Masked man : Umm, well...er......no, goodbye", 3000)
response[e] = 0
end
end
end