Scripting Multiple Instances

Post » Sat May 28, 2011 2:00 am

i've got a bit of trouble making a script for some characters with the same ID. in the script i want them to attack me and as soon as 1 of them gets close enough, he will forcegreet me and present a choice. if answered correctly, they should all stop attacking.

the latter doesn't happen however. instead only the instance that approached me will stop combat, the others will happily continue to kill me. i tried using start scripts but again, it only works on 1 instance and then does not affect the others.

how do i make a certain command apply to ALL instances with the same ID?
User avatar
lolli
 
Posts: 3485
Joined: Mon Jan 01, 2007 10:42 am

Post » Sat May 28, 2011 8:14 am

how do i make a certain command apply to ALL instances with the same ID?


You create a global variable and have the local script on each NPC stop combat when that variable is set to a certain value:
begin fakecodescriptif ( NI_globalStopNow == 1 )   stopCombat;endIfif ( getDistance player <=500 )  forceGreetingendIfend


In your dialog you would set the variable to 1 when the appropriate response is chosen.
User avatar
Anna Beattie
 
Posts: 3512
Joined: Sat Nov 11, 2006 4:59 am

Post » Sat May 28, 2011 2:12 am

hmmm it's not working. this is what the scripts look like now.

script on the instance
begin DBtestscriptIf ( menumode )	returnendifif ( mycrime == 3 )	StartCombat "Player"	SetFight 100	if ( GetDistance "player" <= 256 )		StopCombat		set mycrime to 4		set DoOnce to 1		ForceGreeting	endifendifif (DoOnce == 1 )	startscript safefromyouendifend DBtestscript


startscript
begin safefromyouStopCombat "Player"if (GetSecondsPassed == 2)	set DoOnce to 0endifend safefromyou

User avatar
Laura Elizabeth
 
Posts: 3454
Joined: Wed Oct 11, 2006 7:34 pm

Post » Fri May 27, 2011 7:52 pm

Two things:

1. You shouldn't be starting a script like that on an actor, especially not one so small it could be inlined, especially not on multiple actors.
2. GetSecondsPassed, unless you have exactly 0.5 FPS (exactly), will never be 2.

You might also want to avoid using GetDistance so often, but that's a minor detail.

A cleaner, merged version:
begin DBtestscriptfloat timerIf ( menumode )	returnendifif ( mycrime == 3 )    StartCombat "Player"    SetFight 100    Set myCrime to 4elseif ( myCrime == 4 )    if ( GetDistance "player" <= 256 )        set mycrime to 5    endifelseif ( myCrime == 5 )    if ( timer < 2.0 )        set timer to ( timer + GetSecondsPassed )    else        set myCrime to 6        SetFight 0        StopCombat "player"        ForceGreeting    endifendifend DBtestscript


I also cleaned up some of the timing; for example, they now greet you after they start fighting and after their fight AI is set to 0.
User avatar
oliver klosoff
 
Posts: 3436
Joined: Sun Nov 25, 2007 1:02 am

Post » Sat May 28, 2011 9:33 am

Hmm, I think in this script they won't act in coherence as they are meant to. Another version to consider:
begin DBtestscriptfloat timershort doOnceIf ( menumode == 1 )	returnendifif ( mycrime == 3 )    if ( doOnce == 0 )        StartCombat "Player"        SetFight 100        Set myCrime to 4        set doOnce to 1    elseif ( doOnce == 1 )        if ( GetDistance "player" <= 256 )            set doOnce to 2        endif    elseif ( doOnce == 2 )        set timer to ( timer + GetSecondsPassed )        if ( timer >= 2.0 )            SetFight 0            StopCombat "player"            ForceGreeting        endif    endifendifif ( mycrime == 4 )    if ( doOnce <= 2 )        SetFight 0        StopCombat "player"        set doOnce to 3    else        set mycrime to 6    endifendifend DBtestscript


The dialogue will set mycrime to either 4, which state should be undisturbed for at least one full frame so that all three NPCs might notice it, or to 5 (wrong answer), in which case the action box should contain StartCombat to override the one under doOnce==2.
User avatar
Jack Moves
 
Posts: 3367
Joined: Wed Jun 27, 2007 7:51 am

Post » Sat May 28, 2011 5:14 am

hey! i just wanted to tell you guys that i got the scripts working now!
thanks for posting all your tips and suggestions, it gave me a good idea of how to proceed!
i'm looking forward to uploading the finished version =)
User avatar
Chris Jones
 
Posts: 3435
Joined: Wed May 09, 2007 3:11 am


Return to III - Morrowind