Jump to content

Determining if a object is in a list.


ajs52698

Recommended Posts

Im having a hard time figuring out a way to have a script search to see if a object is in a formlist. Need some help \:

 

Ive gotten this far

 

 

ScriptName Script extends Objectreference
Formlist Property List auto
Event OnHit(aktarget)
Int ListInt == List.GetSize()
Int RandomResourceChance
If aktarget == List.Getat()
Again im having a hard time figuring out how I would go about having the script search a formlist.
Edited by ajs52698
Link to comment
Share on other sites

The Event you are using is complicating in Fallout 4 (it's easier in Skyrim, but it's been changed because stack overflow is just too easy..) and I can't wrap my head around doing it. You have to register for a hit event first: http://www.creationkit.com/fallout4/index.php?title=RegisterForHitEvent_-_ScriptObject and also, that event wouldn't run anyway because you don't have all the parameters. All parameters need to be present, or the compiler will complain. http://www.creationkit.com/fallout4/index.php?title=OnHit_-_ScriptObject

I will however right out a basic function for searching through a formlist. I am better with arrays for they are faster, so I might be a little off with this.

Formlist property MyRefList auto

Int Function GetRefInList(Form akForm)
    ; Checks the Formlist if this form is in it.
    if MyRefList.HasForm(akForm)
        int iIndex = akList.GetSize()
        ; Counts down until it reaches 0
        While iIndex > 0
            iIndex -= 1
            ; Going through the list, from the last index to the first.
            ; Comparing each form to the passed in form.
            if MyRefList.GetAt(iIndex) == akForm
                ; Return the index for the matching form.
                return iIndex
            EndIf
        EndWhile
    EndIf
    ; If not found return this value instead.
    return -1
EndFunction
Edited by TummaSuklaa
Link to comment
Share on other sites

So with this script you have to define the hasform.() no?I was going to use this at first but I didnt because I wanted to avoid typing out all of the forms im trying to search for, theres a lot, very time consuming

Edited by ajs52698
Link to comment
Share on other sites

Ty this:

ScriptName Script extends Objectreference 

Formlist Property List Auto
Actor Property PlayerREF Auto

Event OnInit()
    RegisterForHiteEvent(PlayerREF)
EndEvent

Event OnHit(ObjectReference akTarget, ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked, string apMaterial)
    int Index = Find(akTarget)
    If Index >= 0
       ;put here watherver you want to do if it is in the formlist
    Else
       ; akTarget does not appear in the formlist
    EndIf
EndEvent

I am assuming here that you want to search for what hit the player if not just change PlayerREF to wathever you want to check on.
This script will need to be added to a dummy quest to work.

Link to comment
Share on other sites

No you make a formlist and the onHit event fills in the akTarget and then the Find function seaches your formlist.
But if you want to know if the item that got hit is in a formlist this might not work as the onhit in this case only triggers when the player is hit. You would have to attach this script to everything you want to check on and then replace PlayerREF in the RegisterForHitEvent with Self.

 RegisterForHitEvent(Self)

Which migt not be the best approach.

Edited by LoneRaptor
Link to comment
Share on other sites

This is what you want. I haven't checked to see if this exact script compiles, but I've written code like this before:

Scriptname RenFormlistHitQuestScript extends Quest
 
Formlist Property List Auto
; formlist filled with objectreferences, not baseids
 
int listsize = 0
 
Event OnInit()
   listsize = List.GetSize()
   int itr = 0
   while (itr < listsize)
      Self.RegisterForHitEvent(List.GetAt(itr))
      itr += 1
   endWhile
   Self.RegisterForRemoteEvent(Game.GetPlayer(), "OnPlayerLoadGame")
endEvent
 
Event Actor.OnPlayerLoadGame(Actor akSender)
   if (listsize != List.GetSize())
      int itr = 0
      Self.UnregisterForAllHitEvents(none)
      while (itr < List.GetSize())
         Self.RegisterForHitEvent(List.GetAt(itr))
         itr += 1        
      endWhile
   endif
   listsize = List.GetSize()
endEvent
 
Event OnHit(ObjectReference akTarget, ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked, string apMaterial)
   ; do whatever you need to do here.
endEvent
Edited by Reneer
Link to comment
Share on other sites

  • Recently Browsing   0 members

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