qwertypol012 Posted January 1, 2019 Share Posted January 1, 2019 (edited) First of all, thanks for your concern on this help request of mine :smile: I'm not a native English speaker, so please be advised if my English is a bit messed up or not properly arranged.I've been modding skyrim for several years, most of them involving patching and editing records in the plugins, but this is actually my first time trying to write a script. Yes, i'm totally new to scripting, and i just learned a bit about papyrus recently (i have no programming background whatsoever, so yeah papyrus is my first scripting language i learnt... just a bit, very very little). I'm currently trying to make a script about using a "hold key" feature to activate an effect. The effect is higher and further jump effect (i'm involving fJumpHeightMin, fJumpMoveMult, and SpeedMult game settings) which will be triggered when some specific conditions are made. The conditions are:1. The player must have a specific amount of Stamina in some variable ranges in order for the effect to work (i'm using getBaseAV("Stamina")).2. The player must wear a specific footwear in order for the effect to work.3. The player must hold a sneak key to activate the effect (may need to write how many seconds to hold the key, right? please do tell me). Consider that we need to hold the key for at least 1 second. When the player holds the sneak key for 1 second, the character will jump with the new fJumpHeightMin, fJumpMoveMult, and fJumpFallHeightMin game settings.4. The effect activation will cost some Stamina (so the player will lose that amount of Stamina whenever he/she activate the effect). Lets say, the Stamina cost is 25.5. A message will pop up on the up left corner of the screen if the player has no enough amount of Stamina to cast the effect. The effect is part of a magic effect attached into the footwear (in condition 2). So this script will only activate when the player wears that footwear.I understand that this script requires SKSE, and i'm having no clue on what exactly i should write to make it work as intended. I found OnKeyUp and OnKeyDown forms of SKSE but don't know exactly how to use it.The amount of variable stamina ranges (condition 1) and the name of the footwear (condition 2) will be written in the following (my roughly unfinished written script): Scriptname BerserkerJump extends activemagiceffect {Sets fJumpHeightMin, fJumpMoveMult and fJumpFallHeightMin to higher values if you are transformed, or sets them back to default if you are normal} Armor Property ArmorBerserkerWBoots2 Auto int Property Stamina Auto Event OnEffectStart(Actor akTarget, Actor akCaster) if Game.GetPlayer().IsEquipped(ArmorBerserkerWBoots2) && Game.GetPlayer().getBaseAV("Stamina") as int >= 80 && Game.GetPlayer().getBaseAV("Stamina") as int <= 159 if(Game.GetGameSettingFloat("fJumpHeightMin") == 76) Game.SetGameSettingFloat("fJumpHeightMin", 114) endif if(Game.GetGameSettingFloat("fJumpMoveMult") == 0.3) Game.SetGameSettingFloat("fJumpMoveMult", 0.45) endif if(Game.GetGameSettingFloat("fJumpFallHeightMin") == 600) Game.SetGameSettingFloat("fJumpFallHeightMin", 750) endif else if(Game.GetGameSettingFloat("fJumpHeightMin") == 114) Game.SetGameSettingFloat("fJumpHeightMin", 76) endif if(Game.GetGameSettingFloat("fJumpMoveMult") == 0.45) Game.SetGameSettingFloat("fJumpMoveMult", 0.3) endif if(Game.GetGameSettingFloat("fJumpFallHeightMin") == 750) Game.SetGameSettingFloat("fJumpFallHeightMin", 600) endif ;Do Nothing ;Debug.Notification("Not enough Stamina to cast...") endif if Game.GetPlayer().IsEquipped(ArmorBerserkerWBoots2) && Game.GetPlayer().getBaseAV("Stamina") as int >= 160 && Game.GetPlayer().getBaseAV("Stamina") as int <= 239 if(Game.GetGameSettingFloat("fJumpHeightMin") == 76) Game.SetGameSettingFloat("fJumpHeightMin", 152) endif if(Game.GetGameSettingFloat("fJumpMoveMult") == 0.3) Game.SetGameSettingFloat("fJumpMoveMult", 0.6) endif if(Game.GetGameSettingFloat("fJumpFallHeightMin") == 600) Game.SetGameSettingFloat("fJumpFallHeightMin", 900) endif else if(Game.GetGameSettingFloat("fJumpHeightMin") == 152) Game.SetGameSettingFloat("fJumpHeightMin", 76) endif if(Game.GetGameSettingFloat("fJumpMoveMult") == 0.6) Game.SetGameSettingFloat("fJumpMoveMult", 0.3) endif if(Game.GetGameSettingFloat("fJumpFallHeightMin") == 900) Game.SetGameSettingFloat("fJumpFallHeightMin", 600) endif ;Do Nothing ;Debug.Notification("Not enough Stamina to cast...") endif if Game.GetPlayer().IsEquipped(ArmorBerserkerWBoots2) && Game.GetPlayer().getBaseAV("Stamina") as int >= 240 && Game.GetPlayer().getBaseAV("Stamina") as int <= 319 if(Game.GetGameSettingFloat("fJumpHeightMin") == 76) Game.SetGameSettingFloat("fJumpHeightMin", 190) endif if(Game.GetGameSettingFloat("fJumpMoveMult") == 0.3) Game.SetGameSettingFloat("fJumpMoveMult", 0.75) endif if(Game.GetGameSettingFloat("fJumpFallHeightMin") == 600) Game.SetGameSettingFloat("fJumpFallHeightMin", 1050) endif else if(Game.GetGameSettingFloat("fJumpHeightMin") == 190) Game.SetGameSettingFloat("fJumpHeightMin", 76) endif if(Game.GetGameSettingFloat("fJumpMoveMult") == 0.75) Game.SetGameSettingFloat("fJumpMoveMult", 0.3) endif if(Game.GetGameSettingFloat("fJumpFallHeightMin") == 1050) Game.SetGameSettingFloat("fJumpFallHeightMin", 600) endif ;Do Nothing ;Debug.Notification("Not enough Stamina to cast...") endif if Game.GetPlayer().IsEquipped(ArmorBerserkerWBoots2) && Game.GetPlayer().getBaseAV("Stamina") as int >= 320 && Game.GetPlayer().getBaseAV("Stamina") as int <= 399 if(Game.GetGameSettingFloat("fJumpHeightMin") == 76) Game.SetGameSettingFloat("fJumpHeightMin", 228) endif if(Game.GetGameSettingFloat("fJumpMoveMult") == 0.3) Game.SetGameSettingFloat("fJumpMoveMult", 0.9) endif if(Game.GetGameSettingFloat("fJumpFallHeightMin") == 600) Game.SetGameSettingFloat("fJumpFallHeightMin", 1200) endif else if(Game.GetGameSettingFloat("fJumpHeightMin") == 228) Game.SetGameSettingFloat("fJumpHeightMin", 76) endif if(Game.GetGameSettingFloat("fJumpMoveMult") == 0.9) Game.SetGameSettingFloat("fJumpMoveMult", 0.3) endif if(Game.GetGameSettingFloat("fJumpFallHeightMin") == 1200) Game.SetGameSettingFloat("fJumpFallHeightMin", 600) endif ;Do Nothing ;Debug.Notification("Not enough Stamina to cast...") endif if Game.GetPlayer().IsEquipped(ArmorBerserkerWBoots2) && Game.GetPlayer().getBaseAV("Stamina") as int >= 400 && Game.GetPlayer().getBaseAV("Stamina") as int <= 479 if(Game.GetGameSettingFloat("fJumpHeightMin") == 76) Game.SetGameSettingFloat("fJumpHeightMin", 266) endif if(Game.GetGameSettingFloat("fJumpMoveMult") == 0.3) Game.SetGameSettingFloat("fJumpMoveMult", 1.05) endif if(Game.GetGameSettingFloat("fJumpFallHeightMin") == 600) Game.SetGameSettingFloat("fJumpFallHeightMin", 1350) endif else if(Game.GetGameSettingFloat("fJumpHeightMin") == 266) Game.SetGameSettingFloat("fJumpHeightMin", 76) endif if(Game.GetGameSettingFloat("fJumpMoveMult") == 1.05) Game.SetGameSettingFloat("fJumpMoveMult", 0.3) endif if(Game.GetGameSettingFloat("fJumpFallHeightMin") == 1350) Game.SetGameSettingFloat("fJumpFallHeightMin", 600) endif ;Do Nothing ;Debug.Notification("Not enough Stamina to cast...") endif if Game.GetPlayer().IsEquipped(ArmorBerserkerWBoots2) && Game.GetPlayer().getBaseAV("Stamina") as int >= 480 && Game.GetPlayer().getBaseAV("Stamina") as int <= 559 if(Game.GetGameSettingFloat("fJumpHeightMin") == 76) Game.SetGameSettingFloat("fJumpHeightMin", 304) endif if(Game.GetGameSettingFloat("fJumpMoveMult") == 0.3) Game.SetGameSettingFloat("fJumpMoveMult", 1.2) endif if(Game.GetGameSettingFloat("fJumpFallHeightMin") == 600) Game.SetGameSettingFloat("fJumpFallHeightMin", 1500) endif else if(Game.GetGameSettingFloat("fJumpHeightMin") == 304) Game.SetGameSettingFloat("fJumpHeightMin", 76) endif if(Game.GetGameSettingFloat("fJumpMoveMult") == 1.2) Game.SetGameSettingFloat("fJumpMoveMult", 0.3) endif if(Game.GetGameSettingFloat("fJumpFallHeightMin") == 1500) Game.SetGameSettingFloat("fJumpFallHeightMin", 600) endif ;Do Nothing ;Debug.Notification("Not enough Stamina to cast...") endif if Game.GetPlayer().IsEquipped(ArmorBerserkerWBoots2) && Game.GetPlayer().getBaseAV("Stamina") as int >= 560 && Game.GetPlayer().getBaseAV("Stamina") as int <= 639 if(Game.GetGameSettingFloat("fJumpHeightMin") == 76) Game.SetGameSettingFloat("fJumpHeightMin", 342) endif if(Game.GetGameSettingFloat("fJumpMoveMult") == 0.3) Game.SetGameSettingFloat("fJumpMoveMult", 1.35) endif if(Game.GetGameSettingFloat("fJumpFallHeightMin") == 600) Game.SetGameSettingFloat("fJumpFallHeightMin", 1650) endif else if(Game.GetGameSettingFloat("fJumpHeightMin") == 342) Game.SetGameSettingFloat("fJumpHeightMin", 76) endif if(Game.GetGameSettingFloat("fJumpMoveMult") == 1.35) Game.SetGameSettingFloat("fJumpMoveMult", 0.3) endif if(Game.GetGameSettingFloat("fJumpFallHeightMin") == 1650) Game.SetGameSettingFloat("fJumpFallHeightMin", 600) endif ;Do Nothing ;Debug.Notification("Not enough Stamina to cast...") endif EndEvent Event OnEffectFinish(Actor akTarget, Actor akCaster) Game.SetGameSettingFloat("fJumpHeightMin", 76) Game.SetGameSettingFloat("fJumpMoveMult", 0.3) Game.SetGameSettingFloat("fJumpFallHeightMin", 600) EndEvent So, where should i write codes for "holding the key" from SKSE in above script? And what to write? Some helps, examples, or corrections will be appreciated. Thanks in advance :smile: Edited January 3, 2019 by qwertypol012 Link to comment Share on other sites More sharing options...
qwertypol012 Posted January 2, 2019 Author Share Posted January 2, 2019 (edited) I think i figured it out somehow after looking into Pounce n Dash mod by stonedsquirrel. I duplicated his script and tweaked it a bit into my liking, so thanks to him (he made his mod's scripts free to use as long as not for commercial use). :smile: Now, what needs to be done is how to check the player's race when they activate the effect. To explain it further, i decided to switch the condition number 1 (as stated in my first post) from "based on stamina amount" into "based on race", so the variables of higher jump will be based on player's race and not on stamina amount anymore. I found function Game.GetPlayer().GetRace() and it looks like the correct function to use, but i'm not sure if it works for activemagiceffect script since that's what my script extends to. So, would anyone mind to confirm about this? Another thing i'm still wondering is that function Game.GetPlayer().GetRace() seems to require RaceText string to correctly check for race, and i don't know if we can put strings as properties for activemagiceffect script. Also, since the script is supposed to check for all vanilla race, how do we write all of vanilla race records into a single RaceText strings to be used by Game.GetPlayer().GetRace() function? Can we just put some numbers in front of "RaceText" to identify all vanilla races? Or do we have a better method to check them all which works under activemagiceffect script?I know this may sound stupid or funny for some papyrus experts, hence i'm sorry still i'm still so green in this expertise :sweat:. So, any enlightenments will be really appreciated :laugh: Here i also put the new script i wrote as an attachment. It's not completed yet in the part of vanilla race check, but other parts should have been done already. The script is too long to be copied here as a code, so i attached it instead. If there are some errors in the script, please give me correction. Thanks in advance :smile: Edited January 2, 2019 by qwertypol012 Link to comment Share on other sites More sharing options...
qwertypol012 Posted January 2, 2019 Author Share Posted January 2, 2019 (edited) Oh, i just remembered. There's another thing i'm also wodering. Currently i put string RaceText = "[Race <xxxRace (000xxxxx)>]" under Function because that's the part in which the script applies the higher jump effect to the player. So, will it work? Or does it have to be put under Events? If so, how to correctly check the race when the effect is activated then? Thanks in advance! For some reason the attachment didn't work, so i'll just put the script here. Sorry if it's too long, but please do tell me if there's another way to post it here in a more simple way. Edit: just wrapped it in spoiler, good now Scriptname BerserkerDash extends activemagiceffect {attached to magic effect, used in enchantment, this decides which effect to add} ;Didn't put the properties here to keep it shorter ;-------------------------------------------------------------------------------------------------------------------------------------------------------- ;------ Get Settings ------------------------------------------------------------------------------------------------------------------------------------ ;-------------------------------------------------------------------------------------------------------------------------------------------------------- Function GetSettings() SneakKey = Input.GetMappedKey("Sneak") RegisterForKey(SneakKey) SprintKey = Input.GetMappedKey("Sprint") RegisterForKey(SprintKey) JumpHeight = DashStoreJump.GetValue() JumpLength = DashStoreLength.GetValue() SpeedMult = DashStoreSpeed.GetValue() HoldTimer = DashTimerHold.Getvalue() Delay1 = DashTimerDelay1.Getvalue() Delay2 = DashTimerDelay2.GetValue() Delay3 = DashTimerDelay3.GetValue() Delay4 = DashTimerDelay4.GetValue() EffectTimer = DashTimerEffect.Getvalue() FallDelay = DashTimerFall.Getvalue() Jump1 = DashJump1.Getvalue() Length1 = DashLength1.Getvalue() Speed1 = DashSpeed1.Getvalue() Jump2 = DashJump2.Getvalue() Length2 = DashLength2.Getvalue() Speed2 = DashSpeed2.Getvalue() Jump3 = DashJump3.Getvalue() Length3 = DashLength3.Getvalue() Speed3 = DashSpeed3.Getvalue() Jump4 = DashJump4.Getvalue() Length4 = DashLength4.Getvalue() Speed4 = DashSpeed4.Getvalue() Jump5 = DashJump5.Getvalue() Length5 = DashLength5.Getvalue() Speed5 = DashSpeed5.Getvalue() DashCostX2 = DashCostMult2.Getvalue() DashCostX3 = DashCostMult3.Getvalue() DashCostX4 = DashCostMult4.Getvalue() DashCostX5 = DashCostMult5.Getvalue() If DashFX.GetValue() == 0 zzDashAbilityI = zzDashAbilityBlankI zzDashAbilityII = zzDashAbilityBlankII zzDashAbilityIII = zzDashAbilityBlankIII zzDashAbilityIV = zzDashAbilityBlankIV zzDashAbilityV = zzDashAbilityBlankV ElseIf DashFX.GetValue() == 1 zzDashAbilityI = zzDashAbilityI zzDashAbilityII = zzDashAbilityII zzDashAbilityIII = zzDashAbilityIII zzDashAbilityIV = zzDashAbilityIV zzDashAbilityV = zzDashAbilityV ElseIf DashFX.GetValue() == 2 zzDashAbilityI = zzDashAbilityFireI zzDashAbilityII = zzDashAbilityFireII zzDashAbilityIII = zzDashAbilityFireIII zzDashAbilityIV = zzDashAbilityFireIV zzDashAbilityV = zzDashAbilityFireV ElseIf DashFX.GetValue() == 3 zzDashAbilityI = zzDashAbilityFrostI zzDashAbilityII = zzDashAbilityFrostII zzDashAbilityIII = zzDashAbilityFrostIII zzDashAbilityIV = zzDashAbilityFrostIV zzDashAbilityV = zzDashAbilityFrostV ElseIf DashFX.GetValue() == 4 zzDashAbilityI = zzDashAbilityShockI zzDashAbilityII = zzDashAbilityShockII zzDashAbilityIII = zzDashAbilityShockIII zzDashAbilityIV = zzDashAbilityShockIV zzDashAbilityV = zzDashAbilityShockV ElseIf DashFX.GetValue() == 5 zzDashAbilityI = zzDashAbilityDarkI zzDashAbilityII = zzDashAbilityDarkII zzDashAbilityIII = zzDashAbilityDarkIII zzDashAbilityIV = zzDashAbilityDarkIV zzDashAbilityV = zzDashAbilityDarkV EndIf EndFunction ;-------------------------------------------------------------------------------------------------------------------------------------------------------- ;--------- Functions ------------------------------------------------------------------------------------------------------------------------------------ ;-------------------------------------------------------------------------------------------------------------------------------------------------------- Function Restore() Game.SetGameSettingFloat("fJumpHeightMin", JumpHeight) Game.SetGameSettingFloat("fJumpMoveMult", JumpLength) Game.GetPlayer().ForceAV("speedmult", SpeedMult) Game.GetPlayer().RemoveSpell(zzDashAbilityI) Game.GetPlayer().RemoveSpell(zzDashAbilityII) Game.GetPlayer().RemoveSpell(zzDashAbilityIII) Game.GetPlayer().RemoveSpell(zzDashAbilityIV) Game.GetPlayer().RemoveSpell(zzDashAbilityV) Game.GetPlayer().AddPerk(zzDummyPerk) ; the speedmult setting refuses to take effect Game.GetPlayer().RemovePerk(zzDummyPerk) ; untill something odd happens. like this. RemoveFallProtection() EndFunction ;-------------------------------------------------------------------------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------------------------------------------------------------------------- Function RemoveFallProtection() Utility.Wait(FallDelay) Game.GetPlayer().RemovePerk(zzFallProtection) EndFunction ;-------------------------------------------------------------------------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------------------------------------------------------------------------- Function AddStage1() string RaceText1 = "[Race <ArgonianRace (00013740)>]" string RaceText2 = "[Race <BretonRace (00013741)>]" string RaceText3 = "[Race <DarkElfRace (00013742)>]" string RaceText4 = "[Race <HighElfRace (00013743)>]" string RaceText5 = "[Race <ImperialRace (00013744)>]" string RaceText6 = "[Race <KhajiitRace (00013745)>]" string RaceText7 = "[Race <NordRace (00013746)>]" string RaceText8 = "[Race <OrcRace (00013747)>]" string RaceText9 = "[Race <RedguardRace (00013748)>]" string RaceText10 = "[Race <WoodElfRace (00013749)>]" string RaceText11 = "[Race <ArgonianRaceVampire (0008883A)>]" string RaceText12 = "[Race <BretonRaceVampire (0008883C)>]" string RaceText13 = "[Race <DarkElfRaceVampire (0008883D)>]" string RaceText14 = "[Race <HighElfRaceVampire (00088840)>]" string RaceText15 = "[Race <ImperialRaceVampire (00088844)>]" string RaceText16 = "[Race <KhajiitRaceVampire (00088845)>]" string RaceText17 = "[Race <NordRaceVampire (00088794)>]" string RaceText18 = "[Race <OrcRaceVampire (000A82B9)>]" string RaceText19 = "[Race <RedguardRaceVampire (00088846)>]" string RaceText20 = "[Race <WoodElfRaceVampire (00088884)>]" ;Looks dumb right? That's why i'm asking if anyone knows a better way to write all vanilla race check magicka = Game.GetPlayer().GetAv("magicka") stamina = Game.GetPlayer().GetAv("stamina") If Stamina > DashCostStam.Getvalue() && Magicka > DashCostMag.Getvalue() Game.GetPlayer().DamageActorValue("Stamina", DashCostStam.Getvalue()) Game.GetPlayer().DamageActorValue("Magicka", DashCostMag.Getvalue()) If Game.GetPlayer().GetRace() != RaceText1 && Game.GetPlayer().GetRace() != RaceText6 &&Game.GetPlayer().GetRace() != RaceText9 && Game.GetPlayer().GetRace() != RaceText10 Game.SetGameSettingFloat("fJumpHeightMin", JumpHeight + Jump1) Game.SetGameSettingFloat("fJumpMoveMult", JumpLength + Length1) Game.GetPlayer().ForceAV("speedmult", SpeedMult + Speed1) EndIf Game.GetPlayer().AddSpell(zzDashAbilityI, false) Game.GetPlayer().AddPerk(zzDummyPerk) Game.GetPlayer().RemovePerk(zzDummyPerk) Game.GetPlayer().AddPerk(zzFallProtection) Else If Stamina < (DashCostStam.Getvalue()) Debug.Notification("You don't have the Strength..") endif If Magicka < (DashCostMag.Getvalue()) Debug.Notification("You don't have the Power..") endif int instanceID = FailFX.play(Game.GetPlayer()) EndIf EndFunction ;-------------------------------------------------------------------------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------------------------------------------------------------------------- Function AddStage2() magicka = Game.GetPlayer().GetAv("magicka") stamina = Game.GetPlayer().GetAv("stamina") If Stamina > (DashCostStam.Getvalue() * DashCostX2) && Magicka > (DashCostMag.Getvalue() * DashCostX2) Game.GetPlayer().DamageActorValue("Stamina", (DashCostStam.Getvalue() * DashCostX2)) Game.GetPlayer().DamageActorValue("Magicka", (DashCostMag.Getvalue() * DashCostX2)) Game.SetGameSettingFloat("fJumpHeightMin", JumpHeight + Jump2) Game.SetGameSettingFloat("fJumpMoveMult", JumpLength + Length2) Game.GetPlayer().ForceAV("speedmult", SpeedMult + Speed2) Game.GetPlayer().AddSpell(zzDashAbilityII, false) Game.GetPlayer().AddPerk(zzDummyPerk) Game.GetPlayer().RemovePerk(zzDummyPerk) Game.GetPlayer().AddPerk(zzFallProtection) Else If Stamina < (DashCostStam.Getvalue() * DashCostX2) Debug.Notification("You don't have the Strength..") endif If Magicka < (DashCostMag.Getvalue() * DashCostX2) Debug.Notification("You don't have the Power..") endif int instanceID = FailFX.play(Game.GetPlayer()) EndIf EndFunction ;-------------------------------------------------------------------------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------------------------------------------------------------------------- Function AddStage3() magicka = Game.GetPlayer().GetAv("magicka") stamina = Game.GetPlayer().GetAv("stamina") If Stamina > (DashCostStam.Getvalue() * DashCostX3) && Magicka > (DashCostMag.Getvalue() * DashCostX3) Game.GetPlayer().DamageActorValue("Stamina", (DashCostStam.Getvalue() * DashCostX3)) Game.GetPlayer().DamageActorValue("Magicka", (DashCostMag.Getvalue() * DashCostX3)) Game.SetGameSettingFloat("fJumpHeightMin", JumpHeight + Jump3) Game.SetGameSettingFloat("fJumpMoveMult", JumpLength + Length3) Game.GetPlayer().ForceAV("speedmult", SpeedMult + Speed3) Game.GetPlayer().AddSpell(zzDashAbilityIII, false) Game.GetPlayer().AddPerk(zzDummyPerk) Game.GetPlayer().RemovePerk(zzDummyPerk) Game.GetPlayer().AddPerk(zzFallProtection) Else If Stamina < (DashCostStam.Getvalue() * DashCostX3) Debug.Notification("You don't have the Strength..") endif If Magicka < (DashCostMag.Getvalue() * DashCostX3) Debug.Notification("You don't have the Power..") endif int instanceID = FailFX.play(Game.GetPlayer()) EndIf EndFunction ;-------------------------------------------------------------------------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------------------------------------------------------------------------- Function AddStage4() magicka = Game.GetPlayer().GetAv("magicka") stamina = Game.GetPlayer().GetAv("stamina") If Stamina > (DashCostStam.Getvalue() * DashCostX4) && Magicka > (DashCostMag.Getvalue() * DashCostX4) Game.GetPlayer().DamageActorValue("Stamina", (DashCostStam.Getvalue() * DashCostX4)) Game.GetPlayer().DamageActorValue("Magicka", (DashCostMag.Getvalue() * DashCostX4)) Game.SetGameSettingFloat("fJumpHeightMin", JumpHeight + Jump4) Game.SetGameSettingFloat("fJumpMoveMult", JumpLength + Length4) Game.GetPlayer().ForceAV("speedmult", SpeedMult + Speed4) Game.GetPlayer().AddSpell(zzDashAbilityIV, false) Game.GetPlayer().AddPerk(zzDummyPerk) Game.GetPlayer().RemovePerk(zzDummyPerk) Game.GetPlayer().AddPerk(zzFallProtection) Else If Stamina < (DashCostStam.Getvalue() * DashCostX4) Debug.Notification("You don't have the Strength..") endif If Magicka < (DashCostMag.Getvalue() * DashCostX4) Debug.Notification("You don't have the Power..") endif int instanceID = FailFX.play(Game.GetPlayer()) EndIf EndFunction ;-------------------------------------------------------------------------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------------------------------------------------------------------------- Function AddStage5() magicka = Game.GetPlayer().GetAv("magicka") stamina = Game.GetPlayer().GetAv("stamina") If Stamina > (DashCostStam.Getvalue() * DashCostX5) && Magicka > (DashCostMag.Getvalue() * DashCostX5) Game.GetPlayer().DamageActorValue("Stamina", (DashCostStam.Getvalue() * DashCostX5)) Game.GetPlayer().DamageActorValue("Magicka", (DashCostMag.Getvalue() * DashCostX5)) Game.SetGameSettingFloat("fJumpHeightMin", JumpHeight + Jump5) Game.SetGameSettingFloat("fJumpMoveMult", JumpLength + Length5) Game.GetPlayer().ForceAV("speedmult", SpeedMult + Speed5) Game.GetPlayer().AddSpell(zzDashAbilityV, false) Game.GetPlayer().AddPerk(zzDummyPerk) Game.GetPlayer().RemovePerk(zzDummyPerk) Game.GetPlayer().AddPerk(zzFallProtection) Else If Stamina < (DashCostStam.Getvalue() * DashCostX5) Debug.Notification("You don't have the Strength..") endif If Magicka < (DashCostMag.Getvalue() * DashCostX5) Debug.Notification("You don't have the Power..") endif int instanceID = FailFX.play(Game.GetPlayer()) EndIf EndFunction ;-------------------------------------------------------------------------------------------------------------------------------------------------------- ;--------- Events --------------------------------------------------------------------------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------------------------------------------------------------------------------------------- Event OnEffectStart (Actor akTarget, Actor akCaster) GetSettings() EndEvent ;--------------------------------------------------------------------------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------------------------------------------------------------------------- Event OnKeyDown(Int Keycode) ItsOn = 1 RegisterForSingleUpdate(0.00) EndEvent ;--------------------------------------------------------------------------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------------------------------------------------------------------------- Event OnKeyUp(Int Keycode, Float HoldTime) ItsOn = 0 EndEvent ;---------------------------------------------------------------------------------------------------------------------------------------------------------------------- ;---------------------------------------------------------------------------------------------------------------------------------------------------------------------- Event OnUpdate() If Game.GetPlayer().HasPerk(zzFallProtection) == 0 ;--------- Sprinter OFF --------------------------------------------------------------------------------------------------------------------------------------------- If DashActive.GetValue() == 0 ;--------- Trigger Charger -------------------------------------------------------------------------------------------------------------------------------------- Utility.Wait(HoldTimer) ;--------- Stage 1 Ramp Up ---------------------------------------------------------------------------------------------------------------------------------- If ItsOn == 1 && Game.GetPlayer().IsRunning() == 0 && Game.GetPlayer().IsSprinting() == 0 || ItsOn == 1 && Game.GetPlayer().IsSneaking() == 1 AddStage1() Utility.Wait(Delay1) ;--------- Stage 2 Ramp Up ------------------------------------------------------------------------------------------------------------------------------- If ItsOn == 1 && Game.GetPlayer().IsRunning() == 0 && Game.GetPlayer().IsSprinting() == 0 || ItsOn == 1 && Game.GetPlayer().IsSneaking() == 1 AddStage2() Utility.Wait(Delay2) ;--------- Stage 3 Ramp Up --------------------------------------------------------------------------------------------------------------------------- If ItsOn == 1 && Game.GetPlayer().IsRunning() == 0 && Game.GetPlayer().IsSprinting() == 0 || ItsOn == 1 && Game.GetPlayer().IsSneaking() == 1 AddStage3() Utility.Wait(Delay3) ;--------- Stage 4 Ramp Up --------------------------------------------------------------------------------------------------------------------------- If ItsOn == 1 && Game.GetPlayer().IsRunning() == 0 && Game.GetPlayer().IsSprinting() == 0 || ItsOn == 1 && Game.GetPlayer().IsSneaking() == 1 AddStage4() Utility.Wait(Delay4) ;--------- Stage 5 Ramp Up --------------------------------------------------------------------------------------------------------------------------- If ItsOn == 1 && Game.GetPlayer().IsRunning() == 0 && Game.GetPlayer().IsSprinting() == 0 || ItsOn == 1 && Game.GetPlayer().IsSneaking() == 1 AddStage5() Utility.Wait(EffectTimer) Restore() ;--------- (key released before 5) ------------------------------------------------------------------------------------------------------------------- Else Utility.Wait(EffectTimer - Delay4) Restore() EndIf ;--------- (key released before 4) ------------------------------------------------------------------------------------------------------------------- Else Utility.Wait(EffectTimer - Delay3) Restore() EndIf ;--------- (key released before 3) ------------------------------------------------------------------------------------------------------------------- Else Utility.Wait(EffectTimer - Delay2) Restore() EndIf ;--------- (Key was released before 2) -------------------------------------------------------------------------------------------------------------------- Else Utility.Wait(EffectTimer - Delay1) Restore() EndIf ;--------- (Key was released before 1?) ----------------------------------------------------------------------------------------------------------------------- EndIf ;--------- Sprinter ON ------------------------------------------------------------------------------------------------------------------------------------------------ ElseIf DashActive.GetValue() == 1 ;--------- Trigger Charger ---------------------------------------------------------------------------------------------------------------------------------------- Utility.Wait(HoldTimer) ;--------- Stage 1 Ramp Up ------------------------------------------------------------------------------------------------------------------------------------- If ItsOn == 1 || ItsOn == 1 && Game.GetPlayer().IsSneaking() == 1 AddStage1() Utility.Wait(Delay1) ;--------- Stage 2 Ramp Up --------------------------------------------------------------------------------------------------------------------------------- If ItsOn == 1 || ItsOn == 1 && Game.GetPlayer().IsSneaking() == 1 AddStage2() Utility.Wait(Delay2) ;--------- Stage 3 Ramp Up ------------------------------------------------------------------------------------------------------------------------------ If ItsOn == 1 || ItsOn == 1 && Game.GetPlayer().IsSneaking() == 1 AddStage3() Utility.Wait(Delay3) ;--------- Stage 4 Ramp Up --------------------------------------------------------------------------------------------------------------------------------- If ItsOn == 1 || ItsOn == 1 && Game.GetPlayer().IsSneaking() == 1 AddStage4() Utility.Wait(Delay4) ;--------- Stage 5 Ramp Up --------------------------------------------------------------------------------------------------------------------------------- If ItsOn == 1 || ItsOn == 1 && Game.GetPlayer().IsSneaking() == 1 AddStage4() Utility.Wait(EffectTimer) Restore() ;--------- (key released before 5) ----------------------------------------------------------------------------------------------------------------------- Else Utility.Wait(EffectTimer - Delay4) Restore() EndIf ;--------- (key released before 4) ----------------------------------------------------------------------------------------------------------------------- Else Utility.Wait(EffectTimer - Delay3) Restore() EndIf ;--------- (key released before 3) ----------------------------------------------------------------------------------------------------------------------- Else Utility.Wait(EffectTimer - Delay2) Restore() EndIf ;--------- (Key was released before 2) ------------------------------------------------------------------------------------------------------------------ Else Utility.Wait(EffectTimer - Delay1) Restore() EndIf ;--------- (Key was released before 1) --------------------------------------------------------------------------------------------------------------------- EndIf EndIf ;-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ElseIf Game.GetPlayer().HasPerk(zzFallProtection) == 1 RegisterForSingleUpdate(1.00) ;keep holding.. come back.. EndIf EndEvent ;---------------------------------------------------------------------------------------------------------------------------------------------------------------- ;--------- unequipped ----------------------------------------------------------------------------------------------------------------------------------- Event OnEffectFinish (Actor akTarget, Actor akCaster) UnRegisterForKey(SneakKey) UnRegisterForKey(SprintKey) EndEvent ;-------------------------------------------------------------------------------------------------------------------------------------------------------- ;--------- snuffed it, bummer. -------------------------------------------------------------------------------------------------------------------------- Event OnDying (Actor akKiller) Restore() UnRegisterForKey(SneakKey) UnRegisterForKey(SprintKey) EndEvent ;-------------------------------------------------------------------------------------------------------------------------------------------------------- Edited January 3, 2019 by qwertypol012 Link to comment Share on other sites More sharing options...
IsharaMeradin Posted January 2, 2019 Share Posted January 2, 2019 Use properties for the races. Property declaration would be like this: Race Property NordRace Auto Race Property BretonRace Auto ; etc...Usage within a function or event would be like this: If Game.GetPlayer().GetRace() == NordRace ;do something for nords ElseIf Game.GetPlayer().GetRace() == BretonRace ;do something for bretons EndIfTIP: You can eliminate multiple calls to the Game script for the player data by storing the player data within a variable. You can do a property or local variable. Examples Actor Property PlayerRef Auto ;will auto fill with the player Actor PlayerRef Event OnEffectStart(Actor akTarget, Actor akCaster) PlayerRef = Game.GetPlayer() EndEventIn both scenarios, you can replace future uses of Game.GetPlayer() with PlayerRef. This will speed up your script by eliminating the need to pause the script and wait while the thread jumps to the Game script to get the player info. Link to comment Share on other sites More sharing options...
ReDragon2013 Posted January 3, 2019 Share Posted January 3, 2019 (edited) 1) If you use SKSE functions or events make sure your script handles that right.2) Do not call the same method over and over for comparing. Store the result in a local variable and compare that instead.3) Use functions to split your code, it's better to read and easier to maintain BerserkerJumpEffectScript Scriptname BerserkerJumpEffectScript extends ActiveMagicEffect {Depending on players baseValue 'stamina', it sets fJumpHeightMin, fJumpMoveMult and fJumpFallHeightMin to higher values if you are wearing berserker boots, or sets them back to default if you are normal} ; https://forums.nexusmods.com/index.php?/topic/7276666-how-to-make-a-script-to-activate-an-effect-by-holding-a-specific-key/ Armor PROPERTY ArmorBerserkerWBoots2 auto Float[] DefaultJumpArray ; -- EVENTs -- 2 EVENT OnEffectStart(Actor akTarget, Actor akCaster) IF (akTarget == Game.GetPlayer()) ELSE gotoState("Done") ; ### STATE ### Debug.Trace("OnEffectStart() - dispel effect for target " +akTarget) self.Dispel() RETURN ; - STOP - not the player, failsafe ENDIF ;--------------------- ;;; myF_InitArray() myF_Action(akTarget) ENDEVENT EVENT OnEffectFinish(Actor akTarget, Actor akCaster) myF_Reset() ENDEVENT ;=============================== state Done ;========= EVENT OnEffectFinish(Actor akTarget, Actor akCaster) ; do not reset game settings ENDEVENT ;======= endState ; -- FUNCTIONs -- 1 + 3 ;;----------------------- ;FUNCTION myF_InitArray() ;;----------------------- ; DefaultJumpArray = new Float[3] ; DefaultJumpArray[0] = Game.GetGameSettingFloat("fJumpHeightMin") ; DefaultJumpArray[1] = Game.GetGameSettingFloat("fJumpMoveMult") ; DefaultJumpArray[2] = Game.GetGameSettingFloat("fJumpFallHeightMin") ;ENDFUNCTION ;------------------- FUNCTION myF_Reset() ;------------------- IF (DefaultJumpArray.Length > 0) Game.SetGameSettingFloat("fJumpHeightMin", DefaultJumpArray[0]) Game.SetGameSettingFloat("fJumpMoveMult", DefaultJumpArray[1]) Game.SetGameSettingFloat("fJumpFallHeightMin", DefaultJumpArray[2]) ELSE Game.SetGameSettingFloat("fJumpHeightMin", 76.0) Game.SetGameSettingFloat("fJumpMoveMult", 0.3) Game.SetGameSettingFloat("fJumpFallHeightMin", 600.0) ENDIF ENDFUNCTION ;------------------------------------------------- FUNCTION myF_TryToSet(Float fH, Float fM, Float f) ; internal helper for better overview and shrinking code size ;------------------------------------------------- IF (Game.GetGameSettingFloat("fJumpHeightMin") == 76.0) Game.SetGameSettingFloat("fJumpHeightMin", fH) ENDIF IF (Game.GetGameSettingFloat("fJumpMoveMult") == 0.3) Game.SetGameSettingFloat("fJumpMoveMult", fM) ENDIF IF (Game.GetGameSettingFloat("fJumpFallHeightMin") == 600.0) Game.SetGameSettingFloat("fJumpFallHeightMin", f) ENDIF ENDFUNCTION ;-------------------------------- FUNCTION myF_Action(Actor player) ;-------------------------------- int i = player.GetBaseActorValue("Stamina") IF (i < 80) myF_Reset() RETURN ; - STOP - players base stamina is too low ENDIF ;--------------------- bool bOK = player.IsEquipped(ArmorBerserkerWBoots2) ; TRUE = player has equipped, False = player does not have equipped IF (i < 160) IF ( bOK ) myF_TryToSet(114.0, 0.45, 750.0) ELSE myF_Reset() ENDIF RETURN ; - STOP - ENDIF ;--------------------- IF (i < 240) IF ( bOK ) myF_TryToSet(152.0, 0.60, 900.0) ELSE myF_Reset() ENDIF RETURN ; - STOP - ENDIF ;--------------------- IF (i < 320) IF ( bOK ) myF_TryToSet(190.0, 0.75, 1050.0) ELSE myF_Reset() ENDIF RETURN ; - STOP - ENDIF ;--------------------- IF (i < 400) IF ( bOK ) myF_TryToSet(228.0, 0.90, 1200.0) ELSE myF_Reset() ENDIF RETURN ; - STOP - ENDIF ;--------------------- IF (i < 480) IF ( bOK ) myF_TryToSet(266.0, 1.05, 1350.0) ELSE myF_Reset() ENDIF RETURN ; - STOP - ENDIF ;--------------------- IF (i < 560) IF ( bOK ) myF_TryToSet(304.0, 1.20, 1500.0) ELSE myF_Reset() ENDIF RETURN ; - STOP - ENDIF ;--------------------- IF (i < 640) IF ( bOK ) myF_TryToSet(342.0, 1.35, 1650.0) ELSE myF_Reset() ENDIF ENDIF ENDFUNCTION BerserkerDashEffectScript Scriptname BerserkerDashEffectScript extends ActiveMagicEffect {attached to magic effect, used in enchantment, this decides which effect to add} ; https://forums.nexusmods.com/index.php?/topic/7276666-how-to-make-a-script-to-activate-an-effect-by-holding-a-specific-key/ ;qwertypol012 wrote: "I am currently trying to make a script about using a "hold key" feature to activate an effect." ; "Did not put the properties here to keep it shorter" ; -- EVENTs -- 6 EVENT OnEffectStart(Actor akTarget, Actor akCaster) GetSettings() ENDEVENT EVENT OnEffectFinish(Actor akTarget, Actor akCaster) ; unequipped IF (SKSE.GetVersionRelease() as Bool) UnRegisterForKey(SneakKey) UnRegisterForKey(SprintKey) ENDIF ENDEVENT EVENT OnDying(Actor akKiller) ; snuffed it, bummer. IF (SKSE.GetVersionRelease() as Bool) UnRegisterForKey(SneakKey) UnRegisterForKey(SprintKey) ENDIF Restore(0.0) ENDEVENT EVENT OnKeyUp(Int Keycode, Float HoldTime) ; SKSE required ItsOn = 0 ENDEVENT EVENT OnKeyDown(Int Keycode) ; SKSE required UnRegisterForUpdate() ItsOn = 1 RegisterForSingleUpdate(0.0) ENDEVENT EVENT OnUpdate() ; https://www.creationkit.com/index.php?title=HasPerk_-_Actor IF Game.GetPlayer().HasPerk(zzFallProtection) RegisterForSingleUpdate(1.0) ; keep holding.. come back.. RETURN ; - STOP - player has the perk ENDIF ;--------------------- Utility.Wait(HoldTimer) IF ( DashActive ) IF (DashActive.GetValue() as Bool) ; (DashActive.GetValue() == 1) myF_ON() ELSE myF_OFF() ; (DashActive.GetValue() == 0) ENDIF ENDIF ENDEVENT ; -- FUNCTIONs -- 12 ;------------------------ FUNCTION Restore(Float f) ;------------------------ IF (f < 0.0) f = 0.0 ; set to min time, safety first ELSEIF (f > EffectTimer) f = EffectTimer ; set to max time ENDIF Utility.Wait(f) actor player = Game.GetPlayer() player.RemoveSpell(zzDashAbilityI) player.RemoveSpell(zzDashAbilityII) player.RemoveSpell(zzDashAbilityIII) player.RemoveSpell(zzDashAbilityIV) player.RemoveSpell(zzDashAbilityV) Game.SetGameSettingFloat("fJumpHeightMin", JumpHeight) Game.SetGameSettingFloat("fJumpMoveMult", JumpLength) player.ForceActorValue("speedmult", SpeedMult) player.AddPerk(zzDummyPerk) ; the speedmult setting refuses to take effect player.RemovePerk(zzDummyPerk) ; untill something odd happens. like this. ;;; RemoveFallProtection() Utility.Wait(FallDelay) player.RemovePerk(zzFallProtection) ENDFUNCTION ;---------------- FUNCTION myF_ON() ;---------------- actor player = Game.GetPlayer() IF (ItsOn == 1) || player.IsSneaking() ; *** Stage 1 *** ELSE RETURN ; - STOP - Key released before 1 ENDIF ;--------------------- AddStage1() Utility.Wait(Delay1) ; ( 1 ) IF (ItsOn == 1) || player.IsSneaking() ; *** Stage 2 *** ELSE Restore(EffectTimer - Delay1) RETURN ; - STOP - Key released before 2 ENDIF ;--------------------- AddStage2() Utility.Wait(Delay2) ; ( 2 ) IF (ItsOn == 1) || player.IsSneaking() ; *** Stage 3 *** ELSE Restore(EffectTimer - Delay2) RETURN ; - STOP - Key released before 3 ENDIF ;--------------------- AddStage3() Utility.Wait(Delay3) ; ( 3 ) IF (ItsOn == 1) || player.IsSneaking() ; *** Stage 4 *** ELSE Restore(EffectTimer - Delay3) RETURN ; - STOP - Key released before 4 ENDIF ;--------------------- AddStage4() Utility.Wait(Delay4) ; ( 4 ) IF (ItsOn == 1) || player.IsSneaking() ; *** Stage 5 *** ELSE Restore(EffectTimer - Delay4) RETURN ; - STOP - Key released before 5 ENDIF ;--------------------- AddStage5() ; ( 5 ) ; <-- original: AddStage4() Restore(EffectTimer) ENDFUNCTION ;----------------------------- Bool FUNCTION myF_IsPlayerOK() ; internal helper ;----------------------------- actor player = Game.GetPlayer() IF player.IsSneaking() Return TRUE ; player is sneaking ENDIF ;--------- IF player.IsRunning() Return False ; running not allowed ENDIF ;--------- IF player.IsSprinting() Return False ; sprinting not allowed ENDIF ;--------- Return TRUE ; player is whether running nor sprinting ENDFUNCTION ;----------------- FUNCTION myF_OFF() ;----------------- ;;; actor player = Game.GetPlayer() ;;; IF (ItsOn == 1) && ( player.IsSneaking() || (!player.IsRunning() && !player.IsSprinting()) ) IF myF_IsPlayerOK() && (ItsOn == 1) ; *** Stage 1 *** ELSE RETURN ; - STOP - Key released before 1 ENDIF ;--------------------- AddStage1() Utility.Wait(Delay1) ; ( 1 ) IF myF_IsPlayerOK() && (ItsOn == 1) ; *** Stage 2 *** ELSE Restore(EffectTimer - Delay1) RETURN ; - STOP - Key released before 2 ENDIF ;--------------------- AddStage2() Utility.Wait(Delay2) ; ( 2 ) IF myF_IsPlayerOK() && (ItsOn == 1) ; *** Stage 3 *** ELSE Restore(EffectTimer - Delay2) RETURN ; - STOP - Key released before 3 ENDIF ;--------------------- AddStage3() Utility.Wait(Delay3) ; ( 3 ) IF myF_IsPlayerOK() && (ItsOn == 1) ; *** Stage 4 *** ELSE Restore(EffectTimer - Delay3) RETURN ; - STOP - Key released before 4 ENDIF ;--------------------- AddStage4() Utility.Wait(Delay4) ; ( 4 ) IF myF_IsPlayerOK() && (ItsOn == 1) ; *** Stage 5 *** ELSE Restore(EffectTimer - Delay4) RETURN ; - STOP - Key released before 5 ENDIF ;--------------------- AddStage5() ; ( 5 ) Restore(EffectTimer) ENDFUNCTION ;--------------------- FUNCTION GetSettings() ;--------------------- JumpHeight = DashStoreJump.GetValue() JumpLength = DashStoreLength.GetValue() SpeedMult = DashStoreSpeed.GetValue() HoldTimer = DashTimerHold.GetValue() Delay1 = DashTimerDelay1.GetValue() Delay2 = DashTimerDelay2.GetValue() Delay3 = DashTimerDelay3.GetValue() Delay4 = DashTimerDelay4.GetValue() EffectTimer = DashTimerEffect.GetValue() FallDelay = DashTimerFall.GetValue() Jump1 = DashJump1.GetValue() Speed1 = DashSpeed1.GetValue() Length1 = DashLength1.GetValue() Jump2 = DashJump2.GetValue() Speed2 = DashSpeed2.GetValue() Length2 = DashLength2.GetValue() Jump3 = DashJump3.GetValue() Speed3 = DashSpeed3.GetValue() Length3 = DashLength3.GetValue() Jump4 = DashJump4.GetValue() Speed4 = DashSpeed4.GetValue() Length4 = DashLength4.GetValue() Jump5 = DashJump5.GetValue() Speed5 = DashSpeed5.GetValue() Length5 = DashLength5.GetValue() DashCostX2 = DashCostMult2.GetValue() DashCostX3 = DashCostMult3.GetValue() DashCostX4 = DashCostMult4.GetValue() DashCostX5 = DashCostMult5.GetValue() ;------------------------------------------- SneakKey = Input.GetMappedKey("Sneak") RegisterForKey(SneakKey) SprintKey = Input.GetMappedKey("Sprint") RegisterForKey(SprintKey) ;------------------------------------------- int i = DashFX.GetValueInt() IF (i == 1) ; normal zzDashAbilityI = zzDashAbilityI zzDashAbilityII = zzDashAbilityII zzDashAbilityIII = zzDashAbilityIII zzDashAbilityIV = zzDashAbilityIV zzDashAbilityV = zzDashAbilityV RETURN ; - STOP - ENDIF ;--------------------- IF (i == 2) ; fire zzDashAbilityI = zzDashAbilityFireI zzDashAbilityII = zzDashAbilityFireII zzDashAbilityIII = zzDashAbilityFireIII zzDashAbilityIV = zzDashAbilityFireIV zzDashAbilityV = zzDashAbilityFireV RETURN ; - STOP - ENDIF ;--------------------- IF (i == 3) ; frost zzDashAbilityI = zzDashAbilityFrostI zzDashAbilityII = zzDashAbilityFrostII zzDashAbilityIII = zzDashAbilityFrostIII zzDashAbilityIV = zzDashAbilityFrostIV zzDashAbilityV = zzDashAbilityFrostV RETURN ; - STOP - ENDIF ;--------------------- IF (i == 4) ; shock zzDashAbilityI = zzDashAbilityShockI zzDashAbilityII = zzDashAbilityShockII zzDashAbilityIII = zzDashAbilityShockIII zzDashAbilityIV = zzDashAbilityShockIV zzDashAbilityV = zzDashAbilityShockV RETURN ; - STOP - ENDIF ;--------------------- IF (i == 5) ; dark zzDashAbilityI = zzDashAbilityDarkI zzDashAbilityII = zzDashAbilityDarkII zzDashAbilityIII = zzDashAbilityDarkIII zzDashAbilityIV = zzDashAbilityDarkIV zzDashAbilityV = zzDashAbilityDarkV RETURN ; - STOP - ENDIF ;--------------------- ;IF (i == 0) ; blank zzDashAbilityI = zzDashAbilityBlankI zzDashAbilityII = zzDashAbilityBlankII zzDashAbilityIII = zzDashAbilityBlankIII zzDashAbilityIV = zzDashAbilityBlankIV zzDashAbilityV = zzDashAbilityBlankV ;ENDIF ENDFUNCTION ;----------------------- FUNCTION myF_Fail(Int i) ; internal helper ;----------------------- objectReference playerRef = Game.GetPlayer() as ObjectReference IF (i == 1) Debug.Notification("You don't have the Strength..") FailFX.Play(playerRef) ELSE Debug.Notification("You don't have the Power..") FailFX.Play(playerRef) ENDIF ENDFUNCTION ;------------------- FUNCTION AddStage1() ;------------------- actor player = Game.GetPlayer() float fs = DashCostStam.GetValue() IF (player.GetActorValue("stamina") < fs) ; stamina = Game.GetPlayer().GetAv("stamina") myF_Fail(1) RETURN ; - STOP - ENDIF ;--------------------- float fm = DashCostMag.Getvalue() IF (player.GetActorValue("magicka") < fm) ; magicka = Game.GetPlayer().GetAv("magicka") myyF_Fail(2) RETURN ; - STOP - ENDIF ;--------------------- player.DamageActorValue("Stamina", fs) player.DamageActorValue("Magicka", fm) player.AddSpell(zzDashAbilityI, False) myF_Perks(player, Jump1, Length1, Speed1) ENDFUNCTION ;------------------- FUNCTION AddStage2() ;------------------- actor player = Game.GetPlayer() float fs = DashCostStam.GetValue() * DashCostX2 IF (player.GetActorValue("stamina") < fs) myF_Fail(1) RETURN ; - STOP - ENDIF ;--------------------- float fm = DashCostMag.Getvalue() * DashCostX2 IF (player.GetActorValue("magicka") < fm) myyF_Fail(2) RETURN ; - STOP - ENDIF ;--------------------- player.DamageActorValue("Stamina", fs) player.DamageActorValue("Magicka", fm) player.AddSpell(zzDashAbilityII, False) myF_Perks(player, Jump2, Length2, Speed2) ENDFUNCTION ;------------------- FUNCTION AddStage3() ;------------------- actor player = Game.GetPlayer() float fs = DashCostStam.GetValue() * DashCostX3 IF (player.GetActorValue("stamina") < fs) myF_Fail(1) RETURN ; - STOP - ENDIF ;--------------------- float fm = DashCostMag.Getvalue() * DashCostX3 IF (player.GetActorValue("magicka") < fm) myF_Fail(2) RETURN ; - STOP - ENDIF ;--------------------- player.DamageActorValue("Stamina", fs) player.DamageActorValue("Magicka", fm) player.AddSpell(zzDashAbilityIII, False) myF_Perks(player, Jump3, Length3, Speed3) ENDFUNCTION ;------------------- FUNCTION AddStage4() ;------------------- actor player = Game.GetPlayer() float fs = DashCostStam.GetValue() * DashCostX4 IF (player.GetActorValue("stamina") < fs) myF_Fail(1) RETURN ; - STOP - ENDIF ;--------------------- float fm = DashCostMag.Getvalue() * DashCostX4 IF (player.GetActorValue("magicka") < fm) myF_Fail(2) RETURN ; - STOP - ENDIF ;--------------------- player.DamageActorValue("Stamina", fs) player.DamageActorValue("Magicka", fm) player.AddSpell(zzDashAbilityIV, False) myF_Perks(player, Jump4, Length4, Speed4) ENDFUNCTION ;------------------- FUNCTION AddStage5() ;------------------- actor player = Game.GetPlayer() float fs = DashCostStam.GetValue() * DashCostX5 IF (player.GetActorValue("stamina") < fs) myF_Fail(1) RETURN ; - STOP - ENDIF ;--------------------- float fm = DashCostMag.Getvalue() * DashCostX5 IF (player.GetActorValue("magicka") < fm) myF_Fail(2) RETURN ; - STOP - ENDIF ;--------------------- player.DamageActorValue("Stamina", fs) player.DamageActorValue("Magicka", fm) player.AddSpell(zzDashAbilityV, False) myF_Perks(player, Jump5, Length5, Speed5) ENDFUNCTION ;------------------------------------------------------------- FUNCTION myF_Perks(Actor player, Float fJ, Float fL, Float fS) ; internal helper ;------------------------------------------------------------- int i = player.GetRace().GetFormID() IF (i == 0x00013740) ; ArgonianRace ELSEIF (i == 0x00013745) ; KhajiitRace ELSEIF (i == 0x00013748) ; RedguardRace ELSEIF (i == 0x00013749) ; WoodElfRace ELSE Game.SetGameSettingFloat("fJumpHeightMin", JumpHeight + fJ) Game.SetGameSettingFloat("fJumpMoveMult", JumpLength + fL) player.ForceActorValue("speedmult", SpeedMult + fS) player.AddPerk(zzDummyPerk) player.RemovePerk(zzDummyPerk) ENDIF ;;; Utility.Wait(0.1) player.AddPerk(zzFallProtection) ENDFUNCTION ; Looks dumb right? That's why i'm asking if anyone knows a better way to write all vanilla race check ; ; string RaceText1 = "[Race <ArgonianRace (00013740)>]" ; string RaceText2 = "[Race <BretonRace (00013741)>]" ; string RaceText3 = "[Race <DarkElfRace (00013742)>]" ; string RaceText4 = "[Race <HighElfRace (00013743)>]" ; string RaceText5 = "[Race <ImperialRace (00013744)>]" ; string RaceText6 = "[Race <KhajiitRace (00013745)>]" ; string RaceText7 = "[Race <NordRace (00013746)>]" ; string RaceText8 = "[Race <OrcRace (00013747)>]" ; string RaceText9 = "[Race <RedguardRace (00013748)>]" ; string RaceText10 = "[Race <WoodElfRace (00013749)>]" ; string RaceText11 = "[Race <ArgonianRaceVampire (0008883A)>]" ; string RaceText12 = "[Race <BretonRaceVampire (0008883C)>]" ; string RaceText13 = "[Race <DarkElfRaceVampire (0008883D)>]" ; string RaceText14 = "[Race <HighElfRaceVampire (00088840)>]" ; string RaceText15 = "[Race <ImperialRaceVampire (00088844)>]" ; string RaceText16 = "[Race <KhajiitRaceVampire (00088845)>]" ; string RaceText17 = "[Race <NordRaceVampire (00088794)>]" ; string RaceText18 = "[Race <OrcRaceVampire (000A82B9)>]" ; string RaceText19 = "[Race <RedguardRaceVampire (00088846)>]" ; string RaceText20 = "[Race <WoodElfRaceVampire (00088884)>]" Edited January 3, 2019 by ReDragon2013 Link to comment Share on other sites More sharing options...
ReDragon2013 Posted January 3, 2019 Share Posted January 3, 2019 (edited) to make your script code invisible on this forum, use the spoiler tags in brakets (without spaces) like html code style[ spoiler ] Scriptname xyz_Script extends Quest[ /spoiler ] Scriptname xyz_Script extends Quest Edited January 3, 2019 by ReDragon2013 Link to comment Share on other sites More sharing options...
qwertypol012 Posted January 3, 2019 Author Share Posted January 3, 2019 (edited) Finally! Thank you very much for the replies!!! This is amazing! :DUse properties for the races. Property declaration would be like this: Race Property NordRace Auto Race Property BretonRace Auto ; etc...Usage within a function or event would be like this: If Game.GetPlayer().GetRace() == NordRace ;do something for nords ElseIf Game.GetPlayer().GetRace() == BretonRace ;do something for bretons EndIfTIP: You can eliminate multiple calls to the Game script for the player data by storing the player data within a variable. You can do a property or local variable. Examples Actor Property PlayerRef Auto ;will auto fill with the player Actor PlayerRef Event OnEffectStart(Actor akTarget, Actor akCaster) PlayerRef = Game.GetPlayer() EndEventIn both scenarios, you can replace future uses of Game.GetPlayer() with PlayerRef. This will speed up your script by eliminating the need to pause the script and wait while the thread jumps to the Game script to get the player info. Thanks for the reply! Never thought that we can simply use properties for races (that's actually possible, right) :sweat:Also, thanks for the tip for optimizing the script. Never know how to optimize codes in script, simply because i learnt it self-taught with no structured materials :tongue:Once again, thanks for the optimizing tip. This should be very useful for me if i want to make more scripts in the future :smile: to make your script code invisible on this forum, use the spoiler tags in brakets (without spaces) like html code style[ spoiler ] Scriptname xyz_Script extends Quest[ /spoiler ] Scriptname xyz_Script extends Quest Thanks for the tip. I've actually tried to use spoiler tags, but it didn't work because i wrote it wrong. Now it works. :smile: Edited January 3, 2019 by qwertypol012 Link to comment Share on other sites More sharing options...
qwertypol012 Posted January 3, 2019 Author Share Posted January 3, 2019 (edited) 1) If you use SKSE functions or events make sure your script handles that right.2) Do not call the same method over and over for comparing. Store the result in a local variable and compare that instead.3) Use functions to split your code, it's better to read and easier to maintain BerserkerJumpEffectScript Scriptname BerserkerJumpEffectScript extends ActiveMagicEffect {Depending on players baseValue 'stamina', it sets fJumpHeightMin, fJumpMoveMult and fJumpFallHeightMin to higher values if you are wearing berserker boots, or sets them back to default if you are normal} ; https://forums.nexusmods.com/index.php?/topic/7276666-how-to-make-a-script-to-activate-an-effect-by-holding-a-specific-key/ Armor PROPERTY ArmorBerserkerWBoots2 auto Float[] DefaultJumpArray ; -- EVENTs -- 2 EVENT OnEffectStart(Actor akTarget, Actor akCaster) IF (akTarget == Game.GetPlayer()) ELSE gotoState("Done") ; ### STATE ### Debug.Trace("OnEffectStart() - dispel effect for target " +akTarget) self.Dispel() RETURN ; - STOP - not the player, failsafe ENDIF ;--------------------- ;;; myF_InitArray() myF_Action(akTarget) ENDEVENT EVENT OnEffectFinish(Actor akTarget, Actor akCaster) myF_Reset() ENDEVENT ;=============================== state Done ;========= EVENT OnEffectFinish(Actor akTarget, Actor akCaster) ; do not reset game settings ENDEVENT ;======= endState ; -- FUNCTIONs -- 1 + 3 ;;----------------------- ;FUNCTION myF_InitArray() ;;----------------------- ; DefaultJumpArray = new Float[3] ; DefaultJumpArray[0] = Game.GetGameSettingFloat("fJumpHeightMin") ; DefaultJumpArray[1] = Game.GetGameSettingFloat("fJumpMoveMult") ; DefaultJumpArray[2] = Game.GetGameSettingFloat("fJumpFallHeightMin") ;ENDFUNCTION ;------------------- FUNCTION myF_Reset() ;------------------- IF (DefaultJumpArray.Length > 0) Game.SetGameSettingFloat("fJumpHeightMin", DefaultJumpArray[0]) Game.SetGameSettingFloat("fJumpMoveMult", DefaultJumpArray[1]) Game.SetGameSettingFloat("fJumpFallHeightMin", DefaultJumpArray[2]) ELSE Game.SetGameSettingFloat("fJumpHeightMin", 76.0) Game.SetGameSettingFloat("fJumpMoveMult", 0.3) Game.SetGameSettingFloat("fJumpFallHeightMin", 600.0) ENDIF ENDFUNCTION ;------------------------------------------------- FUNCTION myF_TryToSet(Float fH, Float fM, Float f) ; internal helper for better overview and shrinking code size ;------------------------------------------------- IF (Game.GetGameSettingFloat("fJumpHeightMin") == 76.0) Game.SetGameSettingFloat("fJumpHeightMin", fH) ENDIF IF (Game.GetGameSettingFloat("fJumpMoveMult") == 0.3) Game.SetGameSettingFloat("fJumpMoveMult", fM) ENDIF IF (Game.GetGameSettingFloat("fJumpFallHeightMin") == 600.0) Game.SetGameSettingFloat("fJumpFallHeightMin", f) ENDIF ENDFUNCTION ;-------------------------------- FUNCTION myF_Action(Actor player) ;-------------------------------- int i = player.GetBaseActorValue("Stamina") IF (i < 80) myF_Reset() RETURN ; - STOP - players base stamina is too low ENDIF ;--------------------- bool bOK = player.IsEquipped(ArmorBerserkerWBoots2) ; TRUE = player has equipped, False = player does not have equipped IF (i < 160) IF ( bOK ) myF_TryToSet(114.0, 0.45, 750.0) ELSE myF_Reset() ENDIF RETURN ; - STOP - ENDIF ;--------------------- IF (i < 240) IF ( bOK ) myF_TryToSet(152.0, 0.60, 900.0) ELSE myF_Reset() ENDIF RETURN ; - STOP - ENDIF ;--------------------- IF (i < 320) IF ( bOK ) myF_TryToSet(190.0, 0.75, 1050.0) ELSE myF_Reset() ENDIF RETURN ; - STOP - ENDIF ;--------------------- IF (i < 400) IF ( bOK ) myF_TryToSet(228.0, 0.90, 1200.0) ELSE myF_Reset() ENDIF RETURN ; - STOP - ENDIF ;--------------------- IF (i < 480) IF ( bOK ) myF_TryToSet(266.0, 1.05, 1350.0) ELSE myF_Reset() ENDIF RETURN ; - STOP - ENDIF ;--------------------- IF (i < 560) IF ( bOK ) myF_TryToSet(304.0, 1.20, 1500.0) ELSE myF_Reset() ENDIF RETURN ; - STOP - ENDIF ;--------------------- IF (i < 640) IF ( bOK ) myF_TryToSet(342.0, 1.35, 1650.0) ELSE myF_Reset() ENDIF ENDIF ENDFUNCTION BerserkerDashEffectScript Scriptname BerserkerDashEffectScript extends ActiveMagicEffect {attached to magic effect, used in enchantment, this decides which effect to add} ; https://forums.nexusmods.com/index.php?/topic/7276666-how-to-make-a-script-to-activate-an-effect-by-holding-a-specific-key/ ;qwertypol012 wrote: "I am currently trying to make a script about using a "hold key" feature to activate an effect." ; "Did not put the properties here to keep it shorter" ; -- EVENTs -- 6 EVENT OnEffectStart(Actor akTarget, Actor akCaster) GetSettings() ENDEVENT EVENT OnEffectFinish(Actor akTarget, Actor akCaster) ; unequipped IF (SKSE.GetVersionRelease() as Bool) UnRegisterForKey(SneakKey) UnRegisterForKey(SprintKey) ENDIF ENDEVENT EVENT OnDying(Actor akKiller) ; snuffed it, bummer. IF (SKSE.GetVersionRelease() as Bool) UnRegisterForKey(SneakKey) UnRegisterForKey(SprintKey) ENDIF Restore(0.0) ENDEVENT EVENT OnKeyUp(Int Keycode, Float HoldTime) ; SKSE required ItsOn = 0 ENDEVENT EVENT OnKeyDown(Int Keycode) ; SKSE required UnRegisterForUpdate() ItsOn = 1 RegisterForSingleUpdate(0.0) ENDEVENT EVENT OnUpdate() ; https://www.creationkit.com/index.php?title=HasPerk_-_Actor IF Game.GetPlayer().HasPerk(zzFallProtection) RegisterForSingleUpdate(1.0) ; keep holding.. come back.. RETURN ; - STOP - player has the perk ENDIF ;--------------------- Utility.Wait(HoldTimer) IF ( DashActive ) IF (DashActive.GetValue() as Bool) ; (DashActive.GetValue() == 1) myF_ON() ELSE myF_OFF() ; (DashActive.GetValue() == 0) ENDIF ENDIF ENDEVENT ; -- FUNCTIONs -- 12 ;------------------------ FUNCTION Restore(Float f) ;------------------------ IF (f < 0.0) f = 0.0 ; set to min time, safety first ELSEIF (f > EffectTimer) f = EffectTimer ; set to max time ENDIF Utility.Wait(f) actor player = Game.GetPlayer() player.RemoveSpell(zzDashAbilityI) player.RemoveSpell(zzDashAbilityII) player.RemoveSpell(zzDashAbilityIII) player.RemoveSpell(zzDashAbilityIV) player.RemoveSpell(zzDashAbilityV) Game.SetGameSettingFloat("fJumpHeightMin", JumpHeight) Game.SetGameSettingFloat("fJumpMoveMult", JumpLength) player.ForceActorValue("speedmult", SpeedMult) player.AddPerk(zzDummyPerk) ; the speedmult setting refuses to take effect player.RemovePerk(zzDummyPerk) ; untill something odd happens. like this. ;;; RemoveFallProtection() Utility.Wait(FallDelay) player.RemovePerk(zzFallProtection) ENDFUNCTION ;---------------- FUNCTION myF_ON() ;---------------- actor player = Game.GetPlayer() IF (ItsOn == 1) || player.IsSneaking() ; *** Stage 1 *** ELSE RETURN ; - STOP - Key released before 1 ENDIF ;--------------------- AddStage1() Utility.Wait(Delay1) ; ( 1 ) IF (ItsOn == 1) || player.IsSneaking() ; *** Stage 2 *** ELSE Restore(EffectTimer - Delay1) RETURN ; - STOP - Key released before 2 ENDIF ;--------------------- AddStage2() Utility.Wait(Delay2) ; ( 2 ) IF (ItsOn == 1) || player.IsSneaking() ; *** Stage 3 *** ELSE Restore(EffectTimer - Delay2) RETURN ; - STOP - Key released before 3 ENDIF ;--------------------- AddStage3() Utility.Wait(Delay3) ; ( 3 ) IF (ItsOn == 1) || player.IsSneaking() ; *** Stage 4 *** ELSE Restore(EffectTimer - Delay3) RETURN ; - STOP - Key released before 4 ENDIF ;--------------------- AddStage4() Utility.Wait(Delay4) ; ( 4 ) IF (ItsOn == 1) || player.IsSneaking() ; *** Stage 5 *** ELSE Restore(EffectTimer - Delay4) RETURN ; - STOP - Key released before 5 ENDIF ;--------------------- AddStage5() ; ( 5 ) ; <-- original: AddStage4() Restore(EffectTimer) ENDFUNCTION ;----------------------------- Bool FUNCTION myF_IsPlayerOK() ; internal helper ;----------------------------- actor player = Game.GetPlayer() IF player.IsSneaking() Return TRUE ; player is sneaking ENDIF ;--------- IF player.IsRunning() Return False ; running not allowed ENDIF ;--------- IF player.IsSprinting() Return False ; sprinting not allowed ENDIF ;--------- Return TRUE ; player is whether running nor sprinting ENDFUNCTION ;----------------- FUNCTION myF_OFF() ;----------------- ;;; actor player = Game.GetPlayer() ;;; IF (ItsOn == 1) && ( player.IsSneaking() || (!player.IsRunning() && !player.IsSprinting()) ) IF myF_IsPlayerOK() && (ItsOn == 1) ; *** Stage 1 *** ELSE RETURN ; - STOP - Key released before 1 ENDIF ;--------------------- AddStage1() Utility.Wait(Delay1) ; ( 1 ) IF myF_IsPlayerOK() && (ItsOn == 1) ; *** Stage 2 *** ELSE Restore(EffectTimer - Delay1) RETURN ; - STOP - Key released before 2 ENDIF ;--------------------- AddStage2() Utility.Wait(Delay2) ; ( 2 ) IF myF_IsPlayerOK() && (ItsOn == 1) ; *** Stage 3 *** ELSE Restore(EffectTimer - Delay2) RETURN ; - STOP - Key released before 3 ENDIF ;--------------------- AddStage3() Utility.Wait(Delay3) ; ( 3 ) IF myF_IsPlayerOK() && (ItsOn == 1) ; *** Stage 4 *** ELSE Restore(EffectTimer - Delay3) RETURN ; - STOP - Key released before 4 ENDIF ;--------------------- AddStage4() Utility.Wait(Delay4) ; ( 4 ) IF myF_IsPlayerOK() && (ItsOn == 1) ; *** Stage 5 *** ELSE Restore(EffectTimer - Delay4) RETURN ; - STOP - Key released before 5 ENDIF ;--------------------- AddStage5() ; ( 5 ) Restore(EffectTimer) ENDFUNCTION ;--------------------- FUNCTION GetSettings() ;--------------------- JumpHeight = DashStoreJump.GetValue() JumpLength = DashStoreLength.GetValue() SpeedMult = DashStoreSpeed.GetValue() HoldTimer = DashTimerHold.GetValue() Delay1 = DashTimerDelay1.GetValue() Delay2 = DashTimerDelay2.GetValue() Delay3 = DashTimerDelay3.GetValue() Delay4 = DashTimerDelay4.GetValue() EffectTimer = DashTimerEffect.GetValue() FallDelay = DashTimerFall.GetValue() Jump1 = DashJump1.GetValue() Speed1 = DashSpeed1.GetValue() Length1 = DashLength1.GetValue() Jump2 = DashJump2.GetValue() Speed2 = DashSpeed2.GetValue() Length2 = DashLength2.GetValue() Jump3 = DashJump3.GetValue() Speed3 = DashSpeed3.GetValue() Length3 = DashLength3.GetValue() Jump4 = DashJump4.GetValue() Speed4 = DashSpeed4.GetValue() Length4 = DashLength4.GetValue() Jump5 = DashJump5.GetValue() Speed5 = DashSpeed5.GetValue() Length5 = DashLength5.GetValue() DashCostX2 = DashCostMult2.GetValue() DashCostX3 = DashCostMult3.GetValue() DashCostX4 = DashCostMult4.GetValue() DashCostX5 = DashCostMult5.GetValue() ;------------------------------------------- SneakKey = Input.GetMappedKey("Sneak") RegisterForKey(SneakKey) SprintKey = Input.GetMappedKey("Sprint") RegisterForKey(SprintKey) ;------------------------------------------- int i = DashFX.GetValueInt() IF (i == 1) ; normal zzDashAbilityI = zzDashAbilityI zzDashAbilityII = zzDashAbilityII zzDashAbilityIII = zzDashAbilityIII zzDashAbilityIV = zzDashAbilityIV zzDashAbilityV = zzDashAbilityV RETURN ; - STOP - ENDIF ;--------------------- IF (i == 2) ; fire zzDashAbilityI = zzDashAbilityFireI zzDashAbilityII = zzDashAbilityFireII zzDashAbilityIII = zzDashAbilityFireIII zzDashAbilityIV = zzDashAbilityFireIV zzDashAbilityV = zzDashAbilityFireV RETURN ; - STOP - ENDIF ;--------------------- IF (i == 3) ; frost zzDashAbilityI = zzDashAbilityFrostI zzDashAbilityII = zzDashAbilityFrostII zzDashAbilityIII = zzDashAbilityFrostIII zzDashAbilityIV = zzDashAbilityFrostIV zzDashAbilityV = zzDashAbilityFrostV RETURN ; - STOP - ENDIF ;--------------------- IF (i == 4) ; shock zzDashAbilityI = zzDashAbilityShockI zzDashAbilityII = zzDashAbilityShockII zzDashAbilityIII = zzDashAbilityShockIII zzDashAbilityIV = zzDashAbilityShockIV zzDashAbilityV = zzDashAbilityShockV RETURN ; - STOP - ENDIF ;--------------------- IF (i == 5) ; dark zzDashAbilityI = zzDashAbilityDarkI zzDashAbilityII = zzDashAbilityDarkII zzDashAbilityIII = zzDashAbilityDarkIII zzDashAbilityIV = zzDashAbilityDarkIV zzDashAbilityV = zzDashAbilityDarkV RETURN ; - STOP - ENDIF ;--------------------- ;IF (i == 0) ; blank zzDashAbilityI = zzDashAbilityBlankI zzDashAbilityII = zzDashAbilityBlankII zzDashAbilityIII = zzDashAbilityBlankIII zzDashAbilityIV = zzDashAbilityBlankIV zzDashAbilityV = zzDashAbilityBlankV ;ENDIF ENDFUNCTION ;----------------------- FUNCTION myF_Fail(Int i) ; internal helper ;----------------------- objectReference playerRef = Game.GetPlayer() as ObjectReference IF (i == 1) Debug.Notification("You don't have the Strength..") FailFX.Play(playerRef) ELSE Debug.Notification("You don't have the Power..") FailFX.Play(playerRef) ENDIF ENDFUNCTION ;------------------- FUNCTION AddStage1() ;------------------- actor player = Game.GetPlayer() float fs = DashCostStam.GetValue() IF (player.GetActorValue("stamina") < fs) ; stamina = Game.GetPlayer().GetAv("stamina") myF_Fail(1) RETURN ; - STOP - ENDIF ;--------------------- float fm = DashCostMag.Getvalue() IF (player.GetActorValue("magicka") < fm) ; magicka = Game.GetPlayer().GetAv("magicka") myyF_Fail(2) RETURN ; - STOP - ENDIF ;--------------------- player.DamageActorValue("Stamina", fs) player.DamageActorValue("Magicka", fm) player.AddSpell(zzDashAbilityI, False) myF_Perks(player, Jump1, Length1, Speed1) ENDFUNCTION ;------------------- FUNCTION AddStage2() ;------------------- actor player = Game.GetPlayer() float fs = DashCostStam.GetValue() * DashCostX2 IF (player.GetActorValue("stamina") < fs) myF_Fail(1) RETURN ; - STOP - ENDIF ;--------------------- float fm = DashCostMag.Getvalue() * DashCostX2 IF (player.GetActorValue("magicka") < fm) myyF_Fail(2) RETURN ; - STOP - ENDIF ;--------------------- player.DamageActorValue("Stamina", fs) player.DamageActorValue("Magicka", fm) player.AddSpell(zzDashAbilityII, False) myF_Perks(player, Jump2, Length2, Speed2) ENDFUNCTION ;------------------- FUNCTION AddStage3() ;------------------- actor player = Game.GetPlayer() float fs = DashCostStam.GetValue() * DashCostX3 IF (player.GetActorValue("stamina") < fs) myF_Fail(1) RETURN ; - STOP - ENDIF ;--------------------- float fm = DashCostMag.Getvalue() * DashCostX3 IF (player.GetActorValue("magicka") < fm) myF_Fail(2) RETURN ; - STOP - ENDIF ;--------------------- player.DamageActorValue("Stamina", fs) player.DamageActorValue("Magicka", fm) player.AddSpell(zzDashAbilityIII, False) myF_Perks(player, Jump3, Length3, Speed3) ENDFUNCTION ;------------------- FUNCTION AddStage4() ;------------------- actor player = Game.GetPlayer() float fs = DashCostStam.GetValue() * DashCostX4 IF (player.GetActorValue("stamina") < fs) myF_Fail(1) RETURN ; - STOP - ENDIF ;--------------------- float fm = DashCostMag.Getvalue() * DashCostX4 IF (player.GetActorValue("magicka") < fm) myF_Fail(2) RETURN ; - STOP - ENDIF ;--------------------- player.DamageActorValue("Stamina", fs) player.DamageActorValue("Magicka", fm) player.AddSpell(zzDashAbilityIV, False) myF_Perks(player, Jump4, Length4, Speed4) ENDFUNCTION ;------------------- FUNCTION AddStage5() ;------------------- actor player = Game.GetPlayer() float fs = DashCostStam.GetValue() * DashCostX5 IF (player.GetActorValue("stamina") < fs) myF_Fail(1) RETURN ; - STOP - ENDIF ;--------------------- float fm = DashCostMag.Getvalue() * DashCostX5 IF (player.GetActorValue("magicka") < fm) myF_Fail(2) RETURN ; - STOP - ENDIF ;--------------------- player.DamageActorValue("Stamina", fs) player.DamageActorValue("Magicka", fm) player.AddSpell(zzDashAbilityV, False) myF_Perks(player, Jump5, Length5, Speed5) ENDFUNCTION ;------------------------------------------------------------- FUNCTION myF_Perks(Actor player, Float fJ, Float fL, Float fS) ; internal helper ;------------------------------------------------------------- int i = player.GetRace().GetFormID() IF (i == 0x00013740) ; ArgonianRace ELSEIF (i == 0x00013745) ; KhajiitRace ELSEIF (i == 0x00013748) ; RedguardRace ELSEIF (i == 0x00013749) ; WoodElfRace ELSE Game.SetGameSettingFloat("fJumpHeightMin", JumpHeight + fJ) Game.SetGameSettingFloat("fJumpMoveMult", JumpLength + fL) player.ForceActorValue("speedmult", SpeedMult + fS) player.AddPerk(zzDummyPerk) player.RemovePerk(zzDummyPerk) ENDIF ;;; Utility.Wait(0.1) player.AddPerk(zzFallProtection) ENDFUNCTION ; Looks dumb right? That's why i'm asking if anyone knows a better way to write all vanilla race check ; ; string RaceText1 = "[Race <ArgonianRace (00013740)>]" ; string RaceText2 = "[Race <BretonRace (00013741)>]" ; string RaceText3 = "[Race <DarkElfRace (00013742)>]" ; string RaceText4 = "[Race <HighElfRace (00013743)>]" ; string RaceText5 = "[Race <ImperialRace (00013744)>]" ; string RaceText6 = "[Race <KhajiitRace (00013745)>]" ; string RaceText7 = "[Race <NordRace (00013746)>]" ; string RaceText8 = "[Race <OrcRace (00013747)>]" ; string RaceText9 = "[Race <RedguardRace (00013748)>]" ; string RaceText10 = "[Race <WoodElfRace (00013749)>]" ; string RaceText11 = "[Race <ArgonianRaceVampire (0008883A)>]" ; string RaceText12 = "[Race <BretonRaceVampire (0008883C)>]" ; string RaceText13 = "[Race <DarkElfRaceVampire (0008883D)>]" ; string RaceText14 = "[Race <HighElfRaceVampire (00088840)>]" ; string RaceText15 = "[Race <ImperialRaceVampire (00088844)>]" ; string RaceText16 = "[Race <KhajiitRaceVampire (00088845)>]" ; string RaceText17 = "[Race <NordRaceVampire (00088794)>]" ; string RaceText18 = "[Race <OrcRaceVampire (000A82B9)>]" ; string RaceText19 = "[Race <RedguardRaceVampire (00088846)>]" ; string RaceText20 = "[Race <WoodElfRaceVampire (00088884)>]" This took me awhile to learn and fathom the scripts. Thank you very much for the scripts! I'm very grateful with that :DNow, there are several things i want to ask regarding your edited scripts. 1. About this part of BerserkerDashEffectScript: ;IF (i == 0) ; blank zzDashAbilityI = zzDashAbilityBlankI zzDashAbilityII = zzDashAbilityBlankII zzDashAbilityIII = zzDashAbilityBlankIII zzDashAbilityIV = zzDashAbilityBlankIV zzDashAbilityV = zzDashAbilityBlankV ;ENDIF Why did you comment it out? Is it how it's supposed to be? 2. About part of this function (in BerserkerDashEffectScript): ;--------------------- player.DamageActorValue("Stamina", fs) player.DamageActorValue("Magicka", fm) player.AddSpell(zzDashAbilityI, False) myF_Perks(player, Jump1, Length1, Speed1) ENDFUNCTIONIf i understand it correctly, the function damages the player's stamina and/or magicka if they're lower than the required amount (fm and fs), right?If so, then what i actually want is that the function only damages the player's stam &/or mag if they're higher than fm &/or fs as a result of succesfully casted the effect (if you successfully cast the effect, your stam &/or mag will be damaged). If you fail, then your stam &/or mag won't be damaged.Am i correct in this part (which means that part of the script need to be edited)? Edit: I think i am. I think it needs to be wrapped in another IF ENDIF with condition if player's sta & mag are higher than fs & fm. (i just did) 3. About this part of the script (still in BerserkerDashEffectScript): ;------------------------------------------------------------- FUNCTION myF_Perks(Actor player, Float fJ, Float fL, Float fS) ; internal helper ;------------------------------------------------------------- int i = player.GetRace().GetFormID() IF (i == 0x00013740) ; ArgonianRace ELSEIF (i == 0x00013745) ; KhajiitRace ELSEIF (i == 0x00013748) ; RedguardRace ELSEIF (i == 0x00013749) ; WoodElfRace ELSE Game.SetGameSettingFloat("fJumpHeightMin", JumpHeight + fJ) Game.SetGameSettingFloat("fJumpMoveMult", JumpLength + fL) player.ForceActorValue("speedmult", SpeedMult + fS) player.AddPerk(zzDummyPerk) player.RemovePerk(zzDummyPerk) ENDIF ;;; Utility.Wait(0.1) player.AddPerk(zzFallProtection) ENDFUNCTIONI still couldn't fully grasp it yet. If i understand it correctly, this function checks if the player race is one of the mentioned races, and if it's true then it adds jump heigh, jump length, and speed mult with the amount stored in FJ, FL, and FS, right?So first, where do the fJ, fL, and fS call to? I couldn't find those floats anywhere else. It's the same with myF_Perks(player, Jumpx, Lengthx, Speedx (x = 1 to 5)) in which i couldn't see where Jumpx, Lengthx, and Speedx get their values from.Also, has this function also check for vampire version of each respective race? Or do i need to add more ESLEIF for each vampire races? Edit: I think i just grasped it. Float fJ, float fL, and float FS will call to Jumpx, Lengthx, and Speedx as part of function myF_Perks, right?I also seemed to get temporal memory loss for not knowing where Jumpx, Lengthx, and Speedx get their values from (big duh on that, lol) :sweat: :tongue:And i think i also need to add vampire races ones if i want them to be checked in the function. (just did) 4. Do i need to put objectReference playerRef as a property for the script? Also, anything else i need to add to the properties?As a reference, this is my currently existing properties for BerserkerDashEffectScript: ;-------------Properties----------------- GlobalVariable Property DashJump1 Auto GlobalVariable Property DashLength1 Auto GlobalVariable Property DashSpeed1 Auto GlobalVariable Property DashJump2 Auto GlobalVariable Property DashLength2 Auto GlobalVariable Property DashSpeed2 Auto GlobalVariable Property DashJump3 Auto GlobalVariable Property DashLength3 Auto GlobalVariable Property DashSpeed3 Auto GlobalVariable Property DashJump4 Auto GlobalVariable Property DashLength4 Auto GlobalVariable Property DashSpeed4 Auto GlobalVariable Property DashJump5 Auto GlobalVariable Property DashLength5 Auto GlobalVariable Property DashSpeed5 Auto GlobalVariable Property DashCostStam Auto GlobalVariable Property DashCostMag Auto GlobalVariable Property DashCostMult2 Auto GlobalVariable Property DashCostMult3 Auto GlobalVariable Property DashCostMult4 Auto GlobalVariable Property DashCostMult5 Auto GlobalVariable Property DashFX Auto GlobalVariable Property DashActive Auto GlobalVariable Property DashHidden Auto GlobalVariable Property DashStoreJump Auto GlobalVariable Property DashStoreLength Auto GlobalVariable Property DashStoreSpeed Auto GlobalVariable Property DashTimerHold Auto GlobalVariable Property DashTimerDelay1 Auto GlobalVariable Property DashTimerDelay2 Auto GlobalVariable Property DashTimerDelay3 Auto GlobalVariable Property DashTimerDelay4 Auto GlobalVariable Property DashTimerEffect Auto GlobalVariable Property DashTimerFall Auto Spell Property zzDashAbilityI auto Spell Property zzDashAbilityII auto Spell Property zzDashAbilityIII auto Spell Property zzDashAbilityIV auto Spell Property zzDashAbilityV auto Spell Property zzDashAbilityFireI auto Spell Property zzDashAbilityFireII auto Spell Property zzDashAbilityFireIII auto Spell Property zzDashAbilityFireIV auto Spell Property zzDashAbilityFireV auto Spell Property zzDashAbilityFrostI auto Spell Property zzDashAbilityFrostII auto Spell Property zzDashAbilityFrostIII auto Spell Property zzDashAbilityFrostIV auto Spell Property zzDashAbilityFrostV auto Spell Property zzDashAbilityShockI auto Spell Property zzDashAbilityShockII auto Spell Property zzDashAbilityShockIII auto Spell Property zzDashAbilityShockIV auto Spell Property zzDashAbilityShockV auto Spell Property zzDashAbilityDarkI auto Spell Property zzDashAbilityDarkII auto Spell Property zzDashAbilityDarkIII auto Spell Property zzDashAbilityDarkIV auto Spell Property zzDashAbilityDarkV auto Spell Property zzDashAbilityBlankI auto Spell Property zzDashAbilityBlankII auto Spell Property zzDashAbilityBlankIII auto Spell Property zzDashAbilityBlankIV auto Spell Property zzDashAbilityBlankV auto Perk Property zzFallProtection auto Perk Property zzDummyPerk auto Sound Property FailFX auto Float SpeedMult Float JumpHeight Float JumpLength Float Stamina Float Magicka Float Stamcost Float Magcost Float DashCostX2 Float DashCostX3 Float DashCostX4 Float DashCostX5 Float Jump1 Float Length1 Float Speed1 Float Jump2 Float Length2 Float Speed2 Float Jump3 Float Length3 Float Speed3 Float Jump4 Float Length4 Float Speed4 Float Jump5 Float Length5 Float Speed5 Float ScriptTimer Float HoldTimer Float Delay1 Float Delay2 Float Delay3 Float Delay4 Float EffectTimer Float FallDelay int Property Stamina Auto Int Property SneakKey auto Int Property SprintKey auto Bool ItsOn The only ones i can think of is float f and int i, but i'm not sure if they need to be added as properties (i just added them anyway, just to be safe). 5. What does RETURN function exactly for? Can i also use it in any other functions? I have another script about casting a custom spell and i'm interested in using this to work as some kind of failsafe if the spell fail to cast That's it for now. I'll ask again if i get more questions. Thank you very much :smile: Edited January 3, 2019 by qwertypol012 Link to comment Share on other sites More sharing options...
ReDragon2013 Posted January 22, 2019 Share Posted January 22, 2019 (edited) Sorry for my late return, but I am not so good to make explanation. But if you want to understand papyrus language, you have to code scripts (again and again).qwertypol012 asked:1) Why did you comment it out? Is it how it's supposed to be? ;IF (i == 0) ; blank zzDashAbilityI = zzDashAbilityBlankI zzDashAbilityII = zzDashAbilityBlankII zzDashAbilityIII = zzDashAbilityBlankIII zzDashAbilityIV = zzDashAbilityBlankIV zzDashAbilityV = zzDashAbilityBlankV ;ENDIFWhenever you use multiple if/elseif conditions make sure to have an escape door.One condition should be the default branch.2) About part of this function (in BerserkerDashEffectScript): player.DamageActorValue("Stamina", fs) player.DamageActorValue("Magicka", fm)I only try to optimize the script, I cannot really know what you want to aim here.As I understand you found a proper solution.The whole function is like that: ;------------------- FUNCTION AddStage1() ;------------------- actor player = Game.GetPlayer() float fs = DashCostStam.GetValue() IF (player.GetActorValue("stamina") < fs) ; stamina = Game.GetPlayer().GetAv("stamina") myF_Fail(1) RETURN ; - STOP - ENDIF ;--------------------- float fm = DashCostMag.Getvalue() IF (player.GetActorValue("magicka") < fm) ; magicka = Game.GetPlayer().GetAv("magicka") myyF_Fail(2) RETURN ; - STOP - ENDIF ;--------------------- player.DamageActorValue("Stamina", fs) player.DamageActorValue("Magicka", fm) player.AddSpell(zzDashAbilityI, False) myF_Perks(player, Jump1, Length1, Speed1) ENDFUNCTIONYou wrote: "what i actually want is that the function only damages the player's stam &/or mag if they're higher than fm &/or fs"As you can see stamina and magicka are checked before DamageActorValue() may run. That is what you wanted.3) About this part of script: ;------------------------------------------------------------- FUNCTION myF_Perks(Actor player, Float fJ, Float fL, Float fS) ; internal helper ;------------------------------------------------------------- int i = player.GetRace().GetFormID() IF (i == 0x00013740) ; ArgonianRace ELSEIF (i == 0x00013745) ; KhajiitRace ELSEIF (i == 0x00013748) ; RedguardRace ELSEIF (i == 0x00013749) ; WoodElfRace ELSE Game.SetGameSettingFloat("fJumpHeightMin", JumpHeight + fJ) Game.SetGameSettingFloat("fJumpMoveMult", JumpLength + fL) player.ForceActorValue("speedmult", SpeedMult + fS) player.AddPerk(zzDummyPerk) player.RemovePerk(zzDummyPerk) ENDIF ;;; Utility.Wait(0.1) player.AddPerk(zzFallProtection) ENDFUNCTION What is the different between (global) script variable and (local script) function variable?For example "JumpHeight" is a script variable (which you didn't provide us), it does not need to give us as function parameter,but it can be. I use very short names for function variables to make different to global script variable names.You wrote also: "So first, where do the fJ, fL, and fS call to? I couldn't find those floats anywhere else."Every function has its own name room to identify variables. In the head you can put parameter names as you like the typeshould be known to the compiler (int, float, actor, objectReference, etc.).They are stored on the function stack like any other declared internal function variable.You asked: "Also, has this function also check for vampire version of each respective race?Or do i need to add more ESLEIF for each vampire races?"Depends on what should be the result, you have to put vampire IDs too. ; string RaceText11 = "[Race <ArgonianRaceVampire (0008883A)>]" ELSEIF (i == 0x00013749) ; WoodElfRace ELSEIF (i == 0x0008883A) ; ArgonianRaceVampire ELSE4) Do I need to put objectReference playerRef as a property for the script?Try to minimize using of objectReference and actor as predefined property or script variable.You asked: "The only ones i can think of is float f and int i, but i'm not sure if they need to be added as properties(i just added them anyway, just to be safe)."NO. NO. Both are local function variables and not needed to be declared out of the function.5) What does RETURN function exactly for? Can i also use it in any other functions?The papyrus term "RETURN" is like "ENDFUNCTION" or "ENDEVENT" depends of the body you call it.Keep in mind that functions can be like this: EVENT OnCellLoad() RETURN ; - STOP - no parameter by default, because event body ENDEVENT FUNCTION XYZ() RETURN ; - STOP - no function return parameter needed ENDFUNCTION Int FUNCTION intXYZ() RETURN 0 ; function returns with type integer (as digit) ENDFUNCTION Int FUNCTION intXYZ_2() int i = 0 RETURN i ; function returns with type integer (as value stored in local script variable) ENDFUNCTION Float FUNCTION floatXYZ() RETURN 0.0 ; function returns with type float (as digit) ENDFUNCTION Float FUNCTION floatXYZ_2(Float f) f = 0.0 RETURN f ; function returns with type float (as value stored in local script variable) ENDFUNCTION Edited January 24, 2019 by ReDragon2013 Link to comment Share on other sites More sharing options...
qwertypol012 Posted January 22, 2019 Author Share Posted January 22, 2019 4) Do I need to put objectReference playerRef as a property for the script?Try to minimize using of objectReference and actor as predefined property or script variable. You asked: "The only ones i can think of is float f and int i, but i'm not sure if they need to be added as properties(i just added them anyway, just to be safe)." NO. NO. Both are local function variables and not needed to be declared out of the function. Thanks for your reply! Yes, actually i've been learning almost everyday since the day i asked about this script, and now i understand that they're local function variables and should not be put as script properties :laugh: Yes, code more scripts is a good way to learn more, but i also learnt by cracking up mods' scripts which i'm interested in. In the end, i only want to code something which i'm really interested in, so i'm not sure if i'll be able to master papyrus scripting faster. That said, i mostly always do anything to get something i really want, and if that's a script then i'll learn anything in order to finish that script. Just 2 cents though, not a big real. And thanks for coming back to give your reply. :smile: Link to comment Share on other sites More sharing options...
Recommended Posts