mjw Posted September 9, 2014 Share Posted September 9, 2014 Hello! I am taking my first steps in Skyrim modding with scripts. I wanted to create a type of item that the player cannot remove once it is put on. Unless of course certain conditions are met, but those shall be a concern for later. Let's first just make the item stick to the player. Like the bomb collars in Fallout New Vegas (Dead Money DLC), if you know it. In theory, it should be fairly simple: We just put the item right back on if the player removes it in the inventory. Like this: Event OnUnequipped(Actor akActor) ItemCursedMsg.Show() akActor.EquipItem(self) EndEvent But unfortunately, it does not work. I can remove the item in the inventory. The message is shown but the item is not re-equipped. I assumed that the 'self' was the correct reference. After all, the script is attached to that object and I needed a reference. After frantically searching the CK wiki and coming up empty, I finally decided to try 'self' and it compiled. It just did not work. So how else do I get a reference to the item that was just unequipped? I read about a method where you use a quest to hold a reference to a specific item. But I don't think it's what I want - I don't want one specific instance to get re-equipped. I want all instances to be unremovable. So that they can be spawned randomly, have individual states and still be cursed (or not). Or is 'self' correct and I'm doing something else wrong? Any hints? Link to comment Share on other sites More sharing options...
FireFlickerFlak Posted September 9, 2014 Share Posted September 9, 2014 (edited) I have not scripted items much, but if you add an ability to the player that monitors when the player equips/unequips items, that should be able to requip the items you want to prevent them from unequipping. There might be a simpler way to do on the weapon itself, but I usually put my scripts on activemagiceffects. Edit: Create a formlist with all the forms of sticky items. Make a magic effect that monitors unequip events, sets a property to the object that was unequipped, checks the base object of the unequipped item to see if it is in your formalist, then equips the item if it is found in the formlist. Add the magic effect to a hidden ability spell. Add the spell to the player or whatever is not able to unequip the item. Maybe a lot more complicated than just adding the script to the items, but that is how I would do it. Edited September 9, 2014 by FireFlickerFlak Link to comment Share on other sites More sharing options...
mjw Posted September 9, 2014 Author Share Posted September 9, 2014 Make a magic effect that monitors unequip events Probably a stupid question but how would I do that? The OnUnequipped event belongs to the item. I looked at the Event section in the wiki but I cannot find an event attached to the player or to a magic effect that fires when items are unequipped. Or should I just use OnUpdateGameTime to passively keep polling the player? I would need a high frequency for that (it would not help the atmosphere if the item got re-equipped 5 minutes later) and that would probably cause a lot of load on the CPU. Plus the wiki warns about crashes when the interval is too low.And I don't see any function in the Actor class that would get me a reference to equipped item. My current "solution" btw is to use a property in the script attached to each form pointing to the form itself. However, that probably only equips one of any number of items from that base form. No chance to define which one. Not sure if this can become a problem later. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 9, 2014 Share Posted September 9, 2014 If you script an item to be equipped you can tell the game to not allow the player to remove it. SomeActor.EquipItem(CurrentObject,true,false) In order to allow the player to manually equip an item and then cause it to become non-removable you need a script on a player alias within a start game enabled quest. That script could then do something like: Armor Property YourArmorItem Auto {Fill this with the ARMOR object you wish to remain equipped} Weapon Property YourWeaponItem Auto {Fill this with the WEAPON object you wish to remain equipped} Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) If akBaseObject as Armor == YourArmorItem MakeImpossibleToRemove(akBaseObject) ElseIf akBaseObject as Weapon == YourWeaponItem MakeImpossibleToRemove(akBaseObject) EndIf EndEvent Function MakeImpossibleToRemove(Form CurrentObject) Self.GetActorReference().UnequipItem(CurrentObject,false,false) Utility.Wait(0.1) Self.GetActorReference().EquipItem(CurrentObject,true,false) EndFunction This would most likely show a quick flash as the item is equipped, unequipped then re-equipped. As far as conditions to allow removal of the item, an update loop (series of single update checks) can be established to unequip via script whenever the conditions are met. However, this would not provide each item with its own state of "cursed" or not. It would cause every instance of the item to be "cursed" at all times. There would be no "un-cursed" state as that would only be the brief moment where conditions are met for the currently worn instance to be removed. It may be possible to create an empty formlist which would be used to hold the instance id's (not base id) of the object in question as it becomes "un-cursed". A quick check to ensure that the player equipped item that matches the "cursed" item is not specifically within the formlist would allow previously "un-cursed" items to be unequipped by the player as they desire. Link to comment Share on other sites More sharing options...
mjw Posted September 9, 2014 Author Share Posted September 9, 2014 (edited) I see. That sounds interesting. If I understand it correctly, on the plus side, we would actually fix that very instance of the item to the player. The down side would be that I cannot give a customised message to the player (the CursedItemMsg from my first post). He'll just see a generic error message when he tries to remove the item. There is no event for a failed removal attempt, is there? I think I'll try both and then see what fits my idea better. If nothing else, I'll learn something from it. Edited September 9, 2014 by mjw Link to comment Share on other sites More sharing options...
lofgren Posted September 9, 2014 Share Posted September 9, 2014 You could show a message when the item gets forced on the player the first time, something like "The item has latched onto your skin and cannot be removed." Or whatever is appropriate for the item. Link to comment Share on other sites More sharing options...
FireFlickerFlak Posted September 9, 2014 Share Posted September 9, 2014 Make a magic effect that monitors unequip events Probably a stupid question but how would I do that? The OnUnequipped event belongs to the item. I looked at the Event section in the wiki but I cannot find an event attached to the player or to a magic effect that fires when items are unequipped. To answer your question, activemagiceffect scripts inherit the events of their target, so you could use the actor script event OnObjectUnequipped (as well as any Actor, Form or ObjectReference events). Another cool thing about the activemagiceffect scripts is that it is easy to dynamically spread and remove them because you can just add the magic effect to something and then remove the magic effect with little risk of funny business. Link to comment Share on other sites More sharing options...
Recommended Posts