Hi,
i made 2 scripts for a npc who askes the player if he(the npc) should open a door for him(the player).
When player says "yes" the npc follows waypoints to a door and stops there.
If the player talks again to the npc it says "The door is open. Good luck".
When the player goes away and comes back the npc says: "i'll stay here"....thats the end of the first script.
The other script has 2 more messages in it: "i sayed i'll stay here" and "Leave me alone".
Opening the door certainly works only if you have a Triggerzone at the door (with the zoneanyactivate.fpi as Mainscript) which triggers the door.
For more details about that topic see this thread:
http://forum.thegamecreators.com/?m=forum_view&t=167551&b=23
There are some differences between the 2 scripts.
The first one activates all screentext only if the player clicks Enter (or any other key you define).
And its scipted more "old style" like before Lee addet localvars to the scripting language. That makes it more hard to add more textmessages.
The second script activates all textmessages when the player comes close to the npc.
It's more polished and u can easy add as many text as you want.
Some pics to show how it's meant:
The waypoints should look like this: (you can certainly use more waypoints...it's only a testlevel)
And ingame:
She starts walking to the door:
Then you can have more blabla from her:
And so on...
(FPSC v.1.16 required)
The first script:
;Artificial Intelligence Script
;scripted by ctm
;Header
desc = npc talks to plr and opens door (press enter for dialog)
;Triggers
:state=0:localvar=0,state=1
:state=1,plrdistfurther=150,varequal=1,activated=2:activate=4,setvar=0
:state=1,plrdistwithin=80:rotatetoplr
:state=1,plrdistwithin=80,plrusingaction=1:state=2
:state=2,plrusingaction=0:state=3
:state=3:fpgcrawtextsize=24,fpgcrawtextfont=verdana
:state=3:fpgcrawtextr=255,fpgcrawtextg=255,fpgcrawtextb=255
:state=3:fpgcrawtextx=50,fpgcrawtexty=70
:state=3,activated=0:fpgcrawtext=You want me to open the door? [Yes = Enter][Not yet = N]
:state=3,activated=2:fpgcrawtext=The door is open. Good luck,setvar=1,state=0
:state=3,activated=4:fpgcrawtext=I'll stay here,state=0
:state=3,scancodekeypressed=49:state=4
:state=3,plrusingaction=1:state=5
:state=3,plrdistfurther=150:state=0
:state=4:fpgcrawtext=Bye,state=0
:state=5:fpgcrawtext=Ok follow me,state=10
:state=10,waypointstate=0:animate=2,waypointstart
:state=10,waypointstate=3:animate=2,waypointnext
:state=10,waypointstate=5:animate=2,waypointstop,activate=2,state=0
;End of Script
The second one:
;Artificial Intelligence Script
;scripted by ctm
;Header
desc = npc talks to plr and opens door
;Triggers
:state=0:localvar=0,state=1
:state=1,activated=2,plrdistfurther=120:state=4
:state=1,plrdistwithin=80:rotatetoplr
:state=1,plrdistwithin=80,activated=0:state=3
:state=3:fpgcrawtextsize=24,fpgcrawtextfont=verdana
:state=3:fpgcrawtextr=255,fpgcrawtextg=255,fpgcrawtextb=255
:state=3:fpgcrawtextx=50,fpgcrawtexty=70
:state=3,varequal=0:fpgcrawtext=You want me to open the door? [Yes = Enter][Not yet = N]
:state=3,varequal=1:fpgcrawtext=The door is open. Good luck
:state=3,varequal=2:fpgcrawtext=I'll stay here
:state=3,varequal=3:fpgcrawtext=I sayed i'll stay here!
:state=3,varequal=4:fpgcrawtext=Leave me alone
:state=3,scancodekeypressed=49,varequal=0:fpgcrawtext=Bye,activate=2,state=0
:state=3,plrusingaction=1,varequal=0:fpgcrawtext=Ok follow me,state=10
:state=3,plrusingaction=1,vargreater=0:activate=2,state=0
:state=3,plrdistfurther=120,varequal=0:state=0
:state=3,plrdistfurther=120,vargreater=0:state=4
:state=4,varequal=0:activate=0,state=0
:state=4,varequal=4:activate=0,state=0
:state=4,varless=4:incvar=1,activate=0,state=0
:state=10,waypointstate=0:animate=2,waypointstart
:state=10,waypointstate=3:animate=2,waypointnext
:state=10,waypointstate=5:animate=2,waypointstop,setvar=1,state=0
;End of Script
And a full commented version of the second one:
;Artificial Intelligence Script
;scripted by ctm
;Header
desc = npc talks to plr and opens door
;Triggers
:state=0:localvar=0,state=1
; ----------------------------------------------------------------------------------------------------------------------------------------
; "activated" is set to 2 when plrs choice is "not yet" or text is quit with enter
; it's used here as control variable while the plr is close to the NPC
; when plr goes away script gets reset and var set for next dialogtxt (see state=4)
; -----------------------------------------------------
:state=1,activated=2,plrdistfurther=120:state=4
; ----------------------------------------------------------------------------------------------------------------------------------------
; dialog starts when plr comes close to NPC and "activated" is 0
; -----------------------------------------------------
:state=1,plrdistwithin=80:rotatetoplr
:state=1,plrdistwithin=80,activated=0:state=3
; ----------------------------------------------------------------------------------------------------------------------------------------
; RAWTEXT setup
; -----------------------------------------------------
:state=3:fpgcrawtextsize=24,fpgcrawtextfont=verdana
:state=3:fpgcrawtextr=255,fpgcrawtextg=255,fpgcrawtextb=255
:state=3:fpgcrawtextx=50,fpgcrawtexty=70
; ----------------------------------------------------------------------------------------------------------------------------------------
; Dialog text, the first one is the "choice text"
; localvar becomes the index for the txt
; -----------------------------------------------------
:state=3,varequal=0:fpgcrawtext=You want me to open the door? [Yes = Enter][Not yet = N]
:state=3,varequal=1:fpgcrawtext=The door is open. Good luck
:state=3,varequal=2:fpgcrawtext=I'll stay here
:state=3,varequal=3:fpgcrawtext=I sayed i'll stay here!
:state=3,varequal=4:fpgcrawtext=Leave me alone
; ----------------------------------------------------------------------------------------------------------------------------------------
; check which key the plr presses while choicetext is active (varequal=0)
; when plr says "not yet" activated is set to 2..plr has to move away for a new dialog
; when player presses the Enter key NPC starts to move (waypointstart, state=10)
; -----------------------------------------------------
:state=3,scancodekeypressed=49,varequal=0:fpgcrawtext=Bye,activate=2,state=0
:state=3,plrusingaction=1,varequal=0:fpgcrawtext=Ok follow me,state=10
; ----------------------------------------------------------------------------------------------------------------------------------------
; plr quits dialogtxt with enter key. activated is set to 2, plr has to move away for a reset
; -----------------------------------------------------
:state=3,plrusingaction=1,vargreater=0:activate=2,state=0
; ----------------------------------------------------------------------------------------------------------------------------------------
; plr moves away while choicetxt is active (varequal=0), script resets (state=0)
; -----------------------------------------------------
:state=3,plrdistfurther=120,varequal=0:state=0
; ----------------------------------------------------------------------------------------------------------------------------------------
; plr moves away while one of the other messages is on screen
; var gets set for next message (state=4)
; -----------------------------------------------------
:state=3,plrdistfurther=120,vargreater=0:state=4
; ----------------------------------------------------------------------------------------------------------------------------------------
; script reset for 1st and last message, 3rd line also increases var for next message
; state=4 gets called when plr moves away or quits message with enter....see code obove
; -----------------------------------------------------
:state=4,varequal=0:activate=0,state=0
:state=4,varequal=4:activate=0,state=0
:state=4,varless=4:incvar=1,activate=0,state=0
; ----------------------------------------------------------------------------------------------------------------------------------------
; waipoint start and waypoint stop (see Lee's follow script)
; when NPC stops localvar is set to 1 (the second dialogtxt)
; -----------------------------------------------------
:state=10,waypointstate=0:animate=2,waypointstart
:state=10,waypointstate=3:animate=2,waypointnext
:state=10,waypointstate=5:animate=2,waypointstop,setvar=1,state=0
;End of Script
Hope that helps to understand the script.