Jump to content

Need some help with Fallout 4 papyrus scripting, please!


Recommended Posts

Well, then I would replace those 4 lines:

        int c_grenade_frag_scrap_Count =  PlayerRef.GetItemCount(c_grenade_frag_scrap)
        int fragGrenade_Count =  PlayerRef.GetItemCount(fragGrenade)

        PlayerRef.removeItem(c_grenade_frag_scrap, c_grenade_frag_scrap_Count, abSilent = true)
        PlayerRef.addItem(fragGrenade, fragGrenade_Count, abSilent = true)

With those 2:

        PlayerRef.removeItem(c_grenade_frag_scrap, aiItemCount, abSilent = true)
        PlayerRef.addItem(fragGrenade, aiItemCount, abSilent = true)

This way if 4 c_grenade_frag_scrap enter in to the player inventory this script will convert them in to 4 grenades, by removing (removeItem) the quantity that is entering to the inventory (aiItemCount) of c_grenade_frag_scrap, and adding (addItem) the same quanity (aiItemCount) of grenades (fragGrenade), all of this done without notifications (abSilent = true).

Edited by DieFeM
Link to comment
Share on other sites

:thumbsup: Glad it worked. Thanks for the video.

No, thank you!

 

One quick question, the AddInventoryEventFilter(), do I need to list every item I want the script to filter for, for example

 

AddInventoryEventFilter(c_grenade frag scrap, c_grenade_molotov_scrap, c_grenade_baseball_scrap)

 

Or do I need an event filter for each item, i.e.

 

AddInventoryEventFilter(c_grenade_frag_scrap)

AddInventoryEventFilter(c_grenade_molotov_scrap)

AddInventoryEventFilter(c_grenade_baseball_scrap)

 

Or something else?

 

Thanks again!

 

Edit: the CK wiki says you can use a formlist? Would that be best?

Edited by cerebii
Link to comment
Share on other sites

Only the second example would work.

Indeed a formlist would be the best option for many objects, but you would need to deal with formlist indexes when you want to access elements individually.

 

For example, if you want to access c_grenade_frag_scrap, and it is the third element of your list, you would need to do:

 

MiscObject c_grenade_frag_scrap = MyScrapList.GetAt(2) As MiscObject

 

That way you get the index 2 of the formlist, which is the third element. Note that the first index is zero.

Link to comment
Share on other sites

Only the second example would work.

Indeed a formlist would be the best option for many objects, but you would need to deal with formlist indexes when you want to access elements individually.

 

For example, if you want to access c_grenade_frag_scrap, and it is the third element of your list, you would need to do:

 

MiscObject c_grenade_frag_scrap = MyScrapList.GetAt(2) As MiscObject

 

That way you get the index 2 of the formlist, which is the third element. Note that the first index is zero.

When you say "access elements individually", how would this relate to the script?

Would I need to replace every instance of "c_grenade_frag_scrap" with "MiscObject c_grenade_frag_scrap = MyScrapList.GetAt(2) As MiscObject"?

 

Edit: Tested the script out with a formlist and it seems to just work so I think I'm good, thanks again :smile:

Edited by cerebii
Link to comment
Share on other sites

only once in each event where you want to use it.

 

Or you can declare the variables outside of the events, so they are available inside of all events like the properties, I guess that's the best choice if you really need to do that.

 

Or, having in to account that you have 2 objects, the scrap (c_grenade_frag_scrap) and the replacer (fragGrenade), you could use two lists

MiscObject Property c_grenade_frag_scrap Auto Const
Weapon Property fragGrenade Auto Const

Replace with 2 formlist:

FormList Property MyScrapList Auto Const
FormList Property MyReplacerList Auto Const

When you create the formlist, if you place the scrap and the replacer in the same index in their respective formlists then you can use:

int index = MyScrapList.Find(akBaseItem)
form scrap =  MyScrapList.GetAt(index)

to get the current scrap index based on the base item that just triggered the event, so no mater what scrap, you'll get the proper replacer using the resulting index because you placed it in the same spot (index) in the list than the scrap:

form Replacer =  MyReplacerList.GetAt(index)
Edited by DieFeM
Link to comment
Share on other sites

 

only once in each event where you want to use it.

 

Or you can declare the variables outside of the events, so they are available inside of all events like the properties, I guess that's the best choice if you really need to do that.

 

Or, having in to account that you have 2 objects, the scrap (c_grenade_frag_scrap) and the replacer (fragGrenade), you could use two lists

MiscObject Property c_grenade_frag_scrap Auto Const
Weapon Property fragGrenade Auto Const

Replace with 2 formlist:

FormList Property MyScrapList Auto Const
FormList Property MyReplacerList Auto Const

When you create the formlist, if you place the scrap and the replacer in the same index in their respective formlists then you can use:

int index = MyScrapList.Find(akBaseItem)
form scrap =  MyScrapList.GetAt(index)

to get the current scrap index based on the base item that just triggered the event, so no mater what scrap, you'll get the proper replacer using the resulting index because you placed it in the same spot (index) in the list than the scrap:

form Replacer =  MyReplacerList.GetAt(index)

Ah, I see, yeah, that would definitely be a cleaner way of doing things.

 

At the moment, I've got multiple component items coming from each c_grenade_scrap item, i.e.

 

 

If akBaseItem == c_grenade_frag_scrap

PlayerRef.removeItem(c_grenade_frag_scrap, aiItemCount, abSilent = true)

PlayerRef.addItem(c_adhesive_scrap, aiItemCount*2, abSilent = true)

PlayerRef.addItem(c_aluminum_scrap, aiItemCount, abSilent = true)

PlayerRef.addItem(c_fertilizer_scrap, aiItemCount*2, abSilent = true)

PlayerRef.addItem(c_oil_scrap, aiItemCount*2, abSilent = true)

PlayerRef.addItem(c_springs_scrap, aiItemCount, abSilent = true)

EndIf

So I don't know how or if that could be made to work here.

 

Anyway it works so the less I mess around with it the better lol :laugh:

Link to comment
Share on other sites

There you have an example:

FormList Property MyScrapList Auto Const
FormList Property MyReplacerList Auto Const

Event OnQuestInit()
	AddInventoryEventFilter(MyScrapList)
    RegisterForRemoteEvent(Game.GetPlayer(), "OnItemAdded")   ;Need to register this script to the "OnItemAdded" event
EndEvent

Event ObjectReference.OnItemAdded(ObjectReference akSource, Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
	int index = MyScrapList.Find(akBaseItem)
	
	form scrap = MyScrapList.GetAt(index)
	form replacer = MyReplacerList.GetAt(index)
	
	Game.GetPlayer().removeItem(scrap, aiItemCount, abSilent = true)
	Game.GetPlayer().addItem(replacer, aiItemCount, abSilent = true)
EndEvent

Link to comment
Share on other sites

  • Recently Browsing   0 members

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