I've a little function which I am using to enable a group of violent npcs mob and rob other npcs or the player. As each member of the group activates their target, one item in a formlist carried by the poor victim is transferred to the aggressor. I have the function in a quest script which is called by each attacker. The victim's identity is supplied by another quest which brought the victim's identity to the attention of the bandits. Each 'bandit's identity is supplied by their punching package. My problem is that, although the function works smoothly, it leaves many complaints in the log about the impossibility of using getitemcount on a none object.
actor mvsteal = mvthief.GetActorReference()
actor mvic = mvfutcow.getactorreference()
taken = 0
int iIndex = mvarmorformlist.GetSize()
While iIndex
if taken == 1
iIndex = 0
arrows()
EndIf
iIndex -= 1
Form kReference = mvarmorformlist.GetAt(iIndex) As Form ; Note that you must typecast the entry from the formlist using 'As'.
if kreference != None
If mvic.getitemcount(kreference)
mvic.RemoveItem(kreference,1, True)
mvsteal.AddItem(kreference,1)
mvsteal.equipitem(kreference)
debug.Trace("steal Armor")
taken = 1
EndIf
EndIf
EndWhile
mvvstealquest.Reset()
mvvstealquest.Stop()
; debug.Notification("stealing over")
EndFunction
function done()
EndFunction
I've taken this from the wiki. Actually, tried two different techniques found there. In the original, "Form" in the line "Form kReference = mvarmorformlist.GetAt(iIndex) As Form" was replaced by "ObjectReference," but when I do that or other combinations of the two words nothing gets stolen. The other method featured "while CurrentItems <= ListSize && ItemsLeft > 0" worked as well, but generated even more log complaints.