15 posts / 0 new
Last post
MajinCry
MajinCry's picture
Offline
Last seen: 10 hours 46 min ago
Joined: 04/09/2013 - 12:36
Karma: 188
Calling functions on refs inside arrays?

I'm making a mod that would freeze the player's dropped items in place, and I've hit a snag. I put all the references into several arrays, then take each reference from the arrays, and call SetRigidBodyMass 100 on them. This happens whenever the player presses the insert key.

But it doesn't seem to work. The functions process as expected, the arrays are filled, and the function does get called. The references themselves, however, remain unchanged. I've attached the mod, and here are the scripts:

Script #1 is the hotkey registration script attached to a quest:

</p>
<p>scn AAAFyTyHotkeyFreezeItemsHotkeyEventScript<br />
	short bDone<br />
	<br />
	begin GameMode<br />
	    <br />
	    if bDone == 0<br />
	        SetOnKeyDownEventHandler AAAFyTyHotkeyFreezeItemsScript 1 210<br />
	        set bDone to 1<br />
	        ;StopQuest AAAFyTyHotkeyFreezeItemsQuest<br />
	    endif<br />
	<br />
	end</p>
<p>

Here's the script called by the EventHandler:

</p>
<p>scn AAAFyTyHotkeyFreezeItemsScript<br />
	int    iKeyID<br />
	<br />
	array_var array_MiscRefsInCell<br />
	array_var array_BookRefsInCell<br />
	array_var array_ClothingRefsInCell<br />
	array_var array_IngredientRefsInCell<br />
	array_var array_WeaponRefsInCell<br />
	array_var array_AmmoRefsInCell<br />
	array_var array_AlchemyRefsInCell<br />
	array_var array_Refs<br />
	<br />
	ref refItem<br />
	<br />
	begin function {iKeyID}<br />
	    <br />
	    let array_BookRefsInCell := GetRefs 25, 1<br />
	    let array_ClothingRefsInCell := GetRefs 26, 1<br />
	    let array_IngredientRefsInCell := GetRefs 29, 1<br />
	    let array_MiscRefsInCell := GetRefs 31, 1<br />
	    let array_WeaponRefsInCell := GetRefs 40, 1<br />
	    let array_AmmoRefsInCell := GetRefs 41, 1<br />
	    let array_AlchemyRefsInCell := GetRefs 47, 1<br />
	    <br />
	    Ar_Dump array_BookRefsInCell<br />
	    Ar_Dump array_ClothingRefsInCell<br />
	    Ar_Dump array_IngredientRefsInCell<br />
	    Ar_Dump array_MiscRefsInCell<br />
	    Ar_Dump array_WeaponRefsInCell<br />
	    Ar_Dump array_AmmoRefsInCell<br />
	    Ar_Dump array_AlchemyRefsInCell<br />
	    <br />
	    foreach array_Refs <- array_BookRefsInCell<br />
	        let refItem := array_Refs["value"]<br />
	        call AAAFyTyFreezeIfPlayerOwner refItem<br />
	    loop<br />
	    <br />
	    foreach array_Refs <- array_ClothingRefsInCell<br />
	        let refItem := array_Refs["value"]<br />
	        call AAAFyTyFreezeIfPlayerOwner refItem<br />
	    loop<br />
	    <br />
	    foreach array_Refs <- array_IngredientRefsInCell<br />
	        let refItem := array_Refs["value"]<br />
	        call AAAFyTyFreezeIfPlayerOwner refItem<br />
	    loop<br />
	    <br />
	    foreach array_Refs <- array_MiscRefsInCell<br />
	        let refItem := array_Refs["value"]<br />
	        call AAAFyTyFreezeIfPlayerOwner refItem<br />
	    loop<br />
	    <br />
	    foreach array_Refs <- array_WeaponRefsInCell<br />
	        let refItem := array_Refs["value"]<br />
	        call AAAFyTyFreezeIfPlayerOwner refItem<br />
	    loop<br />
	    <br />
	    foreach array_Refs <- array_AmmoRefsInCell<br />
	        let refItem := array_Refs["value"]<br />
	        call AAAFyTyFreezeIfPlayerOwner refItem<br />
	    loop<br />
	    <br />
	    foreach array_Refs <- array_AlchemyRefsInCell<br />
	        let refItem := array_Refs["value"]<br />
	        call AAAFyTyFreezeIfPlayerOwner refItem<br />
	    loop<br />
	    <br />
	end function</p>
<p>

And here's my user defined function, AAAFyTyFreezeIfPlayerOwner():

</p>
<p>scn AAAFyTyFreezeIfPlayerOwner<br />
	ref refItem<br />
	string_var strFormID<br />
	int iRefFormID<br />
	int iFFToInt<br />
	<br />
	Begin function {refItem}<br />
	    <br />
	    let iFFToInt := 4278190080<br />
	    let strFormID := GetFormIDString refItem<br />
	    let iRefFormID := ToNumber strFormID, 1<br />
	<br />
	    if iRefFormID > iFFToInt<br />
	            refItem.SetRigidBodyMass 100<br />
	            Print "Called SetRigidBodyMass"<br />
	        endif<br />
	    return<br />
	End</p>
<p>

 

Everything works, right up until refItem.SetRigidBodyMass 100. As far as I can tell, I'm properly taking the reference from the array, so it should work. But it's not. Any scripters got any idea why that is?

File Attachments: 

TTW Version Compatibility: 

v2.9

Rating: 

0
Your rating: None
0
No votes yet
James_T_Quirk
James_T_Quirk's picture
Offline
Last seen: 6 hours 20 sec ago
Joined: 02/02/2018 - 03:40
Karma: 55
An Interesting Question,

An Interesting Question, which I admit I have no answer for, I am a Learner in Fallout scripts, BUT, I think, your script helps me understand some of things I am "trying" to sort in my pile of issues ...

One being, the more crap you collect, the crashier FO3/NV/4 seem to be, by what I see here it all stored in arrays in memory, which is what is causing the crashes, maybe. I am looking at a "mod" that stores some assets in a small text files out of main software, on disk. Like specialised containers in different cells that, if you place item in, it is written off to disk file, reducing amount of data being sorted in arrays, I know I need to be careful about special items, linked workshop etc, but I am  annoyed that after building your "world" collected half the crap in the Commonwealth/Nevada/DC, & at high levels, open a Workshop/container with too much crap in it, and software slows down, then goes on holiday ..

I am sorry I am not helping with your issue, but THANKS for sharing info, that is above my paygrade, still..

jlf65
jlf65's picture
Offline
Last seen: 19 hours 58 min ago
Joined: 08/10/2016 - 14:10
Karma: 912
You need more printing to log

You need more printing to log what's going on. You print out the arrays from what I've seen, and you print when the function is called, but you should print the ref info when the function is called to make sure it's actually determining the proper form id and whatnot. More printing! I use logging for most of my debugging, and my code is sometimes half prints until it's working well.

RoyBatty
RoyBatty's picture
Administrator
Offline
Last seen: 3 hours 26 min ago
Joined: 04/27/2014 - 03:26
Karma: 5786
Donor
I can't read the script with

I can't read the script with all the HTML stuck in between it, put it on pastebin or something.

MajinCry
MajinCry's picture
Offline
Last seen: 10 hours 46 min ago
Joined: 04/09/2013 - 12:36
Karma: 188
jlf65 wrote:

jlf65 wrote:

 

You need more printing to log what's going on. You print out the arrays from what I've seen, and you print when the function is called, but you should print the ref info when the function is called to make sure it's actually determining the proper form id and whatnot. More printing! I use logging for most of my debugging, and my code is sometimes half prints until it's working well.

I did that, actually. Just removed them when I didn't need them anymore. The refs are properly filled and printing the arrays shows the refs inside them.

 

RoyBatty wrote:

 

I can't read the script with all the HTML stuck in between it, put it on pastebin or something.

The quest script: https://pastebin.com/raw/nJ1249x2

The script called by the EventHandler: https://pastebin.com/raw/kbVZWNUr

My user defined function script: https://pastebin.com/raw/Gc7m6VHn

To clarify, everything works right up until calling refItem.SetRigidBodyMass 100. It doesn't affect the reference for some reason, but it doesn't throw any errors and it prints successfully each time it's called.

MajinCry
MajinCry's picture
Offline
Last seen: 10 hours 46 min ago
Joined: 04/09/2013 - 12:36
Karma: 188
I did a bit more testing, by

I did a bit more testing, by having the script instead call refItem.Disable instead, which actually worked. So I've no idea why SetRigidBodyMass doesn't work.

Edit: And after some more testing, I found that SetRigidBodyMass does work for certain object types, like the placeable LIGH objects used in this mod: https://www.nexusmods.com/newvegas/mods/42522

For whatever reason, the function doesn't work properly with MISC, ALCH, WEAP, and AMMO references.

RoyBatty
RoyBatty's picture
Administrator
Offline
Last seen: 3 hours 26 min ago
Joined: 04/27/2014 - 03:26
Karma: 5786
Donor
Seems odd, the function is

Seems odd, the function is designed to work with those items types. Lights have no mass, don't see why it would work with them at all.

Maybe you should use logical and instead of that number stuff.

MajinCry
MajinCry's picture
Offline
Last seen: 10 hours 46 min ago
Joined: 04/09/2013 - 12:36
Karma: 188
RoyBatty wrote:

RoyBatty wrote:

Seems odd, the function is designed to work with those items types. Lights have no mass, don't see why it would work with them at all.

Maybe you should use logical and instead of that number stuff.

The number stuff is how I check if the items are player owned. It works fine, as replacing SetRigidBodyMass with Disable causes the items to be disabled, as expected.

You can have LIGH objects that have moveable models, as is shown in this mod: https://www.nexusmods.com/newvegas/mods/42522

And yeah, the function sounds like it should work for anything that can be moved, but unfortunately that's not the case. I PM'd the author of JIP about the function, in hopes that he might have some insight, or be able to create a new equivalent for SetRIgidBodyMass that will affect all item types.

RoyBatty
RoyBatty's picture
Administrator
Offline
Last seen: 3 hours 26 min ago
Joined: 04/27/2014 - 03:26
Karma: 5786
Donor
I'm not sure how checking a

I'm not sure how checking a number would tell you if it belongs to the player or not. If you mean checking if it's a reference starting with FF then logical AND would be faster, and that's no way to check if the item is owned by the player or not anyway. GetOwnership will do that that.

 

MajinCry
MajinCry's picture
Offline
Last seen: 10 hours 46 min ago
Joined: 04/09/2013 - 12:36
Karma: 188
RoyBatty wrote:

RoyBatty wrote:

I'm not sure how checking a number would tell you if it belongs to the player or not. If you mean checking if it's a reference starting with FF then logical AND would be faster, and that's no way to check if the item is owned by the player or not anyway. GetOwnership will do that that.

Unfortunately, IsOwner and GetOwner do not work for this. Items dropped by the player are not owned by the player. There are only two ways around this; the first is to check for the ID to be greater than FF000000 as almost all dropped items have an ID beginning with FF, and the other would be to have the player somehow set the ownership manually.

RoyBatty
RoyBatty's picture
Administrator
Offline
Last seen: 3 hours 26 min ago
Joined: 04/27/2014 - 03:26
Karma: 5786
Donor
Any temp ref begins with FF,

Any temp ref begins with FF, so that is no indication it is owned by the player if the item has been spawned in.

Perhaps an OnDrop event handler with a filter for the player would be the only reliable way to know if the item was in the player container or not. Even then they can steal items and the ownership is not cleared on them, so you can still detect if the item is owned by the player or another NPC specifically if needed.

Mystical Panda
Mystical Panda's picture
Offline
Last seen: 7 hours 4 min ago
Joined: 03/30/2016 - 07:02
Karma: 736
Just off the top of my head..

Just off the top of my head... If that doesn't work, then you might need to do a quick 'scan' of the immediate area surrounding the player by ref (definitely inefficient, and if done in a loop can really task the scripting vm- the smaller the area the better), if that type of function exists in the extender or plugins your using, and look at any item you just dropped (FFxxxxxx) and set the ownership directly on it that way. OnDrop would be a good a way to just 'event' to the script code without using a loop if it can return the specified item dropped and not just 'remove' the item from the player and 'add' it back to the world with a new reference (but same properties). If the reference is the same, just check for items you don't have anymore, and match a 'gathered' list to just that single or multiple refs.

MajinCry
MajinCry's picture
Offline
Last seen: 10 hours 46 min ago
Joined: 04/09/2013 - 12:36
Karma: 188
Doing the scan for FF FormIDs

Doing the scan for FF FormIDs works fine. The only problem is that SetRigidBodyMass only works on a couple object types.

Mystical Panda
Mystical Panda's picture
Offline
Last seen: 7 hours 4 min ago
Joined: 03/30/2016 - 07:02
Karma: 736
I had a similar problem too

I had a similar problem too when trying to get or set the weight of a body (object) I was carrying in my inventory- carrying companions and people back for burial (grave yard at megaton); the first mod I did for FNV awhile back.

The function existed to set it, but for some reason trying to use or call it caused the script to completely hang. The vm just kept chugging as though nothing was wrong, but the script was limbo-ed. It might be something along the same lines.

MajinCry
MajinCry's picture
Offline
Last seen: 10 hours 46 min ago
Joined: 04/09/2013 - 12:36
Karma: 188
Mystical Panda wrote:

Mystical Panda wrote:

 

I had a similar problem too when trying to get or set the weight of a body (object) I was carrying in my inventory- carrying companions and people back for burial (grave yard at megaton); the first mod I did for FNV awhile back.

The function existed to set it, but for some reason trying to use or call it caused the script to completely hang. The vm just kept chugging as though nothing was wrong, but the script was limbo-ed. It might be something along the same lines.

 

The script works fine, and it calls the function as well as the following print function. It's just that the function itself will only work on a small number of object types.