Jump to content

Need some help with Fallout 4 papyrus scripting, please!


Recommended Posts

That script will not work either as your trying to add an inventory event filter to a quest script which has no inventory context so OnItemAdded will never actually fire.

 

But I am too tired to argue to points, so good luck.

 

I copied this code from one of my mod. The original code:

Weapon Property BaseballGrenade Auto Const
Actor Property PlayerRef Auto Const
Keyword Property GRTHKeyword Auto Const


Event OnQuestInIt()
   AddInventoryEventFilter(BaseballGrenade)
EndEvent

Event ObjectReference.OnItemRemoved(ObjectReference akSource, Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
  if akBaseItem == BaseballGrenade && aiItemCount == 1 && !akDestContainer && !UI.IsMenuOpen("PipboyMenu")
     (PlayerRef as actor).SayCustom(GRTHKeyword)
  endif
EndEvent

It's working for me. Or at least I haven't noticed any problems.. :smile:

 

Can you be a bit more specific?

Edited by LarannKiar
Link to comment
Share on other sites

c_grenade_frag_scrap_Count is undefined

 

Note that you defined c_grenade_frag_scrapCount, then used c_grenade_frag_scrap_Count which contains an underscore before Count.

Link to comment
Share on other sites

c_grenade_frag_scrap_Count is undefined

 

Note that you defined c_grenade_frag_scrapCount, then used c_grenade_frag_scrap_Count which contains an underscore before Count.

Derp, sorry.

 

Compiled successfully!

 

I will now go see if it works, fingers crossed!

 

And thank you everyone!

Link to comment
Share on other sites

 

A bunch of stuff

Thanks so much for the reply!

 

So I've got:

 

 

 

Scriptname nadescript extends Quest Const

 

 

MiscObject Property c_grenade_frag_scrap Auto Const

Weapon Property fragGrenade Auto Const

Actor Property PlayerRef Auto Const

 

Event OnQuestInit()

AddInventoryEventFilter(c_grenade_frag_scrap)

AddInventoryEventFilter(fragGrenade)

EndEvent

 

Event ObjectReference.OnItemAdded(ObjectReference akSource, Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)

 

If akBaseItem == c_grenade_frag_scrap

 

int c_grenade_frag_scrapCount = 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)

 

EndIf

 

EndEvent

 

And the following errors:

 

 

variable c_grenade_frag_scrap_Count is undefined Ln 20 Col 45

type mismatch on parameter 2 - cannot pass a none to an int ln 20 Col 45

 

 

You mistyped it. It should look like this:

Scriptname NewScript0 extends Quest Const

MiscObject Property c_grenade_frag_scrap Auto Const
Weapon Property fragGrenade Auto Const
Actor Property PlayerRef Auto Const

Event OnQuestInit()
    AddInventoryEventFilter(c_grenade_frag_scrap)
    AddInventoryEventFilter(fragGrenade)
EndEvent

Event ObjectReference.OnItemAdded(ObjectReference akSource, Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)

    If akBaseItem == c_grenade_frag_scrap

        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)

    EndIf

EndEvent

EDIT: Oh, I see you solved it already. :)

Edited by LarannKiar
Link to comment
Share on other sites

 

That script will not work either as your trying to add an inventory event filter to a quest script which has no inventory context so OnItemAdded will never actually fire.

 

But I am too tired to argue to points, so good luck.

 

I copied this code from one of my mod. The original code:

Weapon Property BaseballGrenade Auto Const
Actor Property PlayerRef Auto Const
Keyword Property GRTHKeyword Auto Const


Event OnQuestInIt()
   AddInventoryEventFilter(BaseballGrenade)
EndEvent

Event ObjectReference.OnItemRemoved(ObjectReference akSource, Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
  if akBaseItem == BaseballGrenade && aiItemCount == 1 && !akDestContainer && !UI.IsMenuOpen("PipboyMenu")
     (PlayerRef as actor).SayCustom(GRTHKeyword)
  endif
EndEvent

It's working for me. Or at least I haven't noticed any problems.. :smile:

 

Can you be a bit more specific?

 

 

SKK is right, the context should be an actor or a reference because OnItemAdded is an ObjectReference event, for it to work outside of such context you would need to use RegisterForRemoteEvent, so the script knows what inventory are you trying to watch.

Link to comment
Share on other sites

Ah, you're right guys.. :smile:

 

Sorry, forgot to add the RegisterForRemoteEvent(PlayerRef, "OnItemAdded") line..

Scriptname NewScript0 extends Quest Const

MiscObject Property c_grenade_frag_scrap Auto Const
Weapon Property fragGrenade Auto Const
Actor Property PlayerRef Auto Const

Event OnQuestInit()
    AddInventoryEventFilter(c_grenade_frag_scrap)
    AddInventoryEventFilter(fragGrenade)
    RegisterForRemoteEvent(PlayerRef, "OnItemAdded")   ;Need to register this script to the "OnItemAdded" event
EndEvent

Event ObjectReference.OnItemAdded(ObjectReference akSource, Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)

    If akBaseItem == c_grenade_frag_scrap

        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)

    EndIf

EndEvent
Edited by LarannKiar
Link to comment
Share on other sites

I'm a bit confused about what this script is supposed to do but, as is, if c_grenade_frag_scrap is what you get when you scrap a grenade (which by default - vanilla - I would say you can't) it will remove all grenade scrap from your inventory (which could be replaced by -1 in the iCount argument, because -1 means all), then you get as many grenades as you currently have in the inventory...

 

 

EDIT:

 

On the other hand, if you use aiItemCount, which is the number of scrap that you are actually receiving in the event, it would make much more sense, because you would be removing the quantity of scrap you are actually scrapping and adding the number of grenades you are scrapping...

 

Well, thinking it twice, you scrap 7 grenades and you receive 7 grenades, in a very convoluted way...

 

EDIT 2:

 

Unless c_grenade_frag_scrap is a broken grenade, that would make sense.

 

EDIT 3:

 

Sorry for the edits, but I think I've solved the puzzle. I deduce that c_grenade_frag_scrap is a component you receive from scraping some other explosive thing. Am I right?

Edited by DieFeM
Link to comment
Share on other sites

I'm a bit confused about what this script is supposed to do but, as is, if c_grenade_frag_scrap is what you get when you scrap a grenade (which by default - vanilla - I would say you can't) it will remove all grenade scrap from your inventory (which could be replaced by -1 in the iCount argument, because -1 means all), then you get as many grenades as you currently have in the inventory...

 

Yeah this is to just test the script, the idea is to take the c_grenade_scrap and give a grenade back... I'm hoping to edit it with all the c_grenade_scrap items I've added and have them automatically swap out for the right components, the reason I need a script is because you can't have non-CMPO items tagged as components on a misc item or the game just crashes when it tries to read it or whatever, and some of the recipies for grenades require stuff like nuka cola and other grenades.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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