Jump to content

Recommended Posts

Posted

I'm having a rather strange problem with the RemoveItemNS function. Although it works fine for me, I recently received feedback on 1 of my mods implying it doesn't always remove items. See below the part where it's going wrong:

 

set canteens to 0
set i to player.GetItemCount BPNCanteenEmpty
if i > 0
player.RemoveItemNS BPNCanteenEmpty i
set canteens to canteens + i
endif
player.AddItemNS drinkfull canteens

 

BPNCanteenEmpty is a standard misc object. Is there something that could block the RemoveItemNS function in any way? Thanks in advance.

Posted (edited)
The remove logic looks OK, but I'd move the AddItem line inside the if block. I don't know what happens when the quantity is zero, but one possibility is that the script is marked unusable, so it doesn't get run the next time. Edited by ghastley
Posted (edited)

Thanks for the suggestion. The actual code is a bit longer (see below), also checking other items, but left it like this for simplicity sake. The only issue is that the RemoveItemNS function doesn't remove the item under some unknown condition, but still adds a new item. So, resulting in 2 items in the player characters inventory rather than just the 1. The AddItemNS part works fine (also with 0).

 

It seems there's a method to lock down an item in the player character's inventory resulting in RemoveItemNS doing nothing. Can't think of anything which might be able to do this though.

 

Scn BPNRefillCanteenFunctionScript

ref drinkfull
ref drinksome
ref drinklittle
ref mydrink
short emptymessage

short canteens
short i

Begin Function { drinkfull drinksome drinklittle mydrink emptymessage }

if BPN.ini_canteen_blood == 0
if mydrink == BPNBlood
return
endif
endif

set canteens to 0
set i to player.GetItemCount drinksome
if i > 0
player.RemoveItemNS drinksome i
set canteens to canteens + i
endif
set i to player.GetItemCount drinklittle
if i > 0
player.RemoveItemNS drinklittle i
set canteens to canteens + i
endif
set i to player.GetItemCount BPNCanteenEmpty
if i > 0
player.RemoveItemNS BPNCanteenEmpty i
set canteens to canteens + i
endif

if canteens == 0
if emptymessage
	Call BPNLocalizeMessagesFunctionScript 10 playerref 0
	messageex "%z" BPN.mymessage
endif
else
PlaySound NPCHumanDrowning
if canteens == 1
	Call BPNLocalizeMessagesFunctionScript 11 mydrink 0
	messageex "%z" BPN.mymessage
else
	Call BPNLocalizeMessagesFunctionScript 12 mydrink 0
	messageex "%z" BPN.mymessage
endif
endif

player.AddItemNS drinkfull canteens
SetFunctionValue canteens

End

Edited by Maskar
Posted

Is it possible that your function is called IMMEDIATELY after the item has been added to the inventory? And how was it added (by player or by script)?

 

There is a known issue for all remove commands if you call remove too quickly. See RemoveItem

Posted
No, the player character had the item in his/her inventory for some time and the call to the function above constantly resulted in new canteens being added without the empty one being removed. GetItemCount returns 1 while RemoveItemNS constantly failed/did nothing. It does seem to be a rare issue though, as I haven't received any further reports concerning this.
Posted
Can it be equipped? If EquipItem xxx 1 is used, then it can't be implicitly unequipped by removing it until you've done the UnequipItem xxx 1 to force it off.
Posted (edited)
No, it's just a default misc item. It does nothing other than being able to be refilled with the above script. I'm guessing it's something similar to it though, but being locked somehow else. Edited by Maskar
Posted

Could it be that RemoveItemNS's first parameter is a base ref and not an objectid? Assuming drinksome is not a base object, you'd have to pass drinksome.GetBaseObject to RemoveItemNS instead.

 

Just a wild guess, could be wrong...

Posted

No they're for sure all base objects. I only use calls like:

 

Call BPNRefillCanteenFunctionScript BPNCanteenFullWater BPNCanteenSomeWater BPNCanteenLittleWater BPNWater 0
Call BPNRefillCanteenFunctionScript BPNCanteenFullBeer BPNCanteenSomeBeer BPNCanteenLittleBeer BPNBeer 1
; etc.

  • Recently Browsing   0 members

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