OnEquip for all items on the player?

Post » Wed Oct 06, 2010 4:37 pm

I'm trying to let my script do stuff when an item (any item) is equipped on the player. OnEquip looks like what I'm after, but I'm not sure if it has to be used in a script attached to an object, which is not what I want.

I'm not new to programming or modding but pretty new to Oblivion scripting. Any help would be very appreciated.
User avatar
Anthony Santillan
 
Posts: 3461
Joined: Sun Jul 01, 2007 6:42 am

Post » Wed Oct 06, 2010 5:46 pm

OnEquip only works on the item it is attached to, but maybe you could use OBSE to check, somehow?

My immediate thought would be run a check in the first frame of MenuMode, and record all of the PCs equipped items, then keep checking throughout and if one of the first items does not match, or equal "0" then you (should) have caught the change.

GetEquippedObject may be the Command to use.
http://cs.elderscrolls.com/constwiki/index.php/GetEquippedObject
User avatar
Ruben Bernal
 
Posts: 3364
Joined: Sun Nov 18, 2007 5:58 pm

Post » Wed Oct 06, 2010 7:41 am

I may have a MUCH simpler way to do it than that.

GetEquippedItems- returns an array containing all items currently equipped by the calling actor
(items:Array) reference.GetEquippedItems


So I would guess

if player.GetEquippedItems > 0
;do stuff
endif


But I am not well skilled in the new "array" commands so I could be wrong.
User avatar
Jah Allen
 
Posts: 3444
Joined: Wed Jan 24, 2007 2:09 am

Post » Wed Oct 06, 2010 3:01 pm

The method you'll probably have to use if you want a script to run when the player equips anything, is to work from the fact that equipping the item is done from the inventory. Use a menumode block (in a quest script, because you can't attach an object script to the player) to determine when the user selects an item to equip from the inventory, and do the work there. Inventory is 1002, and you'll need to determine what action the user is taking and which item is selected, so it gets a bit complicated. If you also need to process when an item is unequipped, you'll have to track the current slots and see if anything is displaced by equipping another item in the same slot, as well as the action of selecting an equipped item to return it to inventory.

It may be possible to catch when the inventory dialog is closed and check the equipment slots at that point, perhaps someone else has done that and can advise?
User avatar
Nina Mccormick
 
Posts: 3507
Joined: Mon Sep 18, 2006 5:38 pm

Post » Wed Oct 06, 2010 10:05 am

Can you compare two arrays?

Get a "GetEquippedItems" array and store it, and then run a comparison every five seconds with the current array result. If the array is different, you count the number of items (lower indicates the player unequipped something rather than equipped it) and act according to that result.
User avatar
Jason White
 
Posts: 3531
Joined: Fri Jul 27, 2007 12:54 pm

Post » Wed Oct 06, 2010 9:32 pm

I may have a MUCH simpler way to do it than that.

GetEquippedItems- returns an array containing all items currently equipped by the calling actor
(items:Array) reference.GetEquippedItems


So I would guess

if player.GetEquippedItems > 0
;do stuff
endif


But I am not well skilled in the new "array" commands so I could be wrong.

That seems to be what I need, thanks :)

Can you compare two arrays?

Get a "GetEquippedItems" array and store it, and then run a comparison every five seconds with the current array result. If the array is different, you count the number of items (lower indicates the player unequipped something rather than equipped it) and act according to that result.

I was thinking this as well, but I can't really find in OBSE's docs if it's possible to compare arrays... Would be perfect though.


EDIT: I just tried comparing arrays with == and eval(), didn't seem to work :/
User avatar
Brittany Abner
 
Posts: 3401
Joined: Wed Oct 24, 2007 10:48 pm


Return to IV - Oblivion