Jump to content


Photo

Jerky AI due to multiple commands


  • Please log in to reply
4 replies to this topic

#1 temnix

temnix
  • Member
  • 983 posts

Posted 30 May 2017 - 02:38 PM

Sometimes the party is hard to move around. I click, but the circles won't appear. It takes a few tries, and the characters keep halting mid-way. I've learned that this is a sure sign of some AI commands constantly being issued. When the party AI is off, and if I know that nothing in the overarching scripts is sending ActionOverrides in their direction, this means that creature scripts are to blame. Something confusing is going on there, and it usually has to do with Range. For example, if you write

 

Range(Player1,7)

 

in a creature's script, followed by some action, it's going to attempt it forever, never move from the spot and so always in range (unless Player1 does a reverse Muhammad moonwalk and gets away first). This issue comes up rarely, but it's come up again now, scripting certain inhabitants of a village to move to their doors and vanish nearby, imitating an entry. The creatures stumble under an almost visible stream of shouting from the AI. I don't know if this sort of thing - imitating realistic comings and goings - has been done in other mods and I can't download every thing made since Noah to look, but I could use some advice from those who have run into the range problem.

 

I'm going to put the code for the override script here, and I should mention that there is quite a bit of other code on top of this.

 

IF
    !Allegiance(Myself,EVILCUTOFF) /// When not an enemy
    !Global("XVARTS_MAD","GLOBAL",1) /// And not angered
    Global("NEXLIT_OKAY","GLOBAL",1) /// And the chief approves
    NearLocation(Myself,2477,1865,5) /// And close enough to the entrance of one of the huts
THEN
    RESPONSE #100
        ClearAllActions()
        MoveToPointNoInterrupt([2477.1865]) /// The actual place, "rug," before the door. They are not doors in the technical sense
        CreateCreatureOffScreen("kxvar1_#",S)  // Spawn another xvart off-screen as a replacement
        DestroySelf() /// And dive in. Repeated below for different doorways
END

IF
    !Allegiance(Myself,EVILCUTOFF)
    !Global("XVARTS_MAD","GLOBAL",1)
    Global("NEXLIT_OKAY","GLOBAL",1)
    NearLocation(Myself,2655,1668,5)
THEN
    RESPONSE #100
        ClearAllActions()
        MoveToPointNoInterrupt([2655.1668])
        CreateCreatureOffScreen("kxvar1_#",N)  // Xvart
        DestroySelf()
END

IF
    !Allegiance(Myself,EVILCUTOFF)
    !Global("XVARTS_MAD","GLOBAL",1)
    Global("NEXLIT_OKAY","GLOBAL",1)
    NearLocation(Myself,3045,1784,5)
THEN
    RESPONSE #100
        ClearAllActions()
        MoveToPointNoInterrupt([3045.1784])
        CreateCreatureOffScreen("kxvar1_#",N)  // Xvart
        DestroySelf()
END

IF
    !Allegiance(Myself,EVILCUTOFF)
    !Global("XVARTS_MAD","GLOBAL",1)
    Global("NEXLIT_OKAY","GLOBAL",1)
    NearLocation(Myself,3294,1696,5)
THEN
    RESPONSE #100
        ClearAllActions()
        MoveToPointNoInterrupt([3294.1696])
        CreateCreatureOffScreen("kxvar1_#",N)  // Xvart
        DestroySelf()
END

IF
    !Allegiance(Myself,EVILCUTOFF)
    !Global("XVARTS_MAD","GLOBAL",1)
    Global("NEXLIT_OKAY","GLOBAL",1)
    NearLocation(Myself,3578,1716,5)
THEN
    RESPONSE #100
        ClearAllActions()
        MoveToPointNoInterrupt([3578.1716])
        CreateCreatureOffScreen("kxvar1_#",W)  // Xvart
        DestroySelf()
END

IF
    !Allegiance(Myself,EVILCUTOFF)
    !Global("XVARTS_MAD","GLOBAL",1)
    Global("NEXLIT_OKAY","GLOBAL",1)
    NearLocation(Myself,4245,944,5)
THEN
    RESPONSE #100
        ClearAllActions()
        MoveToPointNoInterrupt([4245.944])
        CreateCreatureOffScreen("kxvar1_#",W)  // Xvart
        DestroySelf()
END

 

/// The following actions are what the xvarts should do when not near those door rugs. By itself (without the blocks above) the code works and they move about smoothly. With them they walk a few steps and stop, hovering, so there must be some conflict between the two.


IF
    !Allegiance(Myself,EVILCUTOFF)
    !Global("XVARTS_MAD","GLOBAL",1)
    Global("NEXLIT_OKAY","GLOBAL",1)
     !NearLocation(Myself,2477,1865,5)
    !NearLocation(Myself,4245,944,5)
    !NearLocation(Myself,3578,1716,5)
    !NearLocation(Myself,3294,1696,5)
    !NearLocation(Myself,3045,1784,5)
THEN
    RESPONSE #2
        RandomWalk()  /// A smallish chance of moving about - and hopefully passing within Range above to be snatched by homesickness
    RESPONSE #20
        NoAction() /// Mostly standing around
    RESPONSE #1
        CreateCreatureOffScreen("kxvar1_#",S)  // And a small chance of leaving a replacement
        EscapeAreaDestroy(10) /// Before running off
END

What do you think I could do to get this running smoothly?



#2 Fiann of the Silver Hand

Fiann of the Silver Hand
  • Member
  • 286 posts

Posted 30 May 2017 - 11:50 PM

You need to set a variable so that it doesn't repeatedly keep finding the conditions true and starting the action block fresh every time:

 

IF
    !Allegiance(Myself,EVILCUTOFF) /// When not an enemy
    !Global("XVARTS_MAD","GLOBAL",1) /// And not angered
    Global("NEXLIT_OKAY","GLOBAL",1) /// And the chief approves
    NearLocation(Myself,2477,1865,5) /// And close enough to the entrance of one of the huts

    !Global("NEXLIT_IS_MOVING","GLOBAL",1)
THEN
    RESPONSE #100

        SetGlobal("NEXLIT_IS_MOVING","GLOBAL",1)
        ClearAllActions()
        MoveToPointNoInterrupt([2477.1865]) /// The actual place, "rug," before the door. They are not doors in the technical sense
        CreateCreatureOffScreen("kxvar1_#",S)  // Spawn another xvart off-screen as a replacement
        DestroySelf() /// And dive in. Repeated below for different doorways
END



#3 GeN1e

GeN1e

    A very GAR character

  • Modder
  • 1604 posts

Posted 31 May 2017 - 09:34 AM

You need to set a variable so that it doesn't repeatedly keep finding the conditions true and starting the action block fresh every time:
I'm in doubt, tbh. First, you can kill the script this way, even with NoInterrupt (not likely, but still). Second, this bit from SoD's bdshout.bcs works absolutely fine
 
IF
  Global("bd_retreat","locals",1) // in retreat mode
  Global("bd_combat","locals",0) // not in combat mode
  OR(2)
    !See(NearestEnemyOf(Myself))
    !Global("bd_no_combat","locals",0) // no script override
  !NearSavedLocation(Myself,"LOCALSbd_default_loc",5)
  !GlobalTimerNotExpired("bd_search_timer","locals") // i'm not looking for enemies
  !GlobalTimerNotExpired("bd_respond_timer","locals") // i'm not rushing to my allies' side
  Switch("bd_no_retreat","locals") // script override
THEN
  RESPONSE #0
    MoveToSavedLocation("bd_default_loc","LOCALS")
  RESPONSE #1
    SetGlobal("bd_retreat","locals",0) // deactivate retreat mode
END
 

IF
  Global("bd_retreat","locals",1) // in retreat mode
  Global("bd_combat","locals",0) // not in combat mode
  NearSavedLocation(Myself,"LOCALSbd_default_loc",5)
  Global("bd_no_retreat","locals",0) // no script override
  Switch("bd_retreat_escape","locals") // script override
THEN
  RESPONSE #0
    SetGlobal("bd_retreat","locals",0) // deactivate retreat mode
    SetGlobalTimer("bd_rest_timer","locals",1800) // rest after 6 hours
    MoveToSavedLocation("bd_default_loc","LOCALS") // try to reach the exact location one last time, if i was stopped two steps away from it
  RESPONSE #1
    DestroySelf()
END

PS I'll bet my money on ClearAllActions(). It's global, i.e. affects everyone in the area. If you've got two actors clearing each other every second, that might easily produce the observed behavior. Either use ClearActions() which is local, or just skip it entirely,, whatever actor has been doing will be overwritten by moving anyway.

Edited by GeN1e, 31 May 2017 - 09:40 AM.

Retired from modding.


#4 -fiann unlogged-

-fiann unlogged-
  • Guest

Posted 31 May 2017 - 01:23 PM

You're right.  I don't think I've ever used CAA, and I make a habit of keeping actions walled off if/while they're running, in case the response block aborts for some inexplicable reason.



#5 temnix

temnix
  • Member
  • 983 posts

Posted 31 May 2017 - 01:49 PM

Okay! I didn't know about ClearActions(). Thanks. That might be it.