Jump to content

Script Help NPC Approach Type Mod


kxdace

Recommended Posts

Posted

Hello Fam!

I'm making a mod that makes a random NPC approach the player character if they is sitting down and drinking an alcoholic beverage. The code executes properly but for some reason it is being called twice. How did I mess this up? I have a player alias with the following script attached. Also if you have any general critiques or better ways of writing this code please let me know.

 

Scriptname wrScript_RomPlayer extends ReferenceAlias

    FormList Property Drinks Auto
    Actor property actorRandom Auto hidden
    Actor property actorRandomWL Auto hidden
    String property stringFinalText Auto hidden
    FormList Property RacesHumonoid  Auto
    Int property validNPCCount Auto hidden
    Quest Property selQuest Auto
    Actor Property selNPC Auto
    ReferenceAlias Property  Alias_P01 Auto
    Faction Property JobMerchantFaction  Auto  

    Race Property NordRace  Auto  
    Race Property ImperialRace  Auto  
    Race Property BretonRace  Auto  
    Race Property RedguardRace  Auto  
    Race Property HighElfRace  Auto  
    Race Property DarkElfRace  Auto  
    Race Property EtherrealRace  Auto  

    int property intEnabled Auto Hidden
    int property intSex Auto Hidden
    int property intRace Auto Hidden
    int property intTotal Auto Hidden
    int property intArrayPos Auto Hidden

 

Event OnInit()

    AddInventoryEventFilter(Drinks)

EndEvent


Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)

    int sitStatus = game.getplayer().getSitState()

    if (akSourceContainer == "None" && sitStatus == 3)
    

        Cell playerCell = Game.GetPlayer().GetParentCell()
        int npcCountInitial = playerCell.GetNumRefs(43)
        ;debug.MessageBox("There are currently: " + npcCountInitial + " actors in this cell")


        ;Object Array to hold our NPC's
        ObjectReference[] objectRefListA = new ObjectReference[20]
        int formSizeInt = RacesHumonoid.getSize()
        intArrayPos = 0
    

        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;Checks to see if NPC is valid
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        while(npcCountInitial)

            npcCountInitial -= 1
            actorRandomWL = playerCell.GetNthRef(npcCountInitial, 43) AS Actor
            ;debug.MessageBox("The actor in this cell list at postion " + npcCountInitial + " is " + actorRandomWL.getleveledActorBase().getName())

            ;Get current NPC Sex
            int npcSexInt = actorRandomWL.GetActorBase().getSex(); 0 is male 1 is female
        
            ;Get current NPC race
            race npcRace = actorRandomWL.GetActorBase().getRace()
        
            ;Get current NPC enabled \ disable status
            ObjectReference npcEnabledStatus = actorRandomWL AS ObjectReference

            ;Check to see if NPC is enabled
            if(npcEnabledStatus.isDisabled())

                ;debug.MessageBox("The actor " + actorRandomWL.getleveledActorBase().getName() + " is disabled")
    
            else
        
                ;debug.MessageBox("" + actorRandomWL.getleveledActorBase().getName() + " is enabled")
                intEnabled = 1
        
            endIf

    
            ;Check to see if NPC is female
            if (npcSexInt == 1)

                intSex = 1

            endIf
        
            ;;;;;;;;;;;;;;;;;;;;;;;;;
            ;VALID RACE CHECK
            ;;;;;;;;;;;;;;;;;;;;;;;;;;    
            if(npcRace == NordRace)
                ;debug.MessageBox("The actor " + actorRandomWL.getleveledActorBase().getName() + " is a Nord")
                intRace = 1
            elseIf(npcRace == ImperialRace)
                ;debug.MessageBox("The actor " + actorRandomWL.getleveledActorBase().getName() + " is a Imperial")
                intRace = 1
            elseIf(npcRace == BretonRace)
                ;debug.MessageBox("The actor " + actorRandomWL.getleveledActorBase().getName() + " is a Breton")
                intRace = 1
            elseIf(npcRace == RedGuardRace)
                ;debug.MessageBox("The actor " + actorRandomWL.getleveledActorBase().getName() + " is a Redguard")
                intRace = 1
            elseIf(npcRace == HighElfRace)
                ;debug.MessageBox("The actor " + actorRandomWL.getleveledActorBase().getName() + " is a High Elf")
                intRace = 1
            elseIf(npcRace == DarkElfRace)
                ;debug.MessageBox("The actor " + actorRandomWL.getleveledActorBase().getName() + " is a DarkElf")
                intRace = 1        
            elseIf(npcRace == EtherrealRace)
                intRace = 1        
                ;debug.MessageBox("The actor " + actorRandomWL.getleveledActorBase().getName() + " is a Etherreal")
            else
                ;debug.MessageBox("The actor " + actorRandomWL.getleveledActorBase().getName() + " is a  No races match")
            endIf

            int total = intEnabled + intSex + intRace
        
            ;If actor meets all the criteria place inside the array
            if (total == 3)
                ;debug.MessageBox("The actor " + actorRandomWL.getleveledActorBase().getName() + " is valid")
                objectRefListA[intArrayPos] = actorRandomWL
                intArrayPos += 1
            else
                ;debug.MessageBox("The actor " + actorRandomWL.getleveledActorBase().getName() + " is not valid")
            endIf
        
            ;Reset all values for next NPC
            intEnabled = 0
            intSex = 0
            intRace = 0

        endWhile


        int randomNPCnumberA = Utility.RandomInt (0, intArrayPos)
        actorRandom = objectRefListA[randomNPCnumberA] AS Actor
        ;debug.MessageBox("The chosen actor is " + actorRandom.getleveledActorBase().getName())

        if( actorRandom != None)
            debug.notification("It appears " + actorRandom.getleveledActorBase().getName() + " has taken a liking to you")
        else
            ;debug.notification("No one seems that interested today")    
        endIf

        selQuest.setStage(10)
        utility.wait(5)
        Alias_P01.ForceRefTo(actorRandom)

 

        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;DEBUG OUTPUT & TESTING ONLY
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        Actor actA = objectRefListA[0] AS Actor
        Actor actB = objectRefListA[1] AS Actor
        Actor actC = objectRefListA[2] AS Actor
        Actor actD = objectRefListA[3] AS Actor

        ;int testX = actA.getleveledActorBase().GetActorValue("Aggression")
        ;GetActorBase()
        ;int testX = actA.getActorBase().GetActorValue("Aggression")
        int x = actA.GetActorValue("Aggression") AS INT
        String textX = actA.GetActorValue("Aggression")

        ;debug.MessageBox("Actor 0 = " + actA.getleveledActorBase().getName())
        ;utility.wait(1)
        ;debug.MessageBox("Actor 1 = " + actB.getleveledActorBase().getName())
        ;utility.wait(1)
        ;debug.MessageBox("The int is " + intArrayPos)
        
        int MerchantStatus = 0

        if(actorRandom.isInFaction(JobMerchantFaction))
            MerchantStatus = 1
        else
            MerchantStatus = 0
        endIf

        String StringNPCselected = ""
        StringNPCselected = "Slot 0: " + actA.getleveledActorBase().getName() + "\n" + "Slot 1: " + actB.getleveledActorBase().getName()
        StringNPCselected += "\n" + "Slot 2: " + actC.getleveledActorBase().getName()
        StringNPCselected += "\n" + "Slot 3: " + actD.getleveledActorBase().getName()
        StringNPCselected += "\n" + "The chosen actor is: " + actorRandom.getleveledActorBase().getName()
        ;StringNPCselected += "\n" + "Random Number is: " + randomNPCnumberA
        StringNPCselected += "\n" + "Array size is: " + intArrayPos
        StringNPCselected += "\n" + "Random Value between 0 and array size " + intArrayPos + " is " + randomNPCnumberA
        StringNPCselected += "\n" + "Agression is: " + actorRandom.GetActorValue("Aggression")
        StringNPCselected += "\n" + "Confidence is: " + actorRandom.GetActorValue("Confidence")
            if (MerchantStatus == 1)
                StringNPCselected += "\n" + "Faction: Merchant"
            else
                StringNPCselected += "\n" + "Faction: None Merchant"
            endIF
    
    EndIf


endEvent

 

 

 

Posted

What exactly do you mean with "fires twice"?

Looks like the Code is just validating actors so the actual Event is probably triggered with a Forcegreet? 

 

1 hour ago, kxdace said:

utility.wait(5)

Thats unnecessary, SetStage is latent so ForceRefTo wont be called until SetStage is already completed anyway

And dont underestimate the speed at which machines read code. The only reason why youd ever want to use Wait > 1 is because you want to purposefully make the player wait for something

 

OnInit firing twice shouldnt matter here. Youre not actually calling anything. just applying a filter. Applying a filter twice still only applies that filter once

Archived

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

  • Recently Browsing   0 members

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