Maskar Posted November 1, 2011 Share Posted November 1, 2011 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. Link to comment Share on other sites More sharing options...
ghastley Posted November 1, 2011 Share Posted November 1, 2011 (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 November 1, 2011 by ghastley Link to comment Share on other sites More sharing options...
Maskar Posted November 1, 2011 Author Share Posted November 1, 2011 (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 November 1, 2011 by Maskar Link to comment Share on other sites More sharing options...
fore Posted November 7, 2011 Share Posted November 7, 2011 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 Link to comment Share on other sites More sharing options...
Maskar Posted November 7, 2011 Author Share Posted November 7, 2011 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. Link to comment Share on other sites More sharing options...
ghastley Posted November 7, 2011 Share Posted November 7, 2011 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. Link to comment Share on other sites More sharing options...
Maskar Posted November 7, 2011 Author Share Posted November 7, 2011 (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 November 7, 2011 by Maskar Link to comment Share on other sites More sharing options...
Astymma Posted November 8, 2011 Share Posted November 8, 2011 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... Link to comment Share on other sites More sharing options...
Maskar Posted November 8, 2011 Author Share Posted November 8, 2011 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. Link to comment Share on other sites More sharing options...
Recommended Posts