Jump to content

[LE] Quick Questions, Quick Answers


Recommended Posts

Is it ever correct for an ENCH reference to be directly referenced in a cell like in the Morrowloot SE version? SSEEdit lists this as an error. Can't give specifics right now because I just have my phone with me right now. There also seems to be a "default gauntlet" reference in the Master file. So is it possible that the enchantment is then applied to whatever that variable equipment is changed?
Link to comment
Share on other sites

This seems like a great thread for this question. I have zero programming background but I'm trying to learn some scripting so I can make better mods.

 

The good news is I'm starting to get a basic feel for it, and the script I made works as intended! The bad news is the script has fired a few times when it shouldn't have, which in this case is very bad.

 

Here's the basic concept of what I'm trying to do: I'm making a follower with kind of a weird concept where their devastating level of holy power needs to be contained by a worn item. Mechanically an item has to stay equipped in a certain armor slot, and if it's removed there's a non-playable "holy light" item in their inventory which will instantly fill that slot. The new armor emits a bright light, and the player dies! Lesson learned, we hope.

 

All this is working. I made an extremely simple script that kills the player if the npc equips the holy light item:

 

Scriptname _00MSfuntime extends ObjectReference
Event OnEquipped(Actor akActor)
Game.GetPlayer().Kill()
EndEvent

 

 

Couldn't be simpler. Totally works! Here's the issue:

 

Sometimes the player will randomly die on game load, cell load, or when moving unrelated items in or out of the follower's inventory. This doesn't happen constantly, but often enough to be a problem. I suspect that what's happening is that when the NPC's inventory refreshes, they equip the death item for an invisible fraction of a second before the game goes oops, no, this other worn item is better for that slot. But all it takes is that split second for the script to fire and kill the player.

I'd like the script to be able to recognize when this item is actually equipped for real, like adding some sort of condition where it has to be worn for one second or longer. I've tried some stuff for the past couple days but nothing is fixing it.

I'd love to see a script that would do this right. Bonus points if it also triggers a cool explosion effect, like the Dawnbreaker enchantment.

Link to comment
Share on other sites

@nerdofprey
Try this. Not tested for compilation or function.
What it should do is wait the amount of time that you specify in the Creation Kit when filling the property, then if the actor still has the object equipped (assuming it is armor) kill the player. Do keep in mind that the wait will be delayed by menus as well as resting. But if your time frame is short, that shouldn't really matter.


Scriptname _00MSfuntime extends ObjectReference  
 
Float Property TimeToWaitInSeconds Auto
Actor SelfActor
Armor SelfObject
 
Event OnEquipped(Actor akActor)
  SelfActor = akActor
  SelfObject = Self as Armor
  RegisterForSingleUpdate(TimeToWaitInSeconds)
EndEvent
 
Event OnUpdate()
  If SelfActor.IsEquipped(SelfObject)
    Game.GetPlayer().Kill()
  EndIf
EndEvent

 

 

 

However, it is also possible that this won't work as some functions/events do not fire when an object is in an inventory or container. If it doesn't, you can go with the method of simply adding a wait statement before the kill.

 

 

Scriptname _00MSfuntime extends ObjectReference  

Float Property TimeToWaitInSeconds Auto
Actor SelfActor
Armor SelfObject

Event OnEquipped(Actor akActor)
  SelfActor = akActor
  SelfObject = Self as Armor
  Utility.Wait(TimeToWaitInSeconds)
  If SelfActor.IsEquipped(SelfObject)
    Game.GetPlayer().Kill()
  EndIf
EndEvent

If the cast of Self to armor does not work, you can create an armor property that points to the object in question.

Link to comment
Share on other sites

Yeah, those do not compile, it does not like that "self" thing. Unfortunately I get very quickly lost when it comes to setting up and using properties, so more detail on how that option works would be a big help. I will try reading up on it in the mean time; the rest of that info is very useful.

 

For the sake of example scripts, the armor ID is HolyLight, and 1.5 seconds is a good pause. Also, if it helps, the script is on the base armor object, and the armor is placed in the NPC's inventory rather than the default outfit. I definitely don't want this thing firing off when it's in anyone's inventory, only when it's physically worn.

 

 

I noticed a possibly related issue; the armor object was flagged as heavy type armor, a detail I'd overlooked. I had set the armor rating and the priority super low to help other items override it. Setting armor type to "none" seems like it might reduce instances of actors equipping it at the wrong time....

Link to comment
Share on other sites

I wondered about that. It is one of those trial and error things that I'd have to tinker with till it is correct. Here is an example using a property for the armor object. You'll still need to test compilation & function.

 

 

Scriptname _00MSfuntime extends ObjectReference  

Float Property TimeToWaitInSeconds Auto
Actor SelfActor
Armor Property HolyLight Auto

Event OnEquipped(Actor akActor)
  SelfActor = akActor
  RegisterForSingleUpdate(TimeToWaitInSeconds)
EndEvent

Event OnUpdate()
  If SelfActor.IsEquipped(HolyLight)
    Game.GetPlayer().Kill()
  EndIf
EndEvent

 

 

 

Link to comment
Share on other sites

If I enter that code as-is without editing a single thing it compiles successfully, but I'm still very confused about how to specify the number of seconds to wait.

 

Is "TimeToWaitInSeconds" placeholder text for this value, or is that a functional line and the number goes somewhere else? If I replace that with a number the script breaks, but "TimeToWaitInSeconds" is not something I've seen in a script before and google is giving me nothing.

 

Sorry I'm such a super noob but it's best to assume this is the first time I've seen a computer. :laugh: I appreciate the help!

Link to comment
Share on other sites

I set it up as a property. On the object you attach the script to, highlight the script, press the properties button. A new window appears, in that window the properties will be listed. Press the auto-fill button to see if any can be automatically filled. Your armor property should as you gave me the Editor ID name for it. Highlight the remaining property and notice that the grey area on the right hand side has input fields appear. Use those input fields to assign the appropriate data. Since the 'TimeToWaitInSeconds' is a float, you'll want to use a decimal format (i.e. 1.2)

 

TimeToWaitInSeconds is a variable name I used for the property. It could have been something all together different like 'IamCookooForCocoPuffs'. Somehow I don't think that would have made as much sense. :P

Link to comment
Share on other sites

You can add some Notification statements to see while your are playing whether or not the script is reaching certain parts or not. My suspicion is that because the object is inside a player inventory that the OnUpdate event won't trigger. But since I hardly ever apply a script to an object that an NPC will carry around, it isn't something that I'd know for certain.

 

Alternatively, scroll up to other variation I showed that was using a simple wait statement and adapt the script accordingly but with retaining the property for your object. Doing that should definitely work.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...