themitchguy Posted April 21, 2015 Share Posted April 21, 2015 Hey I've been trying to write a script to make infinite arrows. Well, I made a bow that shoots daedric greatswords, which all I did was make a dupe of the daedric arrow and changed the projectile mesh. BUT for some reason I can't get the script to work. I tried to make it so when you shoot an arrow, it checks if you have 5 or less arrows, and if so, adds 5 arrows to your inventory. ScriptName BowSwordArrowRegen extends ObjectReference String BowAnimation = "ArrowRelease" ; I saw that the event BowRelease wasn't as effective as ArrowReleaseActor Property PlayerRef AutoAmmo Property BowSwordArrow00 Auto Function AddArrow(Actor Target, Int Qty)Target.AddItem(BowSwordArrow00, Qty)EndFunction Event OnAnimationEvent(ObjectReference akSource, string asEventName)PlayerRef = akSource as actorif (asEventName == BowAnimation)if PlayerRef.GetItemCount(BowSwordArrow00) <= 5Debug.Notification("5 Sword Arrows left")AddArrow(PlayerRef, 5)PlayerRef.equipitem(BowSwordArrow00)Debug.Notification("5 Sword Arrows equipped")endifendifendEvent Compiled, set properties in CK, and then attached this script to the Sword Bow. Any suggestions as to why it's not working? Link to comment Share on other sites More sharing options...
sLoPpYdOtBiGhOlE Posted April 21, 2015 Share Posted April 21, 2015 As a guess (I could be wrong).An equipped bow is the same as having a bow in a container, scripts attached to non persistent objects in containers will fail to fire functions. Link to comment Share on other sites More sharing options...
lofgren Posted April 21, 2015 Share Posted April 21, 2015 Where are you registering for the animation event? Link to comment Share on other sites More sharing options...
themitchguy Posted April 23, 2015 Author Share Posted April 23, 2015 (edited) On 4/21/2015 at 4:24 AM, sLoPpYdOtBiGhOlE said: As a guess (I could be wrong).An equipped bow is the same as having a bow in a container, scripts attached to non persistent objects in containers will fail to fire functions. Then how do people attatch scripts to weapons? Maybe attatch it to a quest and add to check if I have the bow equipped first? On 4/21/2015 at 12:17 PM, lofgren said: Where are you registering for the animation event?Well I was wondering that too.... The CK wiki page on OnAnimationEvent didn't go into detail on how to register for the event. all it said was to put some function before the event so that's what I did. Edited April 23, 2015 by themitchguy Link to comment Share on other sites More sharing options...
themitchguy Posted April 24, 2015 Author Share Posted April 24, 2015 Bump Link to comment Share on other sites More sharing options...
sLoPpYdOtBiGhOlE Posted April 25, 2015 Share Posted April 25, 2015 (edited) From everything I tried for call OnAnimationEvent(ObjectReference akSource, string asEventName) seems to fail if the script is attached to the bow.Even if the Bow is a persistent object.Calling RegisterForAnimationEvent from the script attached to the Bow Sword reports successful, but the OnAnimationEvent never gets called.(Maybe something I'm missing or lacking in understanding.)Creating a Quest, Add an alias for the Bow Sword, Add script to the Alias for the Bow Sword all works fine from what I tested.OrCreating a Quest, Add an alias for the Player, Add script to the Alias for the Player all works fine from what I tested.Either of the quest methods have their pro's and cons, depending on how your implementing the bow into the game.eg:Creating the bow as one time find only option, then Quest with an alias for the bow method would be good.Adding the bow so there can be multiple bows in game world at any time then the Quest with an Alias for the player is better.Here's one doing Creating a Quest, Add an alias for the Player (just a blank quest with a player alias with a the script attached to it).The script I used:ScriptName BowSwordAliasScript Extends ReferenceAlias Ammo Property BowSwordArrow Auto ;Arrow property to fill in CK Weapon Property BowSword Auto ; Bow Property to fill in CK Int Property Qty = 5 Auto ;Amount of arrows that the player will always have, can be left as is without filling in CK Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) If akBaseObject == BowSword RegisterForAnimationEvent((self as ReferenceAlias).GetReference(), "arrowRelease") EndIf EndEvent Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference) If akBaseObject == BowSword UnregisterForAnimationEvent((self as ReferenceAlias).GetReference(), "arrowRelease") EndIf EndEvent Event OnAnimationEvent(ObjectReference akSource, string asEventName) If (asEventName == "arrowRelease") Int iCnt = akSource.GetItemCount(BowSwordArrow) If iCnt < Qty akSource.AddItem(BowSwordArrow, Qty - iCnt) (akSource As Actor).EquipItem(BowSwordArrow) EndIf EndIf EndEventExample BowSword.esp of what I used the script in: I just used a duplicate renamed GlassBow and glass arrows.To find the bow baseid in the console:help "Bow Sword"player.additem xx000d62 1(xx= the plugin load order that help tells you) Edited April 25, 2015 by sLoPpYdOtBiGhOlE Link to comment Share on other sites More sharing options...
Recommended Posts