Thanks Bruce.
@ mayo76
Quote: " do you use keyword-sequences to get the responses or is it enough to call the right words without any order? i really would be interested in seeing the scripts"
The first thing you have to do is setup stuff for the game engine to have. This might end up being the most complicated part of scripting. The information derived from this script is placed in either arrays or custom variable types within the game engine.
The following is not necessarily a tutorial but just to give you (or anybody else who is interested) an idea of how this needs to be scripted.
To answer your first question from above. It is based on keywords but they do not have to be in sequence. You can make as many keywords as possible. The more keywords the more difficult for the player. My belief is to make things a little more easier for the player in the beginning. And as you continue with the game you can start making things more difficult. So, let's take when the janitor confronts the player asking him what he's doing there. During the conversation with Bob and the Professor (see the video Part 1) they agreed to pose as a telphone repairman. I had only two basic keywords in the response with variations of those two keywords. Here is the script to let the engine know what the keywords are:
:rpg_newplayerinput:rpg_playerinput_numberseq=1,rpg_playerinput_chatnumber=14,rpg_playerinput_keywords=telephone-phone-repairman-bt-engineer,rpg_playerinput_totalnumbercanmatch=5,rpg_playerinput_minimumnumbercanmatch=2,rpg_playerinput_keywordsmustmatch=telephone|phone|bt-repairman|engineer
Here are the keywords outside of the above code as the above is confusing to look at.
rpg_playerinput_keywords=
telephone-phone-repairman-bt-engineer
As I said this is not a tutorial; but, if you have experience as a programmer, you should kind of get the idea of some of the data that is needed.
For conversations you need to set up the text that is involved with the conversation. The following is that setup for the janitor, receptionist, and young security guard. As you peruse through the text you will notice not all of it is used in the example video. That's because there are more than one outcome.
:rpg_newcharacter:rpg_char_name=Janitor1,rpg_char_chatnumber=45,rpg_char_text=PROFESSOR| Say~ before you do that~ I was just wondering. People are talking -- that there have been some strange things going on in this building. Have you seen or heard anything~ you know~ strange or wierd?.,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=Janitor1,rpg_char_chatnumber=46,rpg_char_text=PROFESSOR| Do you think I could take a look at it?,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=Janitor1,rpg_char_chatnumber=47,rpg_char_text=JANITOR| No~ that's too low. I would like~ say~ 75?,rpg_char_chattype=4
:rpg_newcharacter:rpg_char_name=Janitor1,rpg_char_chatnumber=48,rpg_char_text=JANITOR| How about 65?,rpg_char_chattype=4
:rpg_newcharacter:rpg_char_name=Janitor1,rpg_char_chatnumber=49,rpg_char_text=JANITOR| Well~ what about 55? I won't go any lower!,rpg_char_chattype=4
:rpg_newcharacter:rpg_char_name=Janitor1,rpg_char_chatnumber=50,rpg_char_text=JANITOR| OK! I'll let you have it for that much!,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=Janitor1,rpg_char_chatnumber=51,rpg_char_text=JANITOR| They buzzed the door open so you can go in now.,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=receptionist1,rpg_char_chatnumber=52,rpg_char_text=RECEPTIONIST| If you've come to fix the phones~ then how may I help you?,rpg_char_chattype=2
:rpg_newcharacter:rpg_char_name=receptionist1,rpg_char_chatnumber=53,rpg_char_text=RECEPTIONIST| If you have nothing to say~ then we cannot help you! If you would kindly leave.,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=receptionist1,rpg_char_chatnumber=54,rpg_char_text=RECEPTIONIST| That's quite alright. Is there anything more?,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=Janitor1,rpg_char_chatnumber=55,rpg_char_text=JANITOR| Sorry~ that was your last chance! Now~ don't bother me anymore!,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=Janitor1,rpg_char_chatnumber=56,rpg_char_text=PROFESSOR| Wait! What about the door!?,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=Bob2,rpg_char_chatnumber=57,rpg_char_chattype=5
:rpg_newcharacter:rpg_char_name=Bob2,rpg_char_chatnumber=58,rpg_char_text=Bob| I believe there is a connection between the symbols on the four separate buttons that are to my right -- your left -- and the block symbols in the jail cell.,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=Bob2,rpg_char_chatnumber=59,rpg_char_text=Bob| I don't believe that will help us get out of here.,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=Janitor1,rpg_char_chatnumber=60,rpg_char_text=JANITOR| I'm sorry you changed your mind. Are you Sure?,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=Janitor1,rpg_char_chatnumber=61,rpg_char_text=JANITOR| I can't accept that. I need cash for the note.,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=Janitor1,rpg_char_chatnumber=62,rpg_char_text=JANITOR| Oh~ sorry. I forgot! They buzzed the door open so you can go in now,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=receptionist1,rpg_char_chatnumber=63,rpg_char_text=RECEPTIONIST| I'm not sure I understand what you are trying to say!,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=receptionist1,rpg_char_chatnumber=64,rpg_char_text=RECEPTIONIST| I'm not sure what phones are not working. The one on my desk is not working. There is also a phone on the wall and there are phones throughout the various offices. ,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=receptionist1,rpg_char_chatnumber=65,rpg_char_text=RECEPTIONIST| Please stay where you are! I'm getting security!,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=SG2,rpg_char_chatnumber=66,rpg_char_text=Security Guard| Sir~ you'll need to come with me.,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=receptionist1,rpg_char_chatnumber=67,rpg_char_text=RECEPTIONIST| Again~ how may I help you?,rpg_char_chattype=2
:rpg_newcharacter:rpg_char_name=receptionist1,rpg_char_chatnumber=68,rpg_char_text=RECEPTIONIST| One last time~ how may I help you?,rpg_char_chattype=2
:rpg_newcharacter:rpg_char_name=DP2,rpg_char_chatnumber=69,rpg_char_text=PROFESSOR| There ya go. Your phone's fixed. I'll put the phone back on the cradle for ya.,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=SG2,rpg_char_chatnumber=70,rpg_char_text=SECURITY GUARD| I've been watching you. You haven't fixed any phones! I'm not sure you're a phone repairman!,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=SG2,rpg_char_chatnumber=71,rpg_char_text=SECURITY GUARD| I've been watching you. You've only fixed one phone! What are you really doing here?,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=SG2,rpg_char_chatnumber=72,rpg_char_text=SECURITY GUARD| I'm sorry but I can't let you go through this door.,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=SG2,rpg_char_chatnumber=73,rpg_char_text=SECURITY GUARD| You think waving that wand around will do something? It won't work on me~ professor.,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=SG2,rpg_char_chatnumber=74,rpg_char_text=SECURITY GUARD| What are you doing!?,rpg_char_chattype=1
:rpg_newcharacter:rpg_char_name=SG2,rpg_char_chatnumber=75,rpg_char_text=PROFESSOR| Sir~ you can now open the door for me so I can repair the rest of the phones.,rpg_char_chattype=1
There are actually four chat types:
* talkBox (1) - standard
* talkBoxquestion (2) - When character asks a question that needs a response from the player
* talkBoxsellitem (3) - when player wants to sell an item to a character
* talkBoxbuyitem (4) - when the player is negotiating buying an item from a character
Most of the Chat types above are #1 OR #2. However, there is one that is a chat type of #4.
Now for those who are programmer, the following is the code that I used to take input and then check all the keywords. Of course those who are not programmers need to look at it to see that you didn't have to code this. So be sure and check the actually script. that follows this code.
center text 512,730,"Would you like to respond?"
yesnoresult = yesnoprompt("arial","16","750")
if yesnoresult = 21 and rpg_numberplayerinput > 0
rpg_yesnoresult = 1
for i = 0 to rpg_numberplayerinput - 1
sTemp = rpg_playerinput(i).chatnumber$
pos = find first char$(sTemp,"|")
if pos > 0
temp$ = first token$(sTemp,"|")
if len(temp$) > 0
temp$ = removeedgespaces(temp$)
if val(temp$) = currentchatnumber
array insert at bottom playerinputnumber()
playerinputnumber() = rpg_playerinput(i).playerinputnumber
`exit
endif
endif
if not foundplayerinput
repeat
temp$ = next token$("|")
if len(temp$) > 0
temp$ = removeedgespaces(temp$)
if val(temp$) = currentchatnumber
array insert at bottom playerinputnumber()
playerinputnumber() = rpg_playerinput(i).playerinputnumber
endif
endif
until temp$ = ""
endif
else
if len(sTemp) > 0
temp$ = removeedgespaces(sTemp)
if val(temp$) = currentchatnumber
array insert at bottom playerinputnumber()
playerinputnumber() = rpg_playerinput(i).playerinputnumber
endif
endif
endif
next i
pos = 0
array index to top playerinputnumber()
ycoord3 = 725 : ycoord2 = 0 : ycoord1 = 725 : question$ = "" : prompt1$ = "You may type in your response now:" : prompt2$ = ""
boxleft = 50 : boxright = 950
InputString$ = playerinput(question$,prompt1$,promtp2$,ycoord1,ycoord2,ycoord3,boxleft,boxright)
`
for i = 0 to array count( playerinputnumber() )
`if foundplayerinput
usethisplayerinput = playerinputnumber(i) - 1
allmustbecorrect = 1
kw$ = rpg_playerinput(usethisplayerinput).keywords$
totalnumbercanmatch = rpg_playerinput(usethisplayerinput).totalnumbercanmatch
minimumnumbercanmatch = rpg_playerinput(usethisplayerinput).minimumnumbercanmatch
kwmustmatch$ = rpg_playerinput(usethisplayerinput).keywordsmustmatch$
ii = 0
if len(kw$) > 0
firstchar = find first char$(kw$,"-")
if firstchar > 0
kwtoken$ = lower$(first token$(kw$,"-"))
iii=0
bFoundKeyWord = 0
repeat
temp2$ = split$(inputstring$," ",iii)
temp2$ = rpg_trimrightstring(temp2$)
if lower$(kwtoken$) = lower$(temp2$)
bFoundKeyWord = 1
exit
endif
inc iii
until temp2$ = ""
`
if bFoundKeyWord
ii = ii + 1
correct$ = kwtoken$
else
correct$ = ""
endif
`
repeat
kwtoken$=lower$(next token$("-"))
bFoundKeyWord = 0
iii=0
repeat
temp2$ = split$(inputstring$," ",iii)
temp2$ = rpg_trimrightstring(temp2$)
if lower$(kwtoken$) = lower$(temp2$)
bFoundKeyWord = 1
exit
endif
inc iii
until temp2$ = ""
if bFoundKeyWord
ii = ii + 1
if len(correct$) > 0
correct$ = correct$ + "," + kwtoken$
else
correct$ = kwtoken$
endif
endif
until kwtoken$=""
`
if right$(correct$,1) = ","
temp2$ = ""
for iii = 1 to len(correct$) - 1
temp2$ = temp2$ + mid$(correct$,iii)
next iii
correct$ = temp2$
ii = ii - 1
endif
`
if totalnumbercanmatch = ii
correctanswer = 1
currentplayerinputnumber = rpg_playerinput(usethisplayerinput).playerinputnumber
exit
else
if minimumnumbercanmatch > 0
if ii < totalnumbercanmatch
if ii >= minimumnumbercanmatch
if len(kwmustmatch$) > 0
ii = 0
kwtoken$ = ""
kwtoken$ = lower$(first token$(kwmustmatch$,"-"))
firstchar = find first char$(kwtoken$,"|")
if firstchar > 0
keywordcorrect = check4orvalues(kwtoken$,lower$(correct$))
if not keywordcorrect then allmustbecorrect = 0
else
`
iii=0
bFoundKeyWord = 0
repeat
temp2$ = split$(correct$,",",iii)
temp2$ = rpg_trimrightstring(temp2$)
if lower$(kwtoken$) = lower$(temp2$)
bFoundKeyWord = 1
exit
endif
inc iii
until temp2$ = ""
if not bFoundKeyWord then allmustbecorrect = 0
endif
`
if not allmustbecorrect
repeat
kwtoken$=lower$(next token$("-"))
if len(kwtoken$) > 0
firstchar = find first char$(kwtoken$,"|")
if firstchar > 0
keywordcorrect = check4orvalues(kwtoken$,lower$(correct$))
if not keywordcorrect then allmustbecorrect = 0
else
iii=0
bFoundKeyWord = 0
repeat
temp2$ = split$(correct$,",",iii)
temp2$ = rpg_trimrightstring(temp2$)
if lower$(kwtoken$) = lower$(temp2$)
bFoundKeyWord = 1
exit
endif
inc iii
until temp2$ = ""
`
if not bFoundKeyWord then allmustbecorrect = 0
endif
endif
until kwtoken$=""
endif
`
if allmustbecorrect = 1
correctanswer = 1
currentplayerinputnumber = rpg_playerinput(usethisplayerinput).playerinputnumber
exit
endif
else
correctanswer = 1
currentplayerinputnumber = rpg_playerinput(usethisplayerinput).playerinputnumber
exit
endif
endif
endif
endif
endif
else
if lower$(kw$) = lower$(InputString$)
correctanswer = 1
currentplayerinputnumber = rpg_playerinput(usethisplayerinput).playerinputnumber
exit
endif
endif
endif
next i
if correctanswer = 1
for i = 0 to array count( entityelement() )
if lower$(charname$) = lower$(entityelement(i).eleprof.name$)
entityelement(i).rpg_answercorrect = 1
entityelement(i).rpg_usedquestion = 1
entityelement(i).rpg_currentplayerinputnumber = currentplayerinputnumber
entityelement(i).rpg_noanswer = 0
exit
endif
next i
endif
else
for i = 0 to array count( entityelement() )
if lower$(charname$) = lower$(entityelement(i).eleprof.name$)
exit
endif
next i
if yesnoresult = 49
entityelement(i).rpg_noanswer = 1
rpg_yesnoresult = 49
wait 100
else
entityelement(i).rpg_noanswer = 0
endif
endif
inputpositionmouse(screen width()/2,(screen height()/4)*3.5)
cleardelta=mousemovex() : cleardelta=mousemovey()
set text transparent
set text to normal
ink rgb(255,255,255),0 : set text font "Verdana" : set text size 16
endfunction
Here is the script between the Janitor and the player.
;Artificial Intelligence Script
;Header
desc = Level 2 Talkbox - Janitor1
;Triggers
:random=50:rotatehead=65
:random=10:rotateheadrandom=35
:state=0:hudreset,hudx=50,hudy=50,hudimagefine=RPG_Mod\Huds\tt\janitor1_note.png,hudname=jan1note,hudhide=1,hudmake=display
:state=0:animate=95,state=1
:state=1:animate=95,state=2
:state=2:animate=95,rotateheadrandom=10
:state=2,random=30:animate=95,rotateheadrandom=10
:state=2,activated=3:rpg_pointplayeratobject,state=10
;
:state=10:animate=95
:state=10,activated=2:animate=95,rpg_entitytimerstart,state=11,alttexture=1,plrfreeze=100000
:state=11:animate=95
:state=11,rpg_entitytimergreater=650:state=12
:state=12,waypointstate=0:animate=2,waypointstart
:state=12,waypointstate=3:animate=2,rpg_pointplayeratobject,waypointnext
:state=12,waypointstate=4:animate=2,waypointrandom
:state=12,waypointstate=5:animate=2,waypointstop,rotatetoplr,rpg_pointplayeratobject=15,rpg_entitytimerstart,state=13
:state=13,rpg_entitytimergreater=250:rpg_entitytimerstart,state=14
:state=14,rpg_entitytimergreater=250:state=16
:state=16:rpg_talkbox=14,state=18
:state=18,rpg_answeriscorrect=janitor1:state=19
:state=18,rpg_noanswer=Janitor1:state=20
:state=18:state=21
:state=19:state=105
:state=20:rpg_setifused=SG1,rpg_talkbox=20,activateifused=1,state=100
:state=21:state=22
:state=22:rpg_setifused=SG1,rpg_talkbox=15,activateifused=1,state=100
;
:state=100:state=101
:state=101:rotatetoplr
;
:state=105:rpg_talkbox=17,rpg_entitytimerstart,state=106
:state=106,rpg_entitytimergreater=150:rpg_talkbox=45,rpg_entitytimerstart,state=107
:state=107,rpg_entitytimergreater=150:rpg_talkbox=18,rpg_entitytimerstart,state=108
:state=108,rpg_entitytimergreater=150:rpg_talkbox=46,rpg_entitytimerstart,state=109
:state=109,rpg_entitytimergreater=150:rpg_talkbox=19,rpg_entitytimerstart,state=110
:state=110,rpg_purchasepricetoolow=janitor1:state=120
:state=110,rpg_purchasepriceok=janitor1:state=150
:state=110:state=152
:state=120:rpg_talkbox=47,state=130
:state=130,rpg_purchasepricetoolow=janitor1:state=131
:state=130,rpg_purchasepriceok=janitor1:state=150
:state=131:rpg_talkbox=48,state=132
:state=132,rpg_purchasepricetoolow=janitor1:state=140
:state=132,rpg_purchasepriceok=janitor1:state=150
:state=140:rpg_talkbox=49,state=142
:state=142,rpg_purchasepricetoolow=janitor1:state=143
:state=142,rpg_purchasepriceok=janitor1:state=150
:state=143:rpg_talkbox=55,state=144,rpg_entitytimerstart
:state=144,rpg_entitytimergreater=150:rpg_talkbox=56,rpg_entitytimerstart,state=160
;
:state=145:rpg_buycost=buycost,rpg_buynoninvitem=&buycost,rpg_entitytimerstart,state=151
;
:state=150:rpg_talkbox=50,rpg_buycost=buycost,rpg_buynoninvitem=&buycost,rpg_entitytimerstart,state=151
:state=151,rpg_entitytimergreater=250:state=152
:state=152,rpg_playerboughtitem:rpg_incinvitem=$Note1 !1,rpg_setplayercanuseitem=$Note1 !1,rpg_entitytimerstart,state=160
:state=152:rpg_talkbox=60,state=153
:state=153,rpg_showyesnoprompt=verdana 24 725:state=160
:state=154:state=145
;
;buzzed door open you can go in now
:state=160,rpg_entitytimergreater=150:rpg_talkbox=51,state=180
;
:state=180:rpg_talkbox=56,rpg_talkbox=62,state=181
:state=181:rpg_setifused=office_door,state=182
:state=182:activateifused=1,plrfreeze=0,rpg_entitytimerstart,state=183
:state=183,rpg_entitytimergreater=200:state=190
;
:state=190,activated=4:destroy
;End of Script
The above script takes care of all the possibilities. If it was just the one possibility it would be much shorter, however, there is also the selling of the paper with odd writing on it to the player as well as the player not telling the janitor correctly that he is a phone repairman.
Hopefully, maho76, you will find this interesting.
"A programmer is just a tool which converts caffeine into code . . . reminds me….. if I had one more brain cell, I could have a synapse! woo hoo, Sparky!
~I'm the Terry of the Flatlands.