the Sim Settlements forums!

Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Detecting if a workshop object has become unpowered/powered

cbrgamer2

Well-Known Member
Messages
727
Hi,
Does anybody know if there an event that can be received when a workshop object loses or gains power? I want a quest script to receive the event.
 
Yeah, already tried those. The first two need to be run on a script attached to the actual object, which isn't what I want.
I haven't been able to get RegisterForRemoteEvent(WorkshopParent, "WorkshopObjectPowerStageChanged") working.
This is the event I've got to catch it :
Event WorkshopParentScript.WorkshopObjectPowerStageChanged(workshopparentscript akSenderRef, var[] akArgs)
debug.MessageBox("power")
EndEvent

I pulled it from one of KingGaths scripts. I'm not sure what I'm doing wrong.
 
You sure? I could have sworn I did it in the past... :scratchhead
Code:
Function RegisterEvents(ObjectReference akObjectToRegister)
    RegisterForRemoteEvent(akObjectToRegister, "OnPowerOn")
    ; etc...
EndFunction

Event ObjectReference.OnPowerOn(ObjectReference akSender, ObjectReference akPowerGenerator)
    ; akSender is the object I registered
    if ( bOnlyFireEventOnce )
        UnRegisterForRemoteEvent(kObjectToRegister, "OnPowerOn")
    endif

    ; do stuff
EndEvent
Anyway, you need to register that as a custom event.
RegisterForCustomEvent(WorkshopParent, "WorkshopObjectPowerStageChanged")
Kinggath defined a bunch of custom events in WSFW.

I use the CK wiki as a test to determine if it is a vanilla or custom event. If its not in the wiki, most likely its a custom event.
 
[sheepishly re-reads your original post]
Okay, I'll shut up now :grin
I was trying to listen to the onpoweron event with registerforcustomevent, not registerforremoteevent.

I did actually register the other one as a custom event, that was just a typo on my part in my post. So I'm still not sure what WorkshopObjectPowerStageChanged does. However, I'm pretty sure registering for the remote event for onpoweron and onpoweroff will work. Thanks.
 
This is odd. I can get the onpoweroff event to fire, but not the onpoweron event.
I've got RegisterForRemoteEvent(obj, "OnPowerOn") and have confirmed that that section of the script is run.
I've then got :
Event ObjectReference.OnPowerOn(ObjectReference akObjectRef)

As I said, I can register for the onpoweroff event and catch it fine. Just not onpoweron. Pity, I was getting all excited about what I could do with it!

The wiki says it is for when an object gains power for the first time (my emphasis). Does that mean if the object has had power then lost it, then gets turned back on, it won't fire?

EDIT : shit never mind, I just saw it. I need the extra parameter passed for the generator.
 
I'm still not sure what WorkshopObjectPowerStageChanged does.
Its been a while since I looked at that. IIRC, there is a function on WorkshopParentScript who's sole purpose is to send the custom event. WSFW adds this. Other WSFW scripts call that function to "report" an object who's power state changed It is done this way because a custom event can only be sent from the script it is defined in. I kinda remember reading a comment somewhere in a WSFW script...
RegisterForCustomEvent(WorkshopParent, "WorkshopObjectPower[B]State[/B]Changed") 'facepalm' I didn't even notice that... copy/pasta... lol
That's the problem with string literals... it lets typos be a giant PITA as the compiler has no way to throw errors telling you that you are a dummy...
Event ObjectReference.OnPowerOn(ObjectReference akObjectRef)
I'm curious. Did that compile? (Oh, I forgot, you aren't using the vanilla compiler... Or are you???)
I do know when you are half asleep and try to compile
Event Quest.OnWorkshopObjectDestroyed(ObjectReference akSender, ObjectReference akObjectRef)
The compiler will proclaim you are the biggest dummy of all dummies.... ;)

Don't feel bad about the reading fails. I can't tell you how many times Kinggath has pointed stuff like that out to me.
 
I'm curious. Did that compile?
Yeah, it did. Thanks a lot Caprica. :rollseye

That's the problem with string literals... it lets typos
That wasn't actually a typo. That's the custom event that WorkshopParentScript sends (interestingly enough, in a function called SendPowerStateChangedEvent).
This is from the Workshop Framework version of the script. KingGath registers for it in some of his scripts (ie, HUDManager).

Ironically, Caprica actually does throw an error if you put a custom event name that doesn't exist in the string.
 
Top