Troubles with additem command in Papyrus..

Post » Mon Jun 18, 2012 2:35 am

I've been trying too get this rather simple, in my mind anyways, script working in skyrim sinse the release of the CK. But the new scripting language, Papyrus, has been completely defeating me at every turn...

I am trying too make a script for a bow that, when activated, adds arrows too the players inventory, equips these arrows, AND damages the players magicka too simulate magicka being used too "summon" the arrows. It is supposed too be a continually running script that keeps track of the number of arrows in the inventory and only summon more arrows when this number drops below the minimum. I know I could probably just have the bow use a spell effect too summon the arrows now, but this script is just a stepping stone too a much more complex mod I have in the works. And the more complex mod will need too use the additem command instead of a spell.

Right now, the script only cycles once. The magicka use part of the script works just fine, it does damage my magicka like it is trying too add the arrows. But for some reason, I just can't get the script too add any arrows too my inventory, none show up. I also need too figure out how too get this monitor, additem, damage magicka cycle too operate continuously, when the bow is equipped, without the player having too do anything.

This is what I have too start out with... Any ideas what I am missing here too get it too work properly? It compiles correctly and says there are no errors...

Scriptname Summonerbow extends ObjectReferenceAmmo property DaedricArrow AutoEvent OnEquipped(Actor akActor)if (Game.GetPlayer().GetItemCount(DaedricArrow) < 2)  Game.GetPlayer().AddItem(DaedricArrow, 1, true)  Game.GetPlayer().DamageActorValue("magicka", 20)  Game.GetPlayer().EquipItem(DaedricArrow, false, true)endifendeventEvent OnUnEquipped(Actor akActor);Game.GetPlayer().removeitem(Summonedarrow, 2, true)endevent

the extra code in the additem part are too add the amount of arrows and too make it do that without posting a message. As discribed in the creation kit wiki. So yes, I have already been using the wiki but can't find the right information there too make this work...
User avatar
Heather Kush
 
Posts: 3456
Joined: Tue Jun 05, 2007 10:05 pm

Post » Mon Jun 18, 2012 4:10 am

Perhaps...
Scriptname SummonerBow extends ObjectReferenceAmmo Property DaedricArrow Auto;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Event OnEquipped(Actor akActor)	If akActor == Game.GetPlayer()		RegisterForUpdate(0.1)	EndIfEndEvent;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Event OnUpdate()	If Game.GetPlayer().GetItemCount(DaedricArrow) < 2		If akActor.GetAV("magicka") >= 20			akActor.AddItem(DaedricArrow, 1, true)			akActor.DamageActorValue("magicka", 20)			;Shouldn't the arrows already be equipped?			;akActor.EquipItem(DaedricArrow, false, true)		EndIf	EndIfEndEvent;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Event OnUnequipped(Actor akActor)	If akActor == Game.GetPlayer()		UnregisterForUpdate()	EndIfEndEvent;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Event OnUnEquipped(Actor akActor)	If akActor == Game.GetPlayer()		;Game.GetPlayer().RemoveItem(Summonedarrow, 2, true)	EndIfEndEvent
User avatar
Racheal Robertson
 
Posts: 3370
Joined: Thu Aug 16, 2007 6:03 pm

Post » Mon Jun 18, 2012 10:45 am

Gave it a try, but no luck. Still doesn't want too add the arrows too the inventory.

It also doesn't recognize UnregisterForUpdate as a function/command. and it doesn't like using akactor being used in place of game.getplayer()

Still don't have enough of an understanding of the papyrus language too know why just yet.

But I think you may be on too something with pulling the actual function part of the script out of the OnEquipped() event.
User avatar
Michelle davies
 
Posts: 3509
Joined: Wed Sep 27, 2006 3:59 am

Post » Mon Jun 18, 2012 12:08 pm

Ah... I'd forgotten the '()' for http://www.creationkit.com/UnregisterForUpdate_-_Form. Haven't tried anything like this yet, but hopefully you manage to get it working :)

Is the Daedric Arrow Property pointed at the arrow form?
User avatar
Ilona Neumann
 
Posts: 3308
Joined: Sat Aug 19, 2006 3:30 am

Post » Mon Jun 18, 2012 11:47 am

and it doesn't like using akactor being used in place of game.getplayer()
yeah, I think akactor is a local variable so it doesn't exist outside of the function where it is declared. You could create an actor property and assign that to the player, though, and then use that property anywhere you would use game.getplayer() in your script. This would give the script a little bit of polymorphism, just in case you want to use it for a different actor at some point.
User avatar
Jack Walker
 
Posts: 3457
Joined: Wed Jun 06, 2007 6:25 pm

Post » Mon Jun 18, 2012 1:05 am

Well, I got the script working pretty well now. Took a bit too figure it out but thats how it works I guess.

This is what I ended up with:

Scriptname Summonerbow extends ObjectReferenceAmmo property Summonedarrow AutoEvent OnEquipped(Actor akActor)int arrowtime = 2While arrowtime == 2  Utility.Wait(0.1)  if (Game.GetPlayer().GetItemCount(Summonedarrow) <= 2)   If (Game.GetPlayer().GetAV("magicka") >= 20)    Game.GetPlayer().AddItem(Summonedarrow, 1, true)    Game.GetPlayer().DamageActorValue("magicka", 20)    Game.GetPlayer().EquipItem(Summonedarrow, false, true)   endif  endifendwhileendeventEvent OnUnEquipped(Actor akActor)int arrowtime = 1Game.GetPlayer().removeitem(Summonedarrow, 2, true)endevent
User avatar
Bethany Watkin
 
Posts: 3445
Joined: Sun Jul 23, 2006 4:13 pm


Return to V - Skyrim