NeinGaming Posted November 4, 2022 Share Posted November 4, 2022 Hi there, I'm very new to modding and am just trying my hands at some items I can give NPC or followers to create notifications for kills, getting killed, entering bleedout etc. The OnKill one will simply not fire for followers, while it works fine for every other NPC I give the item to, script attached. Events like OnDeath fire on followers as well, and the items for those are exactly the same, just an armor item with the script on it, so I assume it's not that. But then again, what do I know haha. To be perfectly honest, I don't even know why I'm using "remote event", that's just what I saw in other mods so far. So I could try out storing the current actor in a variable, and listening for a non-remote event... ... but that leads to another newbie question: if I create a variable, like AkCurrentOwner or something, which I assume every script instance has a local copy of, give the item to a bunch of characters, but then later change the variable name to, say, AkCurrentHolder -- how would the existing instances deal with that? I still haven't found articles answering such questions, so any pointers where to look I'd be very grateful for. ScriptName MonitorRings_Kill extends ObjectReference hidden Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer) If !(akOldContainer == None) Actor old_actor = akOldContainer as Actor if !(old_actor == None) if !(old_actor == Game.GetPlayer()) UnregisterForRemoteEvent(old_actor, "OnKill") debug.notification("Monitor ring (Kill) unattached from " + old_actor.GetLeveledActorBase().GetName()) endif endif endif If !(akNewContainer == None) Actor new_actor = akNewContainer as Actor if !(new_actor == None) if !(new_actor == Game.GetPlayer()) RegisterForRemoteEvent(new_actor, "OnKill") debug.notification("Monitor ring (Kill) attached to " + new_actor.GetLeveledActorBase().GetName()) endif endif endif EndEvent Event Actor.OnKill(Actor akSender, Actor akVictim) debug.notification(akSender.GetLeveledActorBase().GetName() + " killed " + akVictim.GetLeveledActorBase().GetName()) EndEvent Link to comment Share on other sites More sharing options...
NeinGaming Posted November 4, 2022 Author Share Posted November 4, 2022 (edited) The event will be relayed only to this script and will not be sent to other scripts attached to the same object, or to any aliases or magic effects attached to the object. (from RegisterForRemoteEvent) On the one hand, I'm thinking maybe that event is caught somewhere else -- but then again, shouldn't my item, being the last to register for the event, override that? Or does the first thing that listens for an event on an object reserve that even for itself, basically? I think I need to look at what else might be handling OnKill, both in the base game and the mods I have installed. Edited November 4, 2022 by NeinGaming Link to comment Share on other sites More sharing options...
RaidersClamoring Posted November 4, 2022 Share Posted November 4, 2022 The restricted script-scope thingy should be fine since you are both registering and receiving the event within the same script. There might be something for you to find in FollowerScript.psc and CompanionActorScript.psc sitting among the base source scripts.For instance they make it easy to grab your current companion by RefAlias and track a lot of its behavior with FollowerScript.GetScript() ReferenceAlias CurrentCompanion = FollowerScript.GetScript().CompanionActor CompRef = CurrentCompanion.GetRef() Not sure if the above is much help but the scripts themselves look very useful and are often found in scripts (the good ones) as a shortcut to follower data. Link to comment Share on other sites More sharing options...
SKKmods Posted November 4, 2022 Share Posted November 4, 2022 What form or object are you attaching the MonitorRings_Kill script to ? Also to be neat: If (akOldContainer != None) && (akOldContainer is Actor) Link to comment Share on other sites More sharing options...
NeinGaming Posted November 4, 2022 Author Share Posted November 4, 2022 The restricted script-scope thingy should be fine since you are both registering and receiving the event within the same script. There might be something for you to find in FollowerScript.psc and CompanionActorScript.psc sitting among the base source scripts. For instance they make it easy to grab your current companion by RefAlias and track a lot of its behavior with FollowerScript.GetScript() ReferenceAlias CurrentCompanion = FollowerScript.GetScript().CompanionActor CompRef = CurrentCompanion.GetRef() Not sure if the above is much help but the scripts themselves look very useful and are often found in scripts (the good ones) as a shortcut to follower data. Thanks! I've also seen Game.GetPlayerFollowers() in Follower Revive System :) What form or object are you attaching the MonitorRings_Kill script to ? Also to be neat: If (akOldContainer != None) && (akOldContainer is Actor) Haha yeah, the style needs improvements for sure, also still getting used to camel case (but no point fighting it either I guess heh) It's an armor form. To be precise, I copied the CF Beacon from the Create Followers mod, and basically just changed the script name and removed the 2 properties mine doesn't have. I also cloned the armour addon just to be "safe", though actually I don't need/want these items to be worn, so down the line I might make it something else, like more of a beacon type contraption, but that's neither here nor there :) Creation Kit refuses to not crash on me, even without any mods etc. so for now I'm doing everything in FO4edit, if that makes a difference. Link to comment Share on other sites More sharing options...
SKKmods Posted November 4, 2022 Share Posted November 4, 2022 I have had issues using Self.RegisterForRemoteEvent on scripts attached to non persistent (?) Objects. My workaround is to put the actor in a quest ReferenceAlias or RefCollectionAlias with an attached scipt that receives the native object and actor events. Link to comment Share on other sites More sharing options...
RaidersClamoring Posted November 4, 2022 Share Posted November 4, 2022 Thanks! I've also seen Game.GetPlayerFollowers() in Follower Revive System :smile: Indeed there are many ways to do the same thing in these fascinating and bewildering game systems. It might work perfectly for your ends but as SKK mentions, ReferenceAliases, they are so smooth to use and are clearly something Bethesda has prioritized to be their main vehicle for any actor other than the player, looking at how frictionless everything *except setting them up* is. Lol. With FollowerScript you get freebie and don't have to set up anything, it will conveniently serve you the RefAlias on demand when you make it a variable or property using FollowerScript.GetScript(). Link to comment Share on other sites More sharing options...
NeinGaming Posted November 4, 2022 Author Share Posted November 4, 2022 Thanks for the suggestion, I should learn about those things either way, I hear for anything non-trivials quests are a must. Ultimately, I want to do stuff like have NPC gain stats or perks for kills, so I probably wouldn't get away (well) with doing it this cheaply anyway ^^ Link to comment Share on other sites More sharing options...
NeinGaming Posted November 4, 2022 Author Share Posted November 4, 2022 (edited) (double post sorry) Edited November 4, 2022 by NeinGaming Link to comment Share on other sites More sharing options...
NeinGaming Posted November 8, 2022 Author Share Posted November 8, 2022 I feel like I'm really gimped by not using Creation Kit. What little I find in relation to Reference Aliases is in relation to quests and doing things in CK. I tried making a ring "just for Piper", because then I could at least put something in the FormID field of the property I added to the script. So that's a property named PiperAlias of type Object, and in the Object Union the Form ID points to her, and the Alias is "None" because, welll, I have no clue what that does.(before that, I tried making one with NULL as FormID, and use ForceRefTo in the script, but the alias variable stayed "None" and of course attaching events to that failed -- so I figured why not limit the scope to a particular NPC for now) In the script itself it's declared as such: ReferenceAlias Property PiperAlias Auto Const Mandatorybut with or without the const/mandatory bits, I get this in the logs error: Property PiperAlias on script PipersRings_Kill attached to Item 43 in container (00000014) cannot be bound because (00002F1E) is not the right typeWell, I have no idea what I'm doing, I'll be the first to admit. And as such I'm not posting this expecting help, because the problem really might just be me trying to do things I don't know enough for yet.Are there mods out there that do something when followers kill things? Maybe I could look at those.What really gets me is how when I dismiss followers, the "old" rings I already gave them, that work fine for random NPC, also start firing their events. So registering for the event while they're still a follower works, but the event handling function only gets called when they're no longer a follower. I tried removing the "treat as player follower" flag in the follow packages Liga of my Companions has, and I tried outright removing Liga, but none of that made a difference. Though I know that I really, really need to make a somewhat vanilla (plus the unofficial patch and such things) MO2 profile and save, it's a bit dumb to learn modding in the middle of an actual playthrough with all sorts of things that could be the culprit. Oh, and on a tangent, I made another ring that keeps people in bleedout for a few minutes: just setting bleedout recovery to false when entering bleedout, setting a timer, then setting it it to true. Playing with SKK Combat Settlers set to mortal settlers (but NOT settlers needing stimpaks) and unique protection, I sometimes (but not every time, I tested a bit) get the notification that a combat settler needs a stimpak, and I can revive them. If I wait until the bleedout ring recovers them, that objective marker of a combat settler needing a stimpak stays forever, but still, that's awesome and something I want to play around with more. Currently I gave all unique and therefore immortal settlers a perk that makes them unable to hit the broad side of a barn, on top of making them selfish cowards, so they basically don't really help in combat (and when they don't get up instantly all the time, they also don't provide a lot of distraction). But I'd much prefer to have, say 5 minutes to revive them, plus some kind of semi-permanent damage for every time they go down, likewise for followers. Link to comment Share on other sites More sharing options...
Recommended Posts