Jump to content

Script Advice


kxdace

Recommended Posts

Posted

So looking for some advice on how to execute some code effectively. My end state is to have a NPC’s with 3 AI packages that operate on an 8 hour cycle Work > Relax > Sleep. Each package has the NPC go to a different location and uses a different outfit. For example:

·         0800 to 1600: Location A - Guild Hall | Outfit A - Battle Armor

·         1600 to 0000: Location B - Bar | Outfit B - Casual Clothes

·         0000 to 0800: Location C – Dorm | Outfit C - Underwear

I achieve this by putting a trigger at each location (that covers the entire area). When the NPC enters the trigger it checks to see if the NPC is in a predetermined faction and if so changes that NPC’s clothing. Please see the code below and let me know if this is optimal or if there is a better way to do it. I haven’t encountered any issues yet but I know that with scripting the flaws are not always apparent.

Scriptname wrScriptCIT_TRIG_ChangeClothes extends ObjectReference  

    Bool Property enMSG  Auto  
    Int Property rando Auto

    Faction property SaraCL auto
    Outfit Property SaraDorm Auto
    Outfit Property SaraDefault Auto
    Outfit Property SaraDormB Auto
    Outfit Property SaraDefaultB Auto

    Faction property HydieCL auto
    Outfit Property HydieDorm Auto
    Outfit Property HydieDefault Auto
    Outfit Property HydieDormB Auto
    Outfit Property HydieDefaultB Auto
 
Event OnTriggerEnter(ObjectReference akActionRef)

    rando = Utility.RandomInt (0,1)
    Actor theActor = akActionRef AS Actor

    if(enMSG == 1)

        debug.messageBox(theActor.getleveledActorBase().getName() + " has entered trigger")

    endIf

        if(theActor.isInFaction(SaraCL))
                
            if(rando == 0)
                theActor.setOutfit(SaraDorm)
            else
                theActor.setOutfit(SaraDormB)
            endIf

            enDisarm(theActor)

            if(enMSG == 1)

                debug.messageBox("Changing " + theActor.getleveledActorBase().getName() + "outfit")

            endIf

        endIf

        if(theActor.isInFaction(HydieCL))
                
            if(rando == 0)
                theActor.setOutfit(HydieDorm)
            else
                theActor.setOutfit(HydieDormB)
            endIf

            enDisarm(theActor)

            if(enMSG == 1)

                debug.messageBox("Changing " + theActor.getleveledActorBase().getName() + "outfit")

            endIf
                
        endIf

EndEvent

 

Event OnTriggerLeave(ObjectReference akActionRef)

    Actor theActor = akActionRef AS Actor

    if(enMSG == 1)

        debug.messageBox(theActor.getleveledActorBase().getName() + " has left the trigger")

    endIf

    if((theActor).isInFaction(SaraCL))
                
            if(rando == 0)
                theActor.setOutfit(SaraDefault)
            else
                theActor.setOutfit(SaraDefaultB    )        
            endIf

            if(enMSG == 1)

                debug.messageBox("Changing " + theActor.getleveledActorBase().getName() + "outfit")

            endIf

        endIf

    if((akActionRef as Actor).isInFaction(HydieCL))
                
            ;(akActionRef as Actor).setOutfit(HydieDefault)

            if(rando == 0)
                theActor.setOutfit(HydieDefault)
            else
                theActor.setOutfit(HydieDefaultB)
            endIf

            if(enMSG == 1)

                debug.messageBox("Changing " + theActor.getleveledActorBase().getName() + "outfit")

            endIf

        endIf

EndEvent


Function enDisArm(Actor testA)
            
            Actor theActor = testA
            theActor.UnequipItemSlot(39)
            theActor.UnequipItemSlot(33)
            Weapon equippedLeft  = theActor.GetEquippedWeapon (true)
                theActor.UnequipItem(equippedLeft)
            Weapon equippedRight = theActor.GetEquippedWeapon ()
               theActor.UnequipItem(equippedRight)

endFunction

 

 

 

 

Posted
11 minutes ago, kxdace said:

 

I am not in any way an expert, but overall looks basically right.

 

A few small things:  With outfits, I have found that you usually have to create an intermediate step or they won't reliably change clothing.  An example would be using a naked state as an intermediate.

 

I find IsInFaction to be unreliable when that faction/rank can be changed.  I get more consistent results using "GetFactionRank >= 1".  The main reason for this is if an alias has their faction removed (int should be == -2), and then some process removes it again, it will instead be == -1, and now reads as "isinfaction".  I get around this by always using SetFactionRank(fac, -2) to remove, and always comparing for a positive int value instead of the blanket IsInFaction.

Posted

So that would explain why I've been getting inconsistent results with factions!!!

 

I almost fell out of my chair when I ready that lol.

 

So many frustrating hours spent scratching my head.

 

Thank you!

 

 

 

Posted
10 hours ago, kxdace said:

So that would explain why I've been getting inconsistent results with factions!!!

 

I almost fell out of my chair when I ready that lol.

 

So many frustrating hours spent scratching my head.

 

Thank you!

Yeah, the entire faction system is seriously buggered.  No matter how you manage or massage it, functionally it always bottlenecks to a bool result, and leaves zero room for nuance.

 

That would be fine if it were a bool, but it is invariably expressed as an int where even a negative value can read as true, so... yeah.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...