Jump to content

Problem making papyrus script


ayeayeaye

Recommended Posts

Hi,

I'm trying to write a papyrus script that limits the amount of ammo of a certain type that the player can carry at any one time, but I'm getting an error when I try to compile it: here's the script:

Scriptname PlayerLimitAmmoScript extends Actor Const


Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
    if (Game.GetPlayer().GetItemCount(Ammo44) >= 30)
        Game.GetPlayer().RemoveItem(Ammo44, (Game.GetPlayer().GetItemCount(Ammo44) - 30), true) 
    EndIf
EndEvent

And this is the error:

Starting 1 compile threads for 1 files...
Compiling "PlayerLimitAmmoScript"...
C:\Users\Will\AppData\Local\Temp\PapyrusTemp\PlayerLimitAmmoScript.psc(4,35): variable Ammo44 is undefined
C:\Users\Will\AppData\Local\Temp\PapyrusTemp\PlayerLimitAmmoScript.psc(5,30): variable Ammo44 is undefined
C:\Users\Will\AppData\Local\Temp\PapyrusTemp\PlayerLimitAmmoScript.psc(5,69): variable Ammo44 is undefined
No output generated for PlayerLimitAmmoScript, compilation failed.


Batch compile of 1 files finished. 0 succeeded, 1 failed.
Failed on PlayerLimitAmmoScript

Sorry if this is a stupid question, this is my first time trying to write my own script in Papyrus

Thanks,

Will

 

Link to comment
Share on other sites

You forgot to make the property for the ammo.

You need to use AddInventoryEventFilter() and pass in the ammo, otherwise the Event wont work.

You need to instead attach that script to the Player in an Alias(Dummy Quest) instead of directly on the player.


It might be easier to instead remove the ammo based on aiItemCount as that records how many of that item was added.

Link to comment
Share on other sites

As TummaSuklaa said You need to add a property for your ammo Like this:

 Ammo Property Ammo44 Auto
And Before you can use OnItemAdded you will need to add an inventory event filter for your ammo Like this

Event OnInit()
    AddInventoryEventFilter(Ammo44)
EndEvent
The AddInventoryEventFilter() can also have use a formlist of different ammo types in case you want to do more than just 44 ammo

If this is the case I would suggest changing your OnItemAdded event to:

     
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)

   if (Game.GetPlayer().GetItemCount(akBaseItem) >= 30)
       Game.GetPlayer().RemoveItem(akBaseItem, (Game.GetPlayer().GetItemCount(akBaseItem) - 30), true)
   EndIf
EndEvent
This way you can have one script to handle all the different ammo types in your formlist.

If you want to have different max amounts per ammo type you can still use this just add an if statement that checks which ammo type was added.

I would also suggest swapping the Game.GetPlayer() for a property like this:

 Actor Property PlayerREF Auto
This is more efficient.

To get this to work you will have to create a quest and add this script to an alias for the player.

Edited by LoneRaptor
Link to comment
Share on other sites

  • Recently Browsing   0 members

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