ayeayeaye Posted August 27, 2016 Share Posted August 27, 2016 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 EndEventAnd 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 PlayerLimitAmmoScriptSorry if this is a stupid question, this is my first time trying to write my own script in PapyrusThanks,Will Link to comment Share on other sites More sharing options...
TummaSuklaa Posted August 28, 2016 Share Posted August 28, 2016 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 More sharing options...
LoneRaptor Posted August 28, 2016 Share Posted August 28, 2016 (edited) As TummaSuklaa said You need to add a property for your ammo Like this: Ammo Property Ammo44 AutoAnd Before you can use OnItemAdded you will need to add an inventory event filter for your ammo Like thisEvent 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 ammoIf 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 EndEventThis 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 AutoThis 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 August 28, 2016 by LoneRaptor Link to comment Share on other sites More sharing options...
ayeayeaye Posted August 30, 2016 Author Share Posted August 30, 2016 Thanks Loneraptor. I`ll try and get that to work next time I've a spare moment- and thanks especially for going into more depth with your answer: I couldn't fix it with the above comment (not that I don't appreciate it). Link to comment Share on other sites More sharing options...
Recommended Posts