Azurefae Posted April 20 Share Posted April 20 So, in the attached post i have a script I've written attached to a quest that detects if your player is an argonian, and if so detects if you are swimming or not so it can apply a spell (ability) while swimming and remove it once you exit the water. In another block i have it detect if you're a wood elf and if you're sneaking to similarly add a spell (ability) and remove it once you un-sneak. This code works fine, but it causes slight stuttering during play and i want to know if there's a way i could possibly code it so it only runs when swimming/sneaking or possibly some other way to reduce the strain on the game. I think i can set the quest itself to only run if I'm an argonian or wood elf (which i plan on separating these into 2 different quest scripts eventually, this was just for testing purposes) but that would only solve the issue for playing as races other than the ones that have scripts running. I know the stuttering is probably happening due to the frequency at which it is running checks (every second) so I'd like to find a way where it only runs the check when necessary. Setting the quest delay time back to default isn't an option because I don't want there to be a long janky 5 seconds in between it running checks on whether or not to add or remove the ability. Link to comment Share on other sites More sharing options...
AndalayBay Posted April 20 Share Posted April 20 Yes, you can flip the focus around. Test for the activity first, which wouldn't be all the time, so the script would stop. You can also combine the conditions. Link to comment Share on other sites More sharing options...
LenaWolfBravil Posted April 20 Share Posted April 20 I think the problem with this script is that you keep adding that spell every second, even if the player already has it. Ideally, what you want to do is this: When the player is out of the water, keep checking whether they are swimming. When you notice the change, add the spell, they are now swimming. While swimming, keep checking whether the player is still swimming, but don't do anything else (don't keep adding the same spell, especially since the player already got it! This is what causes stuttering). When you notice that the player is no longer swimming, remove the spell. Here is how I would code it (just for the Argonian, you can do the same for your Wood Elf). scn PTRacebuffscript float fQuestDelayTime short init short swimming begin gamemode if init == 0 ;If you are not Argonian, stop the quest if player.GetIsRace Argonian == 0 StopQuest PTRaceBuffQuest exit endif set fQuestDelayTime to 1 set init to 1 endif ;The rest will only run if you are Argonian ;If we are not swimming, check for a change in status if swimming == 0 if player.IsSwimming set swimming to 1 player.AddSpell PTAbArgonianSwimBuff endif ;If we are swimming, check for a change again else if player.IsSwimming == 0 set swimming to 0 player.RemoveSpell PTAbArgonianSwimBuff endif endif end Link to comment Share on other sites More sharing options...
RomanR Posted April 21 Share Posted April 21 Or similarly: scn PTRacebuffscript float fQuestDelayTime short argoSpellAdded short wElfSpellAdded short init begin gamemode ;init if init == 0 set argoSpellAdded to 0 set wElfSpellAdded to 0 set fQuestDelayTime to 1 set init to 1 endif ;is player an Argonian and is swimming? if player.GetIsRace Argonian if player.IsSwimming if argoSpellAdded == 0 player.AddSpell PTAbArgonianSwimBuff set argoSpellAdded to 1 endif else if argoSpellAdded != 0 player.RemoveSpell PTAbArgonianSwimBuff set argoSpellAdded to 0 endif endif else ;if ability was added accidentaly if argoSpellAdded != 0 player.RemoveSpell PTAbArgonianSwimBuff set argoSpellAdded to 0 endif endif ;now elf part if player.GetIsRace WoodElf if player.IsSneaking if wElfSpellAdded == 0 player.AddSpell PTAbRaceWoodElfStalking set wElfSpellAdded to 1 endif else if wElfSpellAdded != 0 player.RemoveSpell PTAbRaceWoodElfStalking set wElfSpellAdded to 0 endif endif else if wElfSpellAdded != 0 player.RemoveSpell PTAbRaceWoodElfStalking set wElfSpellAdded to 0 endif endif end Added parts which removes buffs if accidentaly added to wrong races. With OBSE you can use HasSpell function too. Link to comment Share on other sites More sharing options...
LenaWolfBravil Posted April 24 Share Posted April 24 On 4/21/2025 at 1:45 PM, RomanR said: With OBSE you can use HasSpell function too. Expand It is an expensive function to use though. If we are looking to optimise this script for performance, we should avoid such functions. Link to comment Share on other sites More sharing options...
RomanR Posted April 26 Share Posted April 26 On 4/24/2025 at 2:28 PM, LenaWolfBravil said: It is an expensive function to use though. If we are looking to optimise this script for performance, we should avoid such functions. Expand Maybe. I thought about using IsSpellTarget too, but in the end checking value of flag variables is the quickest. Link to comment Share on other sites More sharing options...
Recommended Posts