CrystalShapeshifter Posted July 31, 2017 Share Posted July 31, 2017 Hello, I'm new to making mods and a complete noob at scripting and coding. I've been trying to make a script that, when a player equips a weapon, it is unequipped, a message box appears (saying something along the lines of "It slips through your hands), and the item is added back to their inventory. I know how to do it for a specific item by looking at the Amulet of Kings script, but as I want to add this to many weapons, I want a generic unequip script that I can add to many weapons. I have no clue how to go about this, however. I've looked up a few basic scripting guides and looked at the Construction Kit Wiki and OBSE Documentation, but they don't give examples of what I want to do (the Wiki gives an example for a generic removal if a player is male or female, but that's it; I used this for a while to test the balance of the mod but it stopped working one day). There's also the problem of an infinite loop of the message box if not done right; the wiki suggests using unequipme or getbaseobject functions, but does not give an example of how to use them. I attempt to try and figure it out on my own, but I'm not using them right as the Construction Kit Extender won't allow me to compile the script. If anyone can offer any help on this, whether it is an example or a good place to find a scripting guide (especially with OBSE functions, it's hard to find one), it would be much appreciated. I've been stuck on this for quite a while, quitting for a few months before coming back to it today. Thanks. Link to comment Share on other sites More sharing options...
Wolfhound2 Posted August 2, 2017 Share Posted August 2, 2017 HiI'm not sure it can be done with a generic script that you can just attach to any equippable object, without hardcoding the object, like the Amulet Of Kings script does. UnEquipMe needs a reference to the object you want to unequip.So it will only work within a loop while scanning through Inventory items (see OBSE docs 'Ref-walking functions' and 'Inventory References')That's probably why it wouldn't compile for you. I've been playing around in the CS trying to see how this could be done.The fundamental snag is that when the item is in your inventory, it does NOT have a reference, so you can't pick up 'this thing's reference' in order to be able to do anything with it, like unequipping or putting its name in a message and so on, with no hard-coding. Even if you used an inventory-walking loop, you would still have the problem of seeing if 'this thing' matches the current temporary inventory ref, because you're back to the first problem - can't get 'this thing's' reference. T'is a bit of a conundrum, so it is. :geek: I'll have a bit more of a poke around the CS, and get back to you if I find a way to do it. Feel free to throw questions at me, I'm working on a mod overhaul at the moment, so I'm fairly active here for now. Link to comment Share on other sites More sharing options...
glowplug Posted August 4, 2017 Share Posted August 4, 2017 If I understand the objective, you need...One script to unequip all of a certain type of weapons.The unequip has to happen during the OnEquip event....a point to note here is that Weapon does not have the Playable tickbox in the Construction Set. As a new comer to coding it is important to know the difference between a Base Object and a Reference...The Base is what we see in the Construction Set (CS) Object Window - just numbers and characters in the esp/esm database.The Reference is what we see in game or CS Render Window. The sword we hit the enemy with and can Drop on the ground (usually an actual NIF)....in this case we need to work on the Base Object.Say we pick up a sword off the ground. That 'instance' goes out of scope and our Inventory just gets the EditorID (Base Object index). When we open our Inventory the EditorID is used to load things such as the Icon and Name for listing.In short, the OnEquip is running on a Base Object. This has certain issues that are best handled using OBSE commands...Again, as Inventory item, OnEquip is raised on the Base Object - ApostleDagger or ElveShortSword for example (not a run time Reference).A MessageBox 'is' a Menu item, just like the Inventory Menu. Doing a MessageBox at the same time is not only messy but I have had it lock up and crash the game. A message would be more appropriate.Unequipping an item, from code, normally produces a message of it's own.If it's Non Player then I'm assuming it has to be NPC only - the message must not happen when an NPC equips one of these weapons.These can be solved with the following...GetBaseObject (OBSE command) - defaults to the Script's base object.UnEquipItemNS (OBSE command) - OBSE NS functions mean No Spam - no message or noise so now you can do your own.Use Player for the Optional ActorID (OnEquip [ActorID]).The code... ScriptName GenericNonPlayerWeaponScript ref refBaseObject Begin OnEquip Player Set refBaseObject to GetBaseObject PlayerRef.UnEquipItemNS refBaseObject MessageEX "%n slips through your fingers.", refBaseObject End Note: Player is used for ActorID but PlayerRef used for the 'in game' Reference - we can use Player as reference and Oblivion will mostly correct it...mostly. Keep this in mind if something does not work sometime. See OBSE Command Documentation for Format Specifiers such as "%n". When I run this script, it just does not 'feel' right. There is no sound or message icon - something a bit more advanced...GetWeaponType (OBSE command) - returns the integer of Weapon Type (see OBSE command documentation).GetTexturePath (OBSE command) - returns the icon filepath but as per Object Edit window (Weapon/.. for weapons) but...SetMessageIcon (OBSE command) - requires "Data/Textures/.." (in this case "Data/Textures/Menus/Icons/..").sv_Insert (OBSE command) - sv_Insert "text", string_var, position - position is zero based as in 1 would insert it between 1st and 2nd characters, 0 (the default) at the beginning. ScriptName GenericNonPlayerWeaponScript int iWeaponType ref refBaseObject string_var strIconPath Begin OnEquip Player Set refBaseObject to GetBaseObject ;__Note base object goes to Right of command - reference would be refReferenceName.CommandName Set iWeaponType to GetWeaponType refBaseObject Set strIconPath to GetTexturePath refBaseObject sv_Insert "Data\Textures\Menus\Icons\", strIconPath, 0 if iWeaponType == 0 PlaySound WPNBlade1HandUnequip elseif iWeaponType == 1 PlaySound WPNBlade2HandUnequip elseif iWeaponType == 2 PlaySound WPNBlunt1HandUnequip elseif iWeaponType == 3 PlaySound WPNBlunt2HandUnequip elseif iWeaponType == 5 PlaySound WPNBowUnequip else PlaySound WPNStaffUnequip endif PlayerRef.UnEquipItemNS refBaseObject SetMessageIcon $strIconPath MessageEX "%n slips through your fingers.", refBaseObject, 5 End ...notice that I did not use 4 for Staff but put it under 'else' (which has to be last).I've seen all sorts of weird stuff over the years. Functions (commands) returning values that they should not.If there's an error in another script then it should at least play WPNStaffUnequip. If no sound plays then it is most likely an error in this script. Sorry if this is a bit long winded but you can at least copy/paste either of the scripts for now. Link to comment Share on other sites More sharing options...
glowplug Posted August 4, 2017 Share Posted August 4, 2017 EDIT: I missed that the inventory gets additional data such as damage but it is still not a Reference in the 'game' sense of the word.On the second MessageEx I added 5 as the last parameter. That tells it to try and display the message for 5 seconds - change that to whatever but I think 10 is the maximum. Link to comment Share on other sites More sharing options...
Wolfhound2 Posted August 4, 2017 Share Posted August 4, 2017 I'm an idiot. :geek: I was desperately trying to find a way to get around grabbing a reference to the weapon in your inventory when you equip it, knowing that it doesn't have a reference.I totally forgot about grabbing the base object instead, using GetBaseObject as per glowplug's code. D'oh! As me ma use to say "there's more than one way to skin a Khajit." Link to comment Share on other sites More sharing options...
Recommended Posts