Jump to content

OnPlayerBowShot, Not activating at all


Recommended Posts

I'm trying to make a character based on the Forgotten Realms series, and I wanted to make the enchanted quiver that accompanied Taulmaril. I was looking to make a simple script that kept my "quiver," really just my arrow count, at 20, but I'm very new to scripting.

 

All the research I've done is gotten me to the point of making a dummy quest, marking the player as an alias, and tagging the script on through that. My ultimate hope is to connect it to an enchantment, so I'm able to effectively turn it off, but I don't really have any idea how I'd go about doing that.

 

My script so far:

 

Scriptname ArrowBuild extends referencealias
Event OnPlayerBowShot(Weapon akWeapon, Ammo akAmmo, float afPower, bool abSunGazing)
debug.Trace("I Shot My Bow")
If(Game.GetPlayer().GetItemCount(akAmmo) <= 20)
Game.GetPlayer().Additem(akAmmo, 20 - Game.GetPlayer().GetItemCount(akAmmo), true)
EndIf
EndEvent
Upon running the game, my quest is running, and the player is called as an alias, at 00000014, but nothing gets activated when I fire a bow, and the debug never ticks off.
Plz help :confused: :confused:
Link to comment
Share on other sites

I have not used that event before thus I do not know if it works or does not work as advertised. However, for original Skyrim a few years back someone was wanting to do something very similar. They wanted the player to maintain a fixed amount of a specific ammo for a specific weapon. I believe it too was inspired by the bow wielded by Cattie-Brie in the Drizzt stories. At any rate, I did come up with something that worked. There may be better solutions out there these days, but its worth a look.

https://forums.nexusmods.com/index.php?/topic/979583-revolutionary-ammo-mod-scripting-and-mesh-creation/&do=findComment&comment=7930535

Link to comment
Share on other sites

Reading through the code you provided in that mod, I'm hoping you can provide me some clarification on a few bits, as I am pretty new to this :happy: :happy:

 

In the script you posted, you defined an actor property for the player, is that necessary? Does it work better than just using GetPlayer?

Is there a way to attach this script to something like a magic effect, or should I just make a limiter and run that through the magic effect?

 

Here's my newest try, I've defined the properties as the bow and arrows I want to use, though I'd also like to know if it's possible to keep it generic to work with any bow

Scriptname ArrowBuild extends referencealias 
 
Weapon Property Taulmaril Auto
Ammo Property QuikArrow Auto
Actor Property PlayerRef Auto
Int arrowCount
Int usedCount
 
Event OnPlayerBowShot(Weapon akWeapon, Ammo akAmmo, float afPower, bool abSunGazing)
If(PlayerRef.IsEquipped(Taulmaril))
debug.Trace("I Shot My Bow")
arrowCount = (PlayerRef.GetItemCount(QuikArrow))
usedCount = (20 - arrowCount)
If(arrowCount <= 20)
PlayerRef.Additem(QuikArrow, usedCount, true)
EndIf
EndIf
EndEvent

Edit -

 

Nothing happens, still. Player is still called as quest alias, though nothing is called. I'm trying to use a bow and an arrow style from different mods. Should I just copy those styles over into my mod, as seperate entries from those mods?

Edited by geogiepoegie
Link to comment
Share on other sites

Backtrack a bit here. You're trying to adapt what I had working for original Skyrim into your mod. The issue is that neither one of us knows if OnPlayerBowShot works. Try this: Use the script code I have in that other thread exactly as it is. Put it on a script assigned to the player alias. Then see if that works. If it does not, we need to go through some other troubleshooting steps that are not associated with the script at all. Things like: Is the quest running? Is the alias being properly filled? If either of those are no, that has to be resolved first before making sure the script works.

 

**********************************

You could possibly use a magic effect, I suppose. I think it might have to be more like an ability that lasts for a long duration rather than associated with a spell. Might even be possible to use on a perk and have a specific weapon apply the perk, but I'm not sure how to set all that up.

 

**********************************

Regarding usage of actor property / variable vs Game.GetPlayer():

Game.GetPlayer() has to pull the player information every time it is called. This wastes processing time the more it is done within a script.

A property / variable calls the data once and stores it for use. However, a property itself can take up unnecessary memory and it makes things persistent. The player is already persistent so that point is partially moot. But memory usage could be a concern since each property has to be stored even if multiple properties across multiple mods are storing the same data.

The best of both worlds would be to have a local non-property variable i.e. Actor PlayerRef and assign it the player data within an initiation block or other early running event. i.e.

Actor PlayerRef
Event OnInit()
  PlayerRef = Game.GetPlayer()
EndEvent

Because the local variable is defined in the empty state it can be used throughout the script. Because it is a local variable the data is flushed when the object running the script ceases to exist i.e. a quest is stopped, a magic effect is ended, etc.

 

All that aside, if you store the player data in a property or local variable, you'll have less typing to do in your code. That is if you plan your code that way to begin with...

Link to comment
Share on other sites

To IsharaMeradin:

 

Your script does work, I set it to a dwarven bow and arrows to test, and it equipped and unequipped the arrows as deemed by your description of it. So with that knowledge, I tried calling the bow and arrow from the alternate mods, and, lo-and-behold, no dice. It seems I'll have to move those into their own mod with this script, unless I can somehow make it generic to all bows.

 

Edit-

 

Tried my script with a dwarven bow and arrow to test, works fine, so it looks like pointing to those other mods was the problem.

 

Still no idea how to make this run or not run when I have a certain enchant on. I've seen it done with other mods, so I know it is possible, just don't really have a clue how to do it myself

Edited by geogiepoegie
Link to comment
Share on other sites

If you want to work with specific mod bow & ammo, you can use GetFormFromFile to pass the data from the mod to the necessary variables in your script. Otherwise, you can make the other mod a parent master, link the records directly into the properties and then require all users to use that mod as well else the game will crash. Alternatively, as you've mentioned, recreate the items in a new mod with the script.

Link to comment
Share on other sites

You can use If PlayerRef.GetEquippedItemType(0) == 7 to determine if the player is wielding a bow. Crossbows have a value of 12.

 

Unfortunately, there is no way to get the equipped ammo directly. There is a convoluted way which requires running the script on the player using whichever script types can listen for the OnItemRemoved event. Unfortunately, without a formlist to use with AddInventoryEventFilter, this event will attempt to process EVERY TIME the player removes an item. This can lead to stack dumps if a lot of mods add code to this event (which many do).

 

Example which may work (not tested)

 

 

Actor PlayerRef
Int Property AmmoLimit Auto

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
	If akBaseItem as Ammo
		PlayerRef = Game.GetPlayer()
		If PlayerRef.IsEquipped(akBaseItem) && PlayerRef.GetEquippedItemType(0) == 7 ;is ammo equipped and is a bow equipped
			Int num = PlayerRef.GetItemCount(akBaseItem)
			While (num < AmmoLimit)
				PlayerRef.AddItem(akBaseItem,1,true)
				num += 1
			EndWhile
		EndIf
	EndIf
EndEvent

 

 

Link to comment
Share on other sites

Can you explain a little more in depth why AddInventoryEventFilter isn't applicable as a limiter?

 

Edit-

 

Your code works, even with the modded bow and ammo, so calling the bow like that works. Would you advise going into the arrow mod, adding the ammo to the ammo form list, and using that with the event filter?

Edited by geogiepoegie
Link to comment
Share on other sites

  • Recently Browsing   0 members

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