Talk:RemoveItem

From the Oblivion ConstructionSet Wiki
Revision as of 16:07, 23 January 2008 by imported>Haama (Refresh and Lag notes)
Jump to navigation Jump to search

Why does RemoveItem not have a TargetContainerID like RemoveAllItems? This could be useful for toggling the ownership flag (where the target is the same as the caller).

-- Grey Where's even the point in having an ownership override tag? Does that mean all objects of the id will be cleared from "stolen flag" or the first 50 items of that id with "stolen flag" will be removed, or what? edit: RemoveItem won't even compile with override flag, remove note?

How can an object have an inventory? I'd be pretty scared if a weapon had it's own items. This must surely be referring to the object's CONTAINERS inventory, right? --MaXiMiUS 20:49, 11 April 2006 (EDT)

-- Grey Nope, you get that wrong. The "calling object" is the container, since the function is run/called on the container, not on the item. One could possibly change ObjectID into ItemID, but for consistency reasons this should NOT be done, since ObjectID is used widely in the wiki. Note: I also removed the note on the retainownership flag, since it's clearly wrong, as of now.

Refresh and Lag notes

The notes come from my experience with the Keychain mod (by the way, credit for the refresh code should go to mmmpld - the code was in there long before I started working on it). I have a section of code that, when the player equips the Keychain, will either remove all the keys from a remote container back to the player (Unhook keys), or move all the keys from the player to the remote container.

;Take keys on/off the keychain when player equips it (Hook keys).
begin onEquip player
	if Mode
		;Unhook keys
		set Mode to 0
		con_ToggleMenus
		P1DkeyContainer02.RemoveAllItems player, 1 ;Still causes lag in inventory menu, but AddItem does no better
		con_ToggleMenus
		;Equipping and unequipping an item will force the inventory menu to update, showing the keys
		if (MenuMode 1002)
			message "Unhooked keys from Keychain"
			message "Unhooked keys from Keychain"
			player.EquipItem P1DKeychain
			player.UnEquipItem P1DKeychain
		else
			message "Unhooked keys from Keychain"
		endif
		
	else ;if (Mode == 0)
		;Hook keys
		set Mode to 1
		set NoKeysRemoved to 1
		con_ToggleMenus
		message "Re-hooked keys to Keychain"
		message "Re-hooked keys to Keychain"
		set InvPos to 0
		Label 2
		set pItem to (player.GetInventoryObject InvPos)
		if pItem
			if (IsKey pItem)
				if (pItem != P1DKeychain) ;&& ((IsQuestItem pItem) == 0)
					set KeyCount to (player.GetItemCount pItem)
					P1DkeyContainer02.AddItem pItem KeyCount
					player.RemoveItem pItem KeyCount
					Label 3
					set KeyCount to (player.GetItemCount pItem)
					if KeyCount
						player.RemoveItem pItem KeyCount
						Goto 3
					endif
					if NoKeysRemoved
						set NoKeysRemoved to 0
					endif
				else
					set InvPos to (InvPos + 1)
				endif
			else
				set InvPos to (InvPos + 1)
			endif
			Goto 2
		endif
		con_ToggleMenus
		;Refresh inventory menu if necessary
		if (MenuMode 1002)
			if (NoKeysRemoved == 0)
				player.EquipItem P1DKeychain
				player.UnEquipItem P1DKeychain
			endif
		endif
	endif
end

If you comment out the Refresh inventory menu section and try it out in-game (tested with all the non-scripted keys from Oblivion and SI), when the keys are hooked all of the key icons will remain displayed, as if the player still had them. However, if you click on anything in the inventory, close and re-open the inventory, or move to a different tab and back the keys will correctly no longer show. Add back the Refresh inventory menu section and the keys will correctly disappear without the need to close the menu, etc.

If you comment out the con_ToggleMenus, there will be a noticeable pause/delay in the game (the player avatar stops bouncing). Add them back and the lag disappears.

Finally, if you extend the con_ToggleMenus section to include the Refresh inventory menu section, it will no longer refresh the menu.--Haama 16:07, 23 January 2008 (EST)