Jump to content

Infinite arrows script not working?


themitchguy

Recommended Posts

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 ArrowRelease
Actor Property PlayerRef Auto
Ammo Property BowSwordArrow00 Auto
Function AddArrow(Actor Target, Int Qty)
Target.AddItem(BowSwordArrow00, Qty)
EndFunction
Event OnAnimationEvent(ObjectReference akSource, string asEventName)
PlayerRef = akSource as actor
if (asEventName == BowAnimation)
if PlayerRef.GetItemCount(BowSwordArrow00) <= 5
Debug.Notification("5 Sword Arrows left")
AddArrow(PlayerRef, 5)
PlayerRef.equipitem(BowSwordArrow00)
Debug.Notification("5 Sword Arrows equipped")
endif
endif
endEvent
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

  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 by themitchguy
Link to comment
Share on other sites

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.
Or
Creating 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
EndEvent

Example 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 by sLoPpYdOtBiGhOlE
Link to comment
Share on other sites

  • Recently Browsing   0 members

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