Jump to content

Give order to your companion


Recommended Posts

Hello fine people from this board

 

I need your help...again

 

I have a animal companion and I would like to give him one order: "fetching an object for me"

The idea is as follow:

When pressing a key let's say "P" the animal switch into "pick up mode" I point toward with my mouse and click on it and the animal gets the object for me placing the object into a chest (his or mine).

Is this possible. Is there an another way.

In short any idead how I go about doing this.

 

Thanks for your help gals and guys.

 

Link to comment
Share on other sites

OBSE has all the functions to implement this.

 

OnKeyDown to detect the keyboard key press

GetCrosshairRef to identify the object pointed by the mouse

Several SetPackage<xxx> to dynamically adjust the animal AI package to fetch the object

Activate2 to move the object to the proper container

 

I've been away from scripting for a while and coding details are starting to fade, but this is the general idea:

A simple implementation would be an ever running quest the check for the key press every frame. When the key press is detected, it adjusts a pre-existing AI Package with data about the object under the cursor. When the animal reaches the object, the OnPackageDone block moves the object to the proper container.

 

A more complex implementation would allow for queuing objects, so you could point-and-press various objects even before the animal reached the first one.

 

 

 

Link to comment
Share on other sites

Also, as is mentioned on the GetCrosshairRef wiki page, you might need to adjust the iActivatePickLength but only for the duration needed to register a reference that is too far to be normally returned by GetCrosshairRef. I have done a system exactly as the one you described for my follower management system mod, and while the system could be improved a little (it is on my to-do list, but I have not had the time to work on anything mod-related for a while), the basic idea that definitely works is the one described by QQuix. For getting the ref at crosshair at a distance:

  • run a quest every frame, starting with "idle state", and with at least two variables: a ref and a float - the ref to store the target crosshair reference, the float to store the original iActivatePickLength
  • if the player is not holding down the command hotkey, and the stored iActivatePickLength is < 1, skip everything
  • if the stored iActivatePickLength is > 0, then use GetCrosshairRef to get the currently-pointed-at ref (you can now use it, but remember, it can be None still, if the player is not pointing at anything!), and restore iActivatePickLength to the stored value and reset the stored value to 0
  • otherwise, if the stored iActivatePickLength is < 1 and player is holding down the hotkey, then store the original iActivatePickLength value to a variable and raise the real value to your custom value (like 4000) - then skip all else and wait for a new frame

Something like that. As for the AI package, you can also use (if the animal has animations for it) some sort of use-item-at package or somesuch. I cannot remember what I used, exactly, myself, but it is possible to create an xmarker and an AI package with the AI package pointing at that xmarker and then move the xmarker to the target ref. But changing the location data of a package would definitely be a nice and neat way to do it! It is something I will try when I have a chance to update my mod. :smile:

 

When scripted, maybe something like that, although you probably should not copy-paste it, being untested and more of an idea.

scriptname SomeQuestScript

float fQuestDelayTime  ; <-- set to 0.01 to run basically every frame
long YourCustomHotkey
float OriginalActivatePickLength
ref CrosshairRef

begin _GameMode
    if eval ( !( OnKeyDown YourCustomHotkey ) && ( OriginalActivatePickLength < 1 ) )
        return
    endif
    if eval ( OriginalActivatePickLength > 0 )
        ; note that, according to wiki, this might return 0 for a few frames even though there is an object!
        ; the script might need adjusting to account for that - also something could be done to prevent the player
        ; from using the activate key to grab the item, too, if that is even possible
        let CrosshairRef := GetCrosshairRef
        SetNumericGameSetting iActivatePickLength OriginalActivatePickLength
        let OriginalActivatePickLength := 0
    else
        ; somehow get the current value for this
        let CrosshairRef := 0
        let OriginalActivatePickLength := GetGameSetting iActivatePickLength
        SetNumericGameSetting iActivatePickLength 4000
    endif
end
Link to comment
Share on other sites

Thank you guys, both of you. I will probably work on Contrathetix script, try to understand it and test it extensively. I will come back to you guys and the board probably on monday. Thanks again for your kind help.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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