Author Topic: NPCs, Timers, and EscapeAreas, Oh My!  (Read 1261 times)

Offline cmorgan

  • Planewalker
  • *****
  • Posts: 1424
  • Gender: Male
  • Searcher of Bugs
NPCs, Timers, and EscapeAreas, Oh My!
« on: April 05, 2006, 09:51:38 PM »
OK, I have been tracking down how to do the following:

Tutu modification:

Take an existing NPC interacting with the party.
At the end of dialogue, have him Escape Area (or go offscreen) and wait in limbo for  DO ~SetGlobalTimer("NPCSearch","GLOBAL",TWO_DAYS), thus avoiding destroy-respawn problems.

In the same area, IF GlobalTimerExpired("NPCSearch","GLOBAL") have the NPC come back onscreen, walk up to the characters, and begin dialogue.

I thought that I had a good start on this from searching PPG and G3 threads, but I would appreciate targetted help or existing examples to deconstruct. I will gladly read, if folks will point -- any suggestions are appreciated!

Offline Duality

  • Planewalker
  • *****
  • Posts: 147
Re: NPCs, Timers, and EscapeAreas, Oh My!
« Reply #1 on: April 06, 2006, 12:42:20 PM »
Part of the problem is that once a NPC is off screen, their .bcs quits being checked. To avoid this you either have to give them the aifast item or put the check into the area.bcs.
I'm not sure, but I think that once a NPC has used EscapeArea(), they are no longer retained in any save/global, and thus, not only does their script not run, no matter what, but you would have to respawn them.

Here's an example.
The dialog file:

ok, bye then~ DO ~
EscapeArea()
SetGlobalTimer("NPCSearch", "GLOBAL", 120)~ EXIT

Then the area.bcs file would have:

IF
     GlobalTimerExpired("NPCSearch", "GLOBAL")
THEN
     RESPONSE #100
          CreateCreature("myNPC", [whatever the coordinates are], 0)
          MoveToObject(Player1)
          ActionOverride("myNPC", StartDialog("myNPCsDialogFile", Player1))
END

That ought to get you started.
"I'll try being nicer if you try being smarter."

"There is a certain freedom in being totally screwed. It means that nothing you do is going to make it any worse."

"Eagles may soar, but weasels don't get sucked into jet engines."

Offline cmorgan

  • Planewalker
  • *****
  • Posts: 1424
  • Gender: Male
  • Searcher of Bugs
Re: NPCs, Timers, and EscapeAreas, Oh My!
« Reply #2 on: April 06, 2006, 03:01:37 PM »
Cool, thanks --
 To make sure I understand, the .cre file is no longer checked while offscreen/escaped, so the way to do this is to
1. set a timer active through dialogue, sending the NPC offscreen at the conclusion
2. set the area script to spawn the NPC again when the timer has expired

here's the question:
3. and therefore, if we need to keep the NPC on track, reset any globals that they had before leaving, including LTs, and any globals set for continuation of a quest (death variable shouldn't change) -- and making sure that the next set of dialogue weights/globals to continue the quest avoid placing the NPC back to the beginning of the initial quest dialogue?

Offline devSin

  • Planewalker
  • *****
  • Posts: 1632
  • Gender: Male
Re: NPCs, Timers, and EscapeAreas, Oh My!
« Reply #3 on: April 06, 2006, 03:35:51 PM »
If they have local variables, you may want to look at the Deactivate() and Activate() script actions.

Offline Duality

  • Planewalker
  • *****
  • Posts: 147
Re: NPCs, Timers, and EscapeAreas, Oh My!
« Reply #4 on: April 06, 2006, 04:14:14 PM »
Actually, devSin's solution is better. Deactivate() hides the .cre so the PC can't interact with them. And stores the information within the area. What I don't know however is if the NPC's bcs will run while deactivated. My assumption is no, that you would still need a trigger in the area.bcs that if the conditions are met, Activate() the NPC.
"I'll try being nicer if you try being smarter."

"There is a certain freedom in being totally screwed. It means that nothing you do is going to make it any worse."

"Eagles may soar, but weasels don't get sucked into jet engines."

Offline cmorgan

  • Planewalker
  • *****
  • Posts: 1424
  • Gender: Male
  • Searcher of Bugs
Re: NPCs, Timers, and EscapeAreas, Oh My!
« Reply #5 on: April 06, 2006, 09:20:43 PM »
If I understand you folks correctly, after looking at the IESDP,
This means that all I need to do is

//in ~_myNPCsTutuDialogFile~, this (NPCstartsearch set to 1 by a previous interaction):

Code: [Select]
IF WEIGHT #-2
~Global("NPCstartsearch","GLOBAL","1")~ THEN BEGIN NPCSEARCH     
SAY ~ ok, see you in two game days~ DO ~SetGlobalTimer("NPCSearch", "GLOBAL",TWO_DAYS)~
IF ~~ THEN DO ~GiveItemCreate("MyItem","Player1",1,1,0) SetGlobal("NPCstartsearch","GLOBAL","2") Deactivate("myNPC")~ EXIT
END

//EXTEND area.bcs either top or bottom, (more research for me) this:

Code: [Select]
IF
     GlobalTimerExpired("NPCSearch", "GLOBAL")
THEN
     RESPONSE #100
         Activate("myNPC")
          MoveToObject("Player1")
          ActionOverride("myNPC", StartDialog("myNPCsDialogFile", Player1))
END

//Back in ~_myNPCsTutuDialogFile~, this:

Code: [Select]
IF WEIGHT #-2
~Global("NPCstartsearch","GLOBAL","2")~ THEN BEGIN NPCSEARCHFINISHED     
SAY ~ Well, <CHARNAME>, I found the other item. What say you?~
++ ~Yes, I want to do this~ + NPCQUEST2
++ ~No, I want nothing to do with you now~ EXIT
END

and this would result in "myNPC" disappearing for two days, reappearing in area and walking to the party, and starting the conversation again. The NPC retains all current info, including locals set by the initial conversation, untouched, in the save. I could extend this by moving the NPC away from the party before deactivation, so that it appears as if they walk away. This usage should avoid messing with anything other mods have set up for the character.
Am I on track?
« Last Edit: April 06, 2006, 09:30:01 PM by cmorgan »

Offline Duality

  • Planewalker
  • *****
  • Posts: 147
Re: NPCs, Timers, and EscapeAreas, Oh My!
« Reply #6 on: April 06, 2006, 10:12:11 PM »
Looks like it should work, just a few things.

No quotes around Player1. Players1-6 are defined as identifiers in their own right.
GiveItemCreate("MyItem","Player1",1,1,0) - just an example, you did it multiple times.

or around the 2
SetGlobal("NPCstartsearch","GLOBAL","2")

As for extend top/bottom. The scripts run from top-bottom (duh), thus, an action at the top of a script is more likely to get executed. If an action is at the bottom, there is a chance that the conditions will be met for another block before it gets to the bottom.
Thus, if it's not terrible important that the block trigger right away, the bottom is fine, but for the most part, people use extend top.

Hope that helps. Or at the very least is coherent. I think I've been staring at this screen for too long.
"I'll try being nicer if you try being smarter."

"There is a certain freedom in being totally screwed. It means that nothing you do is going to make it any worse."

"Eagles may soar, but weasels don't get sucked into jet engines."

Offline cmorgan

  • Planewalker
  • *****
  • Posts: 1424
  • Gender: Male
  • Searcher of Bugs
Re: NPCs, Timers, and EscapeAreas, Oh My!
« Reply #7 on: April 06, 2006, 10:19:27 PM »
Thank you very much for the help. :) I will take note of the use of " when coding this out. The EXTEND_TOP (not a direct quote; I will go look at some code to get the syntax right) sounds like the way to go.

And next time, I will ignore the "code" button for posting -- like you, my eyes started to swim when reading the snippets!

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: