ka385385 Posted December 29, 2024 Share Posted December 29, 2024 I'm trying to write a script let check the player outfit during the SysDef undercover quest, but I'm not exactly sure what's the best way to trigger the script, I tried it with a quest with OnPlayerTeleport event but it's not working, any idea? Scriptname CheckDisguiseScript extends Quest Armor Property Clothes_CrimsonFleet_Space_Crew_01 Auto Armor Property Clothes_CrimsonFleet_SpacePirate_02 Auto Armor Property Spacesuit_CrimsonFleet_Assault Auto Armor Property Spacesuit_CrimsonFleet_Charger Auto Armor Property Spacesuit_CrimsonFleet_Officer Auto Armor Property Spacesuit_CrimsonFleet_Sniper Auto GlobalVariable Property CF_SysDefShutdown Mandatory Const Auto Message Property DisguiseWarningMessage Auto Location Property StationTheKeyInteriorLocation Auto Quest Property CF03 Auto Quest Property CF04 Auto Quest Property CF05 Auto Quest Property CF06 Auto Quest Property CF07 Auto Event OnQuestInit() RegisterForStages() EndEvent Event OnPlayerTeleport() Actor playerRef = Game.GetPlayer() SpaceshipReference HomeShip = Game.GetPlayerHomeSpaceShip() if (CF_SysDefShutdown.GetValue() == 0 && CF03.GetStageDone(1000) && !CF07.GetStageDone(1000) && playerRef.GetCurrentLocation() == StationTheKeyInteriorLocation) if (!playerRef.IsEquipped(Clothes_CrimsonFleet_Space_Crew_01) && !playerRef.IsEquipped(Clothes_CrimsonFleet_SpacePirate_02) && !playerRef.IsEquipped(Spacesuit_CrimsonFleet_Assault) && !playerRef.IsEquipped(Spacesuit_CrimsonFleet_Charger) && !playerRef.IsEquipped(Spacesuit_CrimsonFleet_Officer) && !playerRef.IsEquipped(Spacesuit_CrimsonFleet_Sniper)) DisguiseWarningMessage.Show() playerRef.MoveTo(HomeShip) endif elseif(CF07.GetStageDone(1000)) UnRegisterForStages() endif EndEvent Function RegisterForStages() RegisterForRemoteEvent(CF03, "OnPlayerTeleport") RegisterForRemoteEvent(CF04, "OnPlayerTeleport") RegisterForRemoteEvent(CF05, "OnPlayerTeleport") RegisterForRemoteEvent(CF06, "OnPlayerTeleport") RegisterForRemoteEvent(CF07, "OnPlayerTeleport") EndFunction Function UnRegisterForStages() UnRegisterForRemoteEvent(CF03, "OnPlayerTeleport") UnRegisterForRemoteEvent(CF04, "OnPlayerTeleport") UnRegisterForRemoteEvent(CF05, "OnPlayerTeleport") UnRegisterForRemoteEvent(CF06, "OnPlayerTeleport") UnRegisterForRemoteEvent(CF07, "OnPlayerTeleport") EndFunction Link to comment Share on other sites More sharing options...
LarannKiar Posted December 30, 2024 Share Posted December 30, 2024 You can try this script. I haven't tested it but you'll probably need to write something like this. Scriptname YOURSCRIPTNAME extends Quest Const Armor[] Property CrimsonFleetArmors Auto Const ; array of properties (i.e. script variables accessible by other scripts), const means it is constant so you can define and change it in the editor only Event OnQuestInit() Utility.Wait(1.0) ; give a short time for the engine to initialize everything; failsafe in case the mod is installed on a new game (in theory, you wouldn't need it but you never know) RegisterForPlayerTeleport() ; native function which is defined in ScriptObject.psc, you can't register for it remotely Actor PlayerActor = Game.GetPlayer() RegisterForRemoteEvent(PlayerActor, "OnItemEquipped") ; native events in Actor.psc, you need to register remotely for these events sent by the Player Actor RegisterForRemoteEvent(PlayerActor, "OnItemUnequipped") EndEvent Event OnPlayerTeleport() ; basically it is sent after a load screen If IsPlayerDisguisedAsCrimsonFleetMember() == True HandleOnPlayerDisguisedAsCFMember(true) Else HandleOnPlayerDisguisedAsCFMember(false) EndIf EndEvent Bool Function IsPlayerDisguisedAsCrimsonFleetMember() ; loop CrimsonFleetArmors and return True if the player wears any Actor PlayerActor = Game.GetPlayer() Int Index = CrimsonFleetArmors.Length - 1 While Index >= 0 Armor LoopArmor = CrimsonFleetArmors[Index] If PlayerActor.IsEquipped(LoopArmor) Return True EndIf Index = Index - 1 EndWhile Return False EndFunction Event Actor.OnItemEquipped(Actor akSender, Form akBaseObject, ObjectReference akReference) ; if you register for a remote event, the sender's type (Actor) and the sender must be specified (the parameter name "akSender" is arbitrary) HandleOnItemEquippedUnequipped(akSender, akBaseObject) EndEvent Event Actor.OnItemUnequipped(Actor akSender, Form akBaseObject, ObjectReference akReference) ; note: if the script receives both OnItemEquipped and OnItemUnequipped and you equip an Armor whose Biped Slot overlaps an already worn Armor, both events are sent almost exactly at the same time HandleOnItemEquippedUnequipped(akSender, akBaseObject) EndEvent Function HandleOnItemEquippedUnequipped(Actor akSender, Form akBaseObject) If akSender == Game.GetPlayer() ; unnecessary if the script is registered for the player's equipped/unequipped events only Armor EquippedArmor = akBaseObject as Armor ; if this Form can be casted as Armor (i.e. an Armor form) If EquippedArmor If CrimsonFleetArmors.Find(EquippedArmor) >= 0 ; the equipped armor can be found in the array (array index starts at 0) HandleOnPlayerDisguisedAsCFMember(true) Else If IsPlayerDisguisedAsCrimsonFleetMember() == True ; otherwise, we need to determine whether the player wears any of the array HandleOnPlayerDisguisedAsCFMember(true) Else HandleOnPlayerDisguisedAsCFMember(false) EndIf EndIf EndIf EndIf EndFunction Function HandleOnPlayerDisguisedAsCFMember(Bool abDisguised) If abDisguised Debug.Notification("Player is dressed as a Crimson Fleet member.") Else Debug.Notification("Player is not dressed as a Crimson Fleet member.") EndIf EndFunction Link to comment Share on other sites More sharing options...
Recommended Posts