vizex1 Posted August 18, 2019 Posted August 18, 2019 Can someone help me with this? I'm having trouble figuring out how to make it work.Scriptname MyScript extends ObjectReference Event OnUnequipped(Actor Player) if (Player.IsWeaponDrawn() == True) RegisterForRemoteEvent(BQuest, "OnStageSet") endIf EndEvent Event BQuest.OnStageSet(int auiStageID, int auiItemID) If auiStageID == 10 Debug.Notification("Boom") Debug.Trace("Boom") endIf EndEvent Quest Property BQuest Auto Actor Property Player Auto It gives this error:(9,0): bquest is not a known script type and therefore cannot be the source of the onstageset event
DieFeM Posted August 18, 2019 Posted August 18, 2019 (edited) The event should match the object script type, and also the fist parameter must be the sender, for example: An actor event Event OnDying(Actor akKiller) becomes: Event Actor.OnDying(Actor akSender, Actor akKiller) or a Object reference event: Event OnWorkshopMode(bool aStart) becomes: Event ObjectReference.OnWorkshopMode(ObjectReference akSender, bool aStart) and for a Quest event Event OnStageSet(int auiStageID, int auiItemID) becomes: Event Quest.OnStageSet(Quest akSender, int auiStageID, int auiItemID) So akSender is the object from which the event comes. So if you remotely register for multiple objects for the same event you can use akSender to know which of them sent the event. Edited August 18, 2019 by DieFeM
SKKmods Posted August 18, 2019 Posted August 18, 2019 To elaborate on DFM;Scriptname MyScript extends ObjectReference Quest Property BQuest Auto ;declare at the top of the script to help reading Actor Property Player Auto Event OnUnequipped(Actor akActor) ;Always use default function and event references if (akActor == Player) && (Player.IsWeaponDrawn() == True) ;incase script is attached to non player object RegisterForRemoteEvent(BQuest, "OnStageSet") endIf EndEvent Event Quest.OnStageSet(Quest akSender, int auiStageID, int auiItemID) If (akSender == BQuest) && (auiStageID == 10) UnRegisterForRemoteEvent(BQuest, "OnStageSet") ;keep it clean Debug.Notification("Boom") Debug.Trace("Boom") endIf EndEvent
vizex1 Posted August 19, 2019 Author Posted August 19, 2019 (edited) Thanks DieFem and SKK50! Do these RegisterForRemoteEvents cause slowdowns in game? Is it good practice to unregister them as soon as possible or would it be okay to have one registered for as long as the player has an item equipped, which could be for a long time. Also if the player puts the object that contains this script away in a container never to be used again, does this disable the script? Or is it like running forever? Edited August 19, 2019 by vizex1
SKKmods Posted August 19, 2019 Posted August 19, 2019 Unless a script is marked Const in the header, once it is activated it is persistent and runs forever to ensure its variables are not lost. But if there is no activity like loops, constant event triggers like OnLoad() or latent timers/event registrations that persistence is not a problem. Registering for an event will create a trigger on a watchlist so yes it is overhead and best practice would be to unregister when the event is no longer needed, like OnContainerChanged() where (akNewContainer != PlayerREF).
Recommended Posts