Difference between revisions of "Generic Unequip"
imported>Wrye (New page: Category: Useful Code ===Problem: Prevent PC from equipping a generic type of item.=== E.g. prevent male pc from equipping female clothes or vice versa. Or prevent pc from equipping f...) |
imported>Iceyeyes |
||
Line 4: | Line 4: | ||
===Solution Ideas=== | ===Solution Ideas=== | ||
* Use '''unequipMe'''. | * Use '''[[unequipMe]]'''. This is an Oblivion Script Extender Function. (The function was added to the OBSE v0019.) | ||
* Use [[getBaseObject]]. But that requires OBSE. | * Use [[getBaseObject]]. But that requires OBSE. | ||
* "[[RemoveMe]] player" comes close to working, but suffers from an infinite loop. | * "[[RemoveMe]] player" comes close to working, but suffers from an infinite loop. |
Latest revision as of 09:19, 24 August 2010
Problem: Prevent PC from equipping a generic type of item.[edit | edit source]
E.g. prevent male pc from equipping female clothes or vice versa. Or prevent pc from equipping faction specific armor.
Solution Ideas[edit | edit source]
- Use unequipMe. This is an Oblivion Script Extender Function. (The function was added to the OBSE v0019.)
- Use getBaseObject. But that requires OBSE.
- "RemoveMe player" comes close to working, but suffers from an infinite loop.
- DropMe seems like it should work, but in fact only partially removes the item. I.e. the item disapears from inventory, but ist still present both visually and statistically on the player (i.e. it's still visible and the player still gets armor, etc. stats from the item).
Solution: RemoveMe[edit | edit source]
Fortunately, the infinite loop problem with removeMe can be circumvented, like so:
short removing begin onEquip player if player.getIsSex male return elseif removing set removing to 0 else message "That's made for a man." set removing to 1 removeMe player endif end
What happens here is that the onEquip block will continue to run until it is exited normally. Ordinarily the removeMe (which causes an immediate return) prevents a normal exit, but that has been sidestepped here through the "removing" flag. I.e. the onEquip block will run twice here -- first time ending with "removeMe", second time ending by clearing the "removing" flag.
A minor problem with this approach is that the player doll does not update to reflect the removal -- however, armor/magic effect stats are correct and the item is correctly un-highlighted in inventory. Also the player doll will be corrected as soon as the player equips/unequips another item.
Solution: RemoveMe or OBSE[edit | edit source]
An improvement on the approach above would be to use OBSE if it's present, but otherwise use the removeMe approach. This is probably too much hassle in most cases (since determining that obse is not present requires recovering from a failed/returned function call). However, if Cobl is being used, then one can simply test the cobSigSe.version variable.
scn cobGenUnequipFemaleOS ;--Generic script that will unequip if item is player is female. short removing ref rItem begin onEquip player ;--Removing test if player.getIsSex male return elseif removing set removing to 0 elseif cobSigSe.version >= 12 ;--See of OBSE version >= 0.12. set rItem to getBaseObject message "That's made for a man." ;Avoid "XXX unequipped" message spam. message "That's made for a man." player.unequipItem rItem else message "That's made for a man." set removing to 1 removeMe player endif end
Solution: Non Generic Removal[edit | edit source]
Of course, if dealing with a specific item, or a small set of items, then a non-generic removal script can be used. E.g. for the Amulet of Kings (slightly optimized):
scn AmuletofKingsSCRIPT begin OnEquip player MessageBox "The Amulet of Kings slips off as you try to fasten it around your neck." player.unequipitem AmuletofKings 1 end
Or for a small set of known items (from Oscuro's Oblivion Overhaul):
scriptName AmazonArmorQueen2 ; Created: Jorge "Oscuro" Salgado Begin OnEquip Player if Player.GetIsSex Male if GetIsID 00GRARG01COOO Player.UnequipItem 00GRARG01COOO 1 elseif GetIsID 00GRARG01GOOO Player.UnequipItem 00GRARG01GOOO 1 elseif GetIsID 00GRARG02GOOO Player.UnequipItem 00GRARG02GOOO 1 else return endif MessageBox "This magnificent armor suits only females." endif End