Jump to content

Function to make player grab an item?


Hoamaii

Recommended Posts

I've been searching the wiki and SKSE's objectReference and Actor functions but I can't find any specific function that'll make the player grab a referenced object...

 

Is there one I have missed, or a set of functions that'll help me do that?

 

(I'm reluctant to use SKSE HoldKey(Int KeyCode) because of non-US keyboards and gamepads...)

 

Thanks! :)

Link to comment
Share on other sites

I've been searching the wiki and SKSE's objectReference and Actor functions but I can't find any specific function that'll make the player grab a referenced object...

 

Is there one I have missed, or a set of functions that'll help me do that?

 

(I'm reluctant to use SKSE HoldKey(Int KeyCode) because of non-US keyboards and gamepads...)

 

Thanks! :smile:

I don't have an answer,

But for the HoldKey(Int KeyCode) is not really a problem with keyboard or game pad layouts as you can use in combination with GetMappedKey() function:

http://www.creationkit.com/GetMappedKey_-_Input

 

Using this method it makes no difference to what key or layout the user has their keys setup.

Link to comment
Share on other sites

You want it to appear as if the player has picked up an object and is carrying it?

 

You could either use existing animations that are close or maybe make new ones that cause the player to appear to do what you want. At the right moment you'd have the static disabled and if it is an item you want to be in the player's inventory (as well as visually carried) then add an instance to the player.

 

Beyond that (and I have no clue how to do it), I can't think of any way to achieve what you are wanting.

Link to comment
Share on other sites

Thanks for your inputs, guys :smile:

 

Actually, I need the player not to look like he's grabbing the item, but rather have the item already "z-keyed" when he exists the scripted menu. Faking it with respawning a clutter item doesn't seem to do the trick (I tried that). One of the issues I face with getting another item from the player's inventory is that if I used "PlaceAtMe" on a Motion_Dynamic item, the coordinates used are always the ones where the item 1st loaded when dropped - in mid-air. I can't find a way to GetPosition of an item once it has fallen to the ground.

 

Here's what I was trying to do: drop an item to the ground, display a menu when activating the dropped item and have the option to grab it in the menu. If I use "placeAtMe" to disable the dropped item and spawn a new one to grab, the new item will only spawn at the location where the dropped item loaded, not where it has fallen. On uneven ground, it looks horrible, but it doesn't look too good either on flat ground. I'm not not good at using Math to recalculate the coordinates relative to where the player is standing rather than from the dropped object, but I tried that too - though looking better, it slows down the script a lot - sometimes objects (even simple, low rez ones) take a hell of a long time to load their 3D.

 

It was mostly a "cosmetic" idea anyway, I suppose I can do without it or find another way around it. I'll post it here if I find something - or if anybody can help me figure out how to get the precise world coordinates of a fallen havok-enabled object, that'd help me too. Thanks again :smile:

Link to comment
Share on other sites

It sounds like you have a custom item and you want the player to be able to move it around but you're also then trying to adjust its position via script or even by letting the player grab it to move it. You're in for a load of pain if you try to do it that way, I learned that the hard way developing my Storage Helpers mod. You can't get accurate coordinates of an item the player drops after it's been affected by Havok and if the player leaves the cell and returns the game will still think it's in the spot where it was originally dropped anyway.

 

You can't wait until the dropped item hits the ground, you have to replace it right as it comes out of inventory. Monitor the inventory change (either from a script on a player alias or on the item itself) and spawn a new copy into the world immediately and delete the item that was just dropped. The newly spawned item is the one that falls to the ground and its collision information is correctly updated and it will keep its position if the player re-enters the cell later.

Link to comment
Share on other sites

Hey cdcooley,

 

Yeah, I suddenly remembered that from when working on my Clearsky mod where I created a droppable bag which could be opened when dropped, I had to swap the armor ground piece for an item onLoad() and immediately delete the armor ground piece - one year not modding and you forget a few things ;). Anyway, that worked ok in Clearsky because I didn't need to track the item's coordinates afterwards.

 

What I'm trying to do here is somewhat different because I'm swapping items for statics. I'm working on a follow up of my 'sleep under blankets' idea from the same mod. In Clearsky it was fairly easy because beds were static and persistent. Here, I'm trying to do the same thing with placeable bedrolls. Dropping an item (a rolled bedroll) from the player inventory, let the player place that item where he wants, then swap that item for a dummy static (or a furniture bedroll - not sure yet, depending on the features I add to this). I need to detect the precise coordinates where that item is placed before swapping because I also need to place disabled blankets on the exact same position as the placed bedroll. For many reasons mainly due to the animation positioning being completely unreliable depending on the entry point, I cannot GetPosition from the player, I have to do it from the static bedroll.

 

I'm facing two issues here: GetPosition, GetAngle and GetDistance are incredibly slow to run (as you clearly stated in your Performance Characteristics on you Bethsoft thread which I only discovered a few days ago) AND the dummy or furniture forms are incredibly slow to load their 3D. The two combined seem to affect the coordinates detection and always get at least one wrong - usually the Angle but not always, even though I do use an iterative wait until 3D is fully loaded before I call getPosition.

 

What I did was: 1. drop the item 2. immediately swap it on load for another instance 3. once that instance has been placed by the player, swap it for a static form 4. once the static is 3D loaded, place the disabled blanket. That's calling PlaceAtMe 3 times and GetPosition, Angle and Distance twice, possibly 3 times even if I need to use a dummy before placing the furniture (because I don't want to attach any script at all to Vanilla furniture). Not to mention that, for other reasons, I also need to call FindClosestReferenceOfTypeInList in the same script - and that script takes forever to do its job...

 

That's why I'm trying to find a way to reduce significantly that delay by skipping one step if I can or possibly use PlaceAtMe without having to call GetPosition first. As for finding a function to make the player Grab an item from script, I'm leaving that aside for the moment until I've solved my other issues.

Link to comment
Share on other sites

If you post or PM the code to me I can see if there's anything I can see to make it a little more efficient. After building my Storage Helpers mod I've got some experience in that sort of thing, but sometimes there isn't a good optimization. I would post my code from Storage Helpers used to place items but it's got too much stuff related to making sure container contents are moved with the containers and I use custom movement scripts to let the player place the containers instead of grabbing.

Link to comment
Share on other sites

Thanks for the offer, cd, I might actually do that once I've cleaned up my scripts from all ;disabled functions and dozens of debug lines :wink:

 

I've made some progress by placing the static item relatively to the player position (no matter what I try, the damn thing keeps loading in mid-air if I don't - even if I change the motionType onLoad) but that works fairly ok so far, everything else gets positioned correctly, no errors appear in my logs and the scripts run way faster. I'm facing another unexpected issue right now, one of the cleaning functions loops forever on one of the scripts (not on 1st placement, but on 2nd placement, with exactly the same script!) and I can't figure out why it would do that... :wallbash: A friend mentionned Windows Prefetch files f***ing up SKSE_Loader sometimes and sure enough, when I start to get unexplainable CTD from the launch screen (my mods not even loaded yet), it only takes that I trash that Prefetch and the game loads fine afterwards. I have no idea what these Prefetch do but they obvioulsy have some sort of unpleasant impact.

 

So thanks, I might take up on your offer once I've pinned down that looping annoyance and cleaned things up a bit :smile: Cheers, man!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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