I went ahead and made a test project and ironed out a few kinks. Here's my final version:
dim PlayerName
PlayerName = "John"
Sub Player_OnSpecialFunction(SpecialObj)
If SpecialObj.FuncType = 7 AND len(SpecialObj.Value) >= 7 AND left(SpecialObj.Value,7) = "#COND" + vbcrlf Then
dim tmp, msg
tmp = mid(SpecialObj.Value,8)
Execute(tmp)
ShowMessage(msg)
End if
End Sub
Sub ShowMessage(msg)
msg = Replace(msg,"%PLAYER%",PlayerName) 'Insert Players name where appropriate
dim msgSpecial, old
Set msgSpecial = NewSpecialFunction
msgSpecial.funcType = 1
msgSpecial.Value = msg
old = HostObj.ScriptTimeoutSeconds
HostObj.ScriptTimeoutSeconds = 0
ProjectObj.GamePlayer.ActivateFunction(msgSpecial)
HostObj.ScriptTimeoutSeconds = old
End Sub
Sub Player_OnPlayInit()
dim tmp
for i = 0 to ProjectObj.MapCount - 1
for j = 0 to ProjectObj.Maps(i).SpecialCount - 1
set tmp = ProjectObj.Maps(i).Specials(j)
if tmp.FuncType = 1 AND len(tmp.Value) >= 5 AND left(tmp.value,5) = "#COND" Then
tmp.FuncType = 7
tmp.Flags = tmp.Flags OR 8 'INTFL_RAISEEVENT
end if
next
next
End Sub
HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16
And the code inside the special function:
#COND
dim FOUNDRING
FOUNDRING = ProjectObj.GamePlayer.InvQuantityOwned(0)
select case FOUNDRING
case 0
msg = "Oh woe is me, I have lost my wedding ring! Who are you? %PLAYER%? Can you help me find my ring, %PLAYER%?"
case 1
msg = "You found it! Thank you so much."
ProjectObj.GamePlayer.InvQuantityOwned(0) = 2
case else
msg = "Thanks again for finding my ring, %PLAYER%!"
end select
In the script, I changed the script timeout to 0 while showing the message so the script doesn't timeout if the player looks at it for more than two seconds. I also changed an IF to check for the right function type in OnSpecialFunction since it changes in OnPlayInit. I also took the liberty of adding a Raise Event flag to all of the messages so even if you forget to put them in during design time it will put them in during runtime. Finally, I added another IF in the OnSpecialFunction to make sure that the value is at least 7 characters long before trying to take the first 7 of them.
In the GUI code, I didn't do much. I just renamed the variable to FOUNDRING since that's all that variable can account for. I also automatically added 1 to it after displaying the initial "You found it" message, so that it will display the "Thanks again" message any subsequent times.
As for your line break, if you want a line break in the message, do something like:
msg = "First line of the message" + vbcrlf + "Second line of the message
Or
msg = "First line of the message" + vbcrlf + _
"Second line of the message
Which does the same thing but is easier to read. The vbcrlf stands for VB Carriage Return Line Feed, which is basically the fancy Windows way of saying New Line.