irswat Posted September 3, 2016 Share Posted September 3, 2016 (edited) It is my first script and there are some concepts in CK that I don't really understand much: how to properly use selfRef and the precise meaning of script extends x. The script is a time check for dawnfang/duskfang. It is attached to the swords. Between 6 am and 5:59 pm the sword becomes dawn fang. At 6 pm the sword becomes duskfang.here is the script. Please help me get it working! Scriptname DawnfangFX extends weapon {Dawnfang & duskfang FX} import utility import debug GlobalVariable property GetCurrentTime auto Weapon property adventurerdawnfang auto Weapon property tsasciduskblade auto Actor Property PlayerRef Auto bool LightOut=true bool ShiftyBlade=false Event OnEffectStart() float TimeofDay=GetCurrentTime.GetValue() if ((TimeofDay>=6.0)&&(TimeofDay<18.0)) LightOut=true else LightOut=false endif if ((PlayerRef.GetEquippedWeapon()==adventurerdawnfang)||(PlayerRef.GetEquippedWeapon(true)==adventurerdawnfang) || (PlayerRef.GetEquippedWeapon()==tsasciduskblade)||(PlayerRef.GetEquippedWeapon(true)==tsasciduskblade)) ShiftyBlade=true else ShiftyBlade=false endif if ((ShiftyBlade==true)&&(LightOut==true)) PlayerRef.EquipItem(adventurerdawnfang,false,true) Debug.Notification("Time of Day: " + TimeofDay) Debug.Notification("Dawnfang has emerged") elseif ((ShiftyBlade==true)&&(LightOut==false)) PlayerRef.EquipItem(tsasciduskblade,false,true) Debug.Notification("Time of Day: " + TimeofDay) Debug.Notification("Duskfang has emerged") endif endEVENT Edited September 3, 2016 by irswat Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 3, 2016 Share Posted September 3, 2016 Typically a script on an object will extend the script for that object type. So a script on a placed object will extend ObjectReference, a script on a quest will extend Quest. However, there is more to it than that. What the extends really does is allow the current script to use events/functions from the script being extended as if they were the same script. This is how MCM scripts can work. A mod's MCM script extends upon a base script in SkyUI's framework thus allowing the mod's MCM script to run functions and events without having to directly call the other script first. I would not refer to the player as selfRef. It gets confusing as 'self' refers to the object running the script. Use PlayerRef instead. Also, you keep casting it as an actor. It would be better to simply start out with the variable as an actor instead of an ObjectReference. But for this script it isn't even needed as the OnEquipped event contains an actor variable which passes into the script the actor that equipped the item. Furthermore, I'm not even sure if you can call EquipItem from an item in the inventory. You may need to consider using a player alias script to handle this. At any rate, here is a much shortened version which would do the exact same thing, provided that EquipItem does work from an object in an inventory. And following, after the comment marks, is a player alias version if you'd like to try that instead. Scriptname DawnfangFX extends Weapon {Dawnfang & duskfang FX} import utility import debug GlobalVariable property GetCurrentTime auto Weapon property adventurerdawnfang auto Weapon property adventurerduskfang auto Event OnEquipped(Actor akActor) If akActor == Game.GetPlayer() float TimeofDay = GetCurrentTime.GetValue() If (Self as Weapon) == adventurerduskfang && (TimeofDay >= 6.0 && TimeofDay < 18.0) PlayerRef.EquipItem(adventurerdawnfang,false,true) ElseIf (Self as Weapon) == adventurerdawnfang && (TimeofDay >= 18.0 || TimeofDay < 6.0) PlayerRef.EquipItem(adventurerduskfang,false,true) EndIf EndIf endEVENT ;========================= ;player alias version ScriptName DawnFangFXPlayerAlias Extends ReferenceAlias GlobalVariable Property GetCurrentTime Auto Weapon Property AdventureDawnFang Auto Weapon Property AdventureDuskFang Auto Actor Property PlayerRef Auto Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) float TimeofDay = GetCurrentTime.GetValue() If akBaseObject == AdventureDuskFang && (TimeofDay >= 6.0 && TimeofDay < 18.0) PlayerRef.EquipItem(AdventureDawnFang,false,true) ElseIf akBaseObject == AdventureDawnFang && (TimeofDay >= 18.0 || TimeofDay < 6.0) PlayerRef.EquipItem(AdventureDuskFang,false,true) EndIf EndEvent FYI - spaces are your friend. There is no benefit to removing all the spacing in a script. And you changed your script from what you originally posted... So some of what I said, might not make sense now to anyone who follows along. Link to comment Share on other sites More sharing options...
irswat Posted September 3, 2016 Author Share Posted September 3, 2016 (edited) thanks. You're right the script was changed. Scriptname DawnfangFX extends weapon {Dawnfang & duskfang FX} import utility import debug Weapon property adventurerdawnfang auto Weapon property tsasciduskblade auto Actor Property PlayerRef Auto Sound property DawnfangEquipSFXMarker auto Sound property DuskfangEquipSFXMarker auto bool LightOut=true bool ShiftyBlade=false ;credit to FamilyFrank for the get time function float Function GetCurrentHourOfDay() float Time = Utility.GetCurrentGameTime() Time -= Math.Floor(Time) ; Remove "previous in-game days passed" bit Time *= 24 ; Convert from fraction of a day to number of hours Return Time EndFunction Event OnLoad() float TimeofDay=GetCurrentHourOfDay() Debug.Notification("Time of Day: " + TimeofDay) if ((TimeofDay>=6.0)&&(TimeofDay<18.0)) LightOut=true else LightOut=false endif if ((PlayerRef.GetEquippedWeapon()==adventurerdawnfang)||(PlayerRef.GetEquippedWeapon(true)==adventurerdawnfang) || (PlayerRef.GetEquippedWeapon()==tsasciduskblade)||(PlayerRef.GetEquippedWeapon(true)==tsasciduskblade)) ShiftyBlade=true else ShiftyBlade=false endif ;credit to steve40 for help adding sounds to a script if ((ShiftyBlade==true)&&(LightOut==true)) PlayerRef.EquipItem(adventurerdawnfang,false,true) int SFXPointer1 = DawnfangEquipSFXMarker.play(PlayerRef) Sound.SetInstanceVolume(SFXPointer1, 1.0) Debug.Notification("Time of Day: " + TimeofDay) Debug.Notification("Dawnfang has emerged") elseif ((ShiftyBlade==true)&&(LightOut==false)) PlayerRef.EquipItem(tsasciduskblade,false,true) int SFXPointer2 = DuskfangEquipSFXMarker.play(PlayerRef) Sound.SetInstanceVolume(SFXPointer2, 1.0) Debug.Notification("Time of Day: " + TimeofDay) Debug.Notification("Duskfang has emerged") endif endEVENTIt's like I'm not using the right script extend x, or event, because the debug message displaying time of day isn't playing, and that isn't a conditional statement. I'm going to try using your OnEquipped (actor akActor) event to see if that works. Edited September 3, 2016 by irswat Link to comment Share on other sites More sharing options...
FrankFamily Posted September 3, 2016 Share Posted September 3, 2016 OnLoad triggers when the object's 3d is loaded, so while in inventory it won't, i don't its the appropiate event for this. Indeed go for onequipped. And extend objectreference, not weapon, both OnLoad and Onequipped belong to objectreference so that's what you'd want to extend. Link to comment Share on other sites More sharing options...
irswat Posted September 3, 2016 Author Share Posted September 3, 2016 (edited) Thank you both very much! The script is working. Any idea why the sound effect won't play?I created a sound descriptor with the wav, and a sound marker that points to the descriptor, which I declared as a property in the script. import utility import debug import sound Weapon property adventurerdawnfang auto Weapon property tsasciduskblade auto Actor Property PlayerRef Auto Sound property DawnfangEquipSFXMarker auto Sound property DuskfangEquipSFXMarker auto ;credit to FamilyFrank for the get time function float Function GetCurrentHourOfDay() float Time = Utility.GetCurrentGameTime() Time -= Math.Floor(Time) ; Remove "previous in-game days passed" bit Time *= 24 ; Convert from fraction of a day to number of hours Return Time EndFunction Event OnEquipped(Actor akActor) float TimeofDay=GetCurrentHourOfDay() ;credit to steve40 for help adding sounds to a script if ((TimeofDay>=6) && (TimeofDay<18)) if (PlayerRef.GetEquippedWeapon()==tsasciduskblade)||(PlayerRef.GetEquippedWeapon(true)==tsasciduskblade) PlayerRef.UnequipItem(tsasciduskblade,true,true) Debug.Notification("You cannot equip Duskfang during the day") int SFXPointer1 = DawnfangEquipSFXMarker.play(PlayerRef) Sound.SetInstanceVolume(SFXPointer1, 1.0) PlayerRef.EquipItem(adventurerdawnfang,false,true) Debug.Notification("Dawnfang has emerged") endif elseif ((TimeofDay>=18) && (TimeofDay<6)) if (PlayerRef.GetEquippedWeapon()==adventurerdawnfang)||(PlayerRef.GetEquippedWeapon(true)==adventurerdawnfang) PlayerRef.UnequipItem(adventurerdawnfang,true,true) Debug.Notification("You cannot equip Dawnfang during the night") int SFXPointer1 = DuskfangEquipSFXMarker.play(PlayerRef) Sound.SetInstanceVolume(SFXPointer1, 1.0) PlayerRef.EquipItem(tsasciduskblade,false,true) Debug.Notification("Duskfang has emerged") endif endif endEVENT Edited September 3, 2016 by irswat Link to comment Share on other sites More sharing options...
irswat Posted September 3, 2016 Author Share Posted September 3, 2016 is there an event like OnUpdate for ObjectReferences? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 3, 2016 Share Posted September 3, 2016 OnUpdate() event is available to any object because it is on the Form script. It simply needs to be registered with something like RegisterForSingleUpdate(). Link to comment Share on other sites More sharing options...
irswat Posted September 3, 2016 Author Share Posted September 3, 2016 thank you Link to comment Share on other sites More sharing options...
irswat Posted September 3, 2016 Author Share Posted September 3, 2016 I didn't realize I had to manually register the script properties. Oy vay. Script is almost fully functional I think. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 4, 2016 Share Posted September 4, 2016 Manually register? If by that you mean, press the properties button and assign the data that you want to use. Then yes, you have to do that. Link to comment Share on other sites More sharing options...
Recommended Posts