Jump to content

[LE] Actor.GetParentCell() only gets a small area when outdoors... how do I reference a much larger area?


Cheyron

Recommended Posts

ObjectReference Function FindClosestChoppingBlock()
    Actor player = PlayerRef.GetActorReference()
    Cell c = player.GetParentCell()
    ObjectReference closestBed = None
    Float closestDistance = 9999.0 ;//the parent cell is much smaller than this and won't find chopping blocks near me unless i walk close to them
    Int i = c.GetNumRefs(40)
    While i
        i -= 1
        ObjectReference o = c.GetNthRef(i, 40)
        If o && !o.IsDisabled() && !o.IsFurnitureInUse(True)
            If o.GetBaseObject().GetName() == "Wood Chopping Block" ;//is there a better way to do this?
                float dist = player.GetDistance(o)
                If dist < closestDistance
                    closestBed = o
                    closestDistance = dist
                EndIf
            EndIf
        EndIf
    EndWhile
    If closestBed
        Debug.Notification("Chopping Block Found, Distance = " + closestDistance)
        Return closestBed
    EndIf
    Return None
EndFunction

ignore the variables named bed (was looking for a bed with this code earlier)

 

How can I modify this code to search multiple outdoor cells or possibly even the entire loaded world??

Link to comment
Share on other sites

Your line:

If o.GetBaseObject().GetName() == "Wood Chopping Block" ;//is there a better way to do this?

Can replace with (uses SKSE):

 

 

If o.GetBaseObject().GetType() == 40 ;is it a furniture
  If KeywordCheck(o,FurnitureWoodChoppingBlock) == true
    ;do stuff

Required function - working (is used by my Inventory Management System Rebuilt mod)

Bool Function KeywordCheck(ObjectReference TheRef, Keyword TheKW,Bool isLinkedRef = false)
    Bool result = false
    If  TheRef
        If isLinkedRef == false
            If  TheRef.GetBaseObject().HasKeyword(TheKW)
                result = true
            EndIf
        Else
            If  TheRef.HasKeyword(TheKW)
                result = true
            EndIf
        EndIf
    EndIf
    return result
EndFunction

Required property

Keyword     Property     FurnitureWoodChoppingBlock        Auto

 

 

 

Unfortunately, I cannot help you with what you really want to know. But I do know that you can fill quest aliases with the closest references when a quest is started. You may get better luck going that route. Only question then is: when to start the quest and how often to re-start the quest so that it can refresh the aliases.

Link to comment
Share on other sites

Your line:

If o.GetBaseObject().GetName() == "Wood Chopping Block" ;//is there a better way to do this?

Can replace with (uses SKSE):

 

 

If o.GetBaseObject().GetType() == 40 ;is it a furniture
  If KeywordCheck(o,FurnitureWoodChoppingBlock) == true
    ;do stuff

Required function - working (is used by my Inventory Management System Rebuilt mod)

Bool Function KeywordCheck(ObjectReference TheRef, Keyword TheKW,Bool isLinkedRef = false)
    Bool result = false
    If  TheRef
        If isLinkedRef == false
            If  TheRef.GetBaseObject().HasKeyword(TheKW)
                result = true
            EndIf
        Else
            If  TheRef.HasKeyword(TheKW)
                result = true
            EndIf
        EndIf
    EndIf
    return result
EndFunction

Required property

Keyword     Property     FurnitureWoodChoppingBlock        Auto

 

 

 

Unfortunately, I cannot help you with what you really want to know. But I do know that you can fill quest aliases with the closest references when a quest is started. You may get better luck going that route. Only question then is: when to start the quest and how often to re-start the quest so that it can refresh the aliases.

 

thank you very much. I do have the luxury of starting this procedure by key press so I can always refresh the quest at that point, maybe I will look into using quest aliases but in the past it has been unreliable to find something near me even when the conditions would meet something I was standing next to. One time I was trying to find a bed in the bannered mare and it kept giving me a bed in dragonsreach below the kitchen... that was when I was using quest aliases and matching by closest in loaded area (I am inside the bannered mare too). My conditions were it had to be in the same cell and within a certain distance of the player (like 1000 and while testing I would stand < 100 from the bed... right next to it actually)… that's why I have been resorting to finding objects via this method, it is much more reliable the only problem is when outdoors I am noticing cells are like 10ft x 10 ft squares (just guessing the size but they are small areas... I have to be within 5 feet of the chopping block for my code to work)

 

if I can loop through more cells I will just do that but I wonder how to get an array of cells around the player... I could probably spawn something invisible and move it around and grab cells but that seems kinda a hackish way to do it because obviously the game has the ability to look further than the parent cell of an object

 

thanks again!

Link to comment
Share on other sites

One thing you could do, instead of looking for just one closest reference to fill a single alias, look for multiples to fill multiple aliases. There is no harm in having say 20 aliases that would each do the same thing with whatever matching object fills it. Just make sure to flag them as optional so that the quest will continue to work in case there are not enough objects to fill those aliases.

 

Another option you may want to consider, using a hotkey and getting the crosshair reference when that key is pressed. The user would have to be right up on the object but it has the benefit of working with any object that would match your criteria. In fact, this is how my Inventory Management System Rebuilt mod works in regards to interactions with merchants, ore veins, chopping blocks, etc.

Link to comment
Share on other sites

One thing you could do, instead of looking for just one closest reference to fill a single alias, look for multiples to fill multiple aliases. There is no harm in having say 20 aliases that would each do the same thing with whatever matching object fills it. Just make sure to flag them as optional so that the quest will continue to work in case there are not enough objects to fill those aliases.

 

Another option you may want to consider, using a hotkey and getting the crosshair reference when that key is pressed. The user would have to be right up on the object but it has the benefit of working with any object that would match your criteria. In fact, this is how my Inventory Management System Rebuilt mod works in regards to interactions with merchants, ore veins, chopping blocks, etc.

 

yeah those are good ideas, I may try to fill a bunch of quest aliases, I like that idea, and then I can narrow down the one I use in the script that uses the block. Aiming could work too but I play with controller so I prefer to "automate" the choosing the block. I play with Frostfall and I am sick of chopping wood when I have followers so with this mod I like to be able to just "yell over my shoulder" using a lesser voice power to command a follower to go do it. It is pretty convenient but I would like it to work at farther range, aiming at stuff even in front of me can be tough with a controller lol... sometimes the "hitboxes" are in weird places (maybe a bug)… earlier I was playing and it took me 5 minutes to grab a pheasant off those racks in kitchens that was right in front of me... I had to aim completely off of it to grab it in that case (only happens on certain ones, not every single one luckily)

Link to comment
Share on other sites

Well I just tried filling quest aliases by matching in loaded area and checking if it has that keyword you mentioned and the aliases dont get filled even when i am in near the blocks, only my code can find the block apparently and i am resetting the quest right before checking

Link to comment
Share on other sites

I'm not sure why you're having trouble with the aliases. In the past I have found using quest alias filling to be, by far, the fastest and most reliable way to find objects in the world. If you could post the alias and its conditions, and the code which triggers it, it would help diagnose things.

Link to comment
Share on other sites

well I had just removed it from the mod since it was not working but I can easily explain what I was doing. In my quest which is running on game start not just once. it is always running. I added a quest alias to look for an object reference with the single condition to look for that keyword in the loaded area (HasKeyword: FurnitureWoodChoppingBlock… mentioned above), i did not even check the closest checkbox, i just wanted any chopping block. Then in my magic effect OnEffectStart event it would first.. Reset the quest with the chopping block aliases... theQuest.Reset() then after that I put a small Wait so the quest could have some time to reset (in case that function is not latent) and then I would check the reference that is autofilled by doing...

 

If theQuestAlias.GetReference()

;this would never be true when trying to use quest lias match condition even when i am looking at the block in front of me... only my loop works to find the block

EndIf

 

basically everything starts when i use a shout power... and the "entry" to all of this is OnEffectStart … my quest is running and I even reset the quest to fill aliases

Link to comment
Share on other sites

I'm not sure why you're having trouble with the aliases. In the past I have found using quest alias filling to be, by far, the fastest and most reliable way to find objects in the world. If you could post the alias and its conditions, and the code which triggers it, it would help diagnose things.

 

forgot to quote you, replied above

Link to comment
Share on other sites

I would stop and start the quest rather than reset. I don't think a reset will re-fill aliases with different objects. Reset should just revert any values changed during the course of play back to their original, this would included aliases. Stop and then start will completely flush the data and cause it to re-fill aliases with current matching objects.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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