WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Help with simple addon - enforcing cvars (https://www.wowinterface.com/forums/showthread.php?t=55964)

X33STORM 01-10-18 08:40 AM

Help with simple addon - enforcing cvars
 
So i'm looking for a little help with this personal addon i made to enforce a list of cvars, keybinds and other fixes across all characters.
I am not really a coder, so i don't know much about this other than the most basic principles.

This mod should run these cvars when i log on a character as is.
Problem is that both config-cache.wtf and AdvancedInterfaceOptions has some of these cvars, and i want this to override any other settings set by either the game or other addons.
I'm not sure if this already does that by running on every character login entering the world, either way i want to be sure this works as intended.

Now i' thinking maybe i need either to name the mod so it is loaded after? before? all other mods, like calling it !MyCvars.
Or the code needs to be executed at a point later than what the game config and AdvancedInterfaceOptions does.

Anyone maybe able to help me with this?

X33STORM.lua
Code:

local function eventHandler(self,event,...)

-- Floating Combat Text
SetCVar("enableFloatingCombatText", 1)
SetCVar("floatingCombatTextFloatMode", 1)
SetCVar("floatingCombatTextAllSpellMechanics", 0)
SetCVar("floatingCombatTextAuras", 0)
SetCVar("floatingCombatTextCombatDamageStyle", 1)
SetCVar("floatingCombatTextCombatDamage", 1)
SetCVar("floatingCombatTextCombatHealing", 1)
SetCVar("floatingCombatTextCombatDamageAllAutos", 1)
SetCVar("floatingCombatTextCombatDamageDirectionalScale", 1)
SetCVar("floatingCombatTextCombatDamageDirectionalOffset", 1)
SetCVar("floatingCombatTextCombatHealingAbsorbSelf", 1)
SetCVar("floatingCombatTextCombatHealingAbsorbTarget", 1)
SetCVar("floatingCombatTextCombatLogPeriodicSpells", 1)
SetCVar("floatingCombatTextCombatState", 1)
SetCVar("floatingCombatTextComboPoints", 1)
SetCVar("floatingCombatTextDamageReduction", 0)
SetCVar("floatingCombatTextDodgeParryMiss", 1)
SetCVar("floatingCombatTextEnergyGains", 1)
SetCVar("floatingCombatTextFriendlyHealers", 1)
SetCVar("floatingCombatTextHonorGains", 0)
SetCVar("floatingCombatTextLowManaHealth", 1)
SetCVar("floatingCombatTextPeriodicEnergyGains", 0)
SetCVar("floatingCombatTextPetMeleeDamage", 1)
SetCVar("floatingCombatTextPetSpellDamage", 1)
SetCVar("floatingCombatTextReactives", 1)
SetCVar("floatingCombatTextRepChanges", 0)
SetCVar("floatingCombatTextSpellMechanics", 1)
SetCVar("floatingCombatTextSpellMechanicsOther", 1)

-- Nameplate Settings
SetCVar("nameplateShowSelf", 0)
SetCVar("nameplateShowAll", 1)
SetCVar("nameplateShowEnemies", 1)
SetCVar("nameplateShowFriends", 1)
SetCVar("nameplateMaxDistance", 75)

-- Nameplate Fixes
SetCVar("nameplateLargeTopInset", -1)
SetCVar("nameplateOtherTopInset", -1)
SetCVar("nameplateLargeBottomInset", -1)
SetCVar("nameplateOtherBottomInset", -1)
SetCVar("nameplateHorizontalScale", 1)

-- Misc
SetCVar("useCompactPartyFrames", 1)
SetCVar("autoLootDefault", 1)
SetCVar("TargetNearestUseNew", 0)

end

local frame = CreateFrame("Frame","CVarSet")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent",eventHandler)


Tim 01-10-18 09:25 AM

Alter your .toc and add an optional dependency for AIO.

Code:

# OptionalDeps: AdvancedInterfaceOptions
This will make it so that addon loads before yours. As for the config-cache.wtf, this is character specific settings that generally require a game restart to take into effect. You should be good to go once you add that to your toc.

X33STORM 01-10-18 09:48 AM

Quote:

Originally Posted by Tim (Post 326426)
Alter your .toc and add an optional dependency for AIO.

Code:

# OptionalDeps: AdvancedInterfaceOptions
This will make it so that addon loads before yours. As for the config-cache.wtf, this is character specific settings that generally require a game restart to take into effect. You should be good to go once you add that to your toc.

Well ain't that just a stroke of brilliance, thanks buddy :)

Fizzlemizz 01-10-18 09:53 AM

Does it matter the order the addon loads because the function isn't being called until PLAYER_ENTERING_WORLD, unless of course addons receive events in the order they loaded which I have no idea about.

Doesn't AIO only set CVars when you action them in its UI?.

That said, this function will fire every time you see a loading screen. If you want a single event when the game loads use PLAYER_LOGIN.

Kanegasi 01-10-18 10:38 AM

Quote:

Originally Posted by Fizzlemizz (Post 326428)
Does it matter the order the addon loads because the function isn't being called until PLAYER_ENTERING_WORLD, unless of course addons receive events in the order they loaded which I have no idea about.

Doesn't AIO only set CVars when you action them in its UI?.

That said, this function will fire every time you see a loading screen. If you want a single event when the game loads use PLAYER_LOGIN.

Frames get events in the order they were registered. If you want a frame to always go last when an event registers, you can find a way to occasionally call UnregisterEvent then RegisterEvent right after, such as in ADDON_LOADED or UNIT_AURA or something like a 5 second OnUpdate. There’s some chat update events that are spammed during loading between ADDON_LOADED and PLAYER_LOGIN you could use if you’re confident addons wouldn’t try to register afterwards.

If you want to ensure your frame goes first, you can do the same thing but with the first return of GetFramesRegisteredForEvent("event"), which returns an ordered list of frames, the first one being the first one that was registered.

“Lua” Code:
  1. local myframe=CreateFrame(‘frame’)
  2. myframe:RegisterEvent(‘event’)
  3. local firstframe=GetFramesRegisteredForEvent(‘event’)
  4. while firstframe~=myframe do
  5.     firstframe:UnregisterEvent(‘event’)
  6.     firstframe:RegisterEvent(‘event’)
  7.     firstframe=GetFramesRegisteredForEvent(‘event’)
  8. end

Fizzlemizz 01-10-18 11:39 AM

Now I know, thank you.

semlar 01-11-18 10:19 AM

Quote:

Originally Posted by Fizzlemizz (Post 326428)
Doesn't AIO only set CVars when you action them in its UI?

AIO has an option to "enforce" all cvars that were set the last time you logged out, so temporary and character-specific cvars get reapplied the next time you log into any character.

It's meant to keep a global list of settings so if you change something it stays changed across your whole account.

Originally it was intended to prevent other addons from modifying cvars that you set manually through AIO, but I modified it to allow the changes but track which addon last touched the cvar so you can see it in the cvar browser.

Loading after AIO does might not always work. It reapplies the settings only after both VARIABLES_LOADED and ADDON_LOADED fires for it. If VARIABLES_LOADED fires after ADDON_LOADED does, setting it as an optional dependency won't be enough, and you'll have to wait for VARIABLES_LOADED to fire before overriding the settings.

Unfortunately, tracking settings that addons apply before AIO loads is considerably more complicated than the current setup, and would probably actually require loading a separate module before any other addons load, so it hasn't been done yet.

Also, this seems like a lot of personalized settings for an addon to change if this is something that's going to be distributed to other people, and the exact reason AIO tracks which addon modified which cvar, because these are things that persist after your addon is disabled and people get confused about why their settings are all different from what they had set when they turn it off and it doesn't go back to the way it was before.

Ammako 01-11-18 11:16 AM

Quote:

Originally Posted by semlar (Post 326443)
Also, this seems like a lot of personalized settings for an addon to change if this is something that's going to be distributed to other people, and the exact reason AIO tracks which addon modified which cvar, because these are things that persist after your addon is disabled and people get confused about why their settings are all different from what they had set when they turn it off and it doesn't go back to the way it was before.

OP said personal addon in the first sentence of their post. :p

semlar 01-11-18 11:17 AM

Quote:

Originally Posted by Ammako (Post 326446)
OP said personal addon in the first sentence of their post. :p

If that were the case, the addon would not need to set these cvars when they could be set through AIO, making worrying about the loading process a moot point.

Ammako 01-11-18 11:33 AM

Depends on whether they want to have AIO installed or not, to be fair.

semlar 01-11-18 11:42 AM

Quote:

Originally Posted by Ammako (Post 326449)
Depends on whether they want to have AIO installed or not, to be fair.

If he decides to disable AIO it won't be overriding his settings any more. If he sets his cvars through AIO then it won't matter if they override his addon because they'll be the same.

It does not matter whether he has it installed or not.

Ammako 01-11-18 11:50 AM

It sounded to me like they wanted to ensure it would override settings set by any addons. Though I guess my point is moot because OP is using AIO, but other people finding this thread from Google might not be. :p

semlar 01-11-18 01:11 PM

Quote:

Originally Posted by Ammako (Post 326451)
It sounded to me like they wanted to ensure it would override settings set by any addons. Though I guess my point is moot because OP is using AIO, but other people finding this thread from Google might not be. :p

If this is the case then loading later in the loading process won't be enough to really solve this problem.

Since any addon can change any cvar at any point while the game is running, to actually prevent a cvar from being changed requires actively monitoring for any future cvar changes and reversing them (which could cause an infinite loop if someone else has the same idea that their settings are actually more important than your settings and tries to reinforce them too), and would prevent you from doing things like toggling nameplate visibility on the fly (although I believe those are combat-protected so you'd have to take that into account as well).

To anyone finding this thread later: Don't automatically change cvars in your addon unless you have a very good reason to do so, and make it clear to your users that this is something you're doing.

These settings are generally permanent, and many of them can't be set through the interface, so even if your addon is disabled its changes will remain in-place and not easily reverted.

Ammako 01-11-18 07:54 PM

Quote:

Originally Posted by semlar (Post 326453)
To anyone finding this thread later: Don't automatically change cvars in your addon unless you have a very good reason to do so, and make it clear to your users that this is something you're doing.

These settings are generally permanent, and many of them can't be set through the interface, so even if your addon is disabled its changes will remain in-place and not easily reverted.

Can SetCVar be called at PLAYER_LOGOUT?
If so, I imagine a (partial) solution to this could be for an addon author to revert affected CVars back to defaults at logout.
Partial, because it wouldn't work if the user incorrectly exited the game before removing the addon, without explicitly logging out properly, but for the average user, this would effectively ensure that any changes to CVars from the addon wouldn't remain after uninstalling.

JDoubleU00 01-11-18 08:36 PM

Quote:

Originally Posted by Ammako (Post 326461)
Can SetCVar be called at PLAYER_LOGOUT?
If so, I imagine a (partial) solution to this could be for an addon author to revert affected CVars back to defaults at logout.
Partial, because it wouldn't work if the user incorrectly exited the game before removing the addon, without explicitly logging out properly, but for the average user, this would effectively ensure that any changes to CVars from the addon wouldn't remain after uninstalling.

I'm just thinking/typing out loud, but what if you set a flag when PLAYER_LOGOUT is properly used or exited? If the player exits improperly, then the app would know that things didn't end well and make changes appropriately.

Torhal 01-11-18 08:38 PM

Quote:

Originally Posted by JDoubleU00 (Post 326462)
I'm just thinking/typing out loud, but what if you set a flag when PLAYER_LOGOUT is properly used or exited? If the player exits improperly, then the app would know that things didn't end well and make changes appropriately.

Improper exit means the game crashed, which means no disk write.

Ammako 01-11-18 08:49 PM

Wouldn't really help anyway, even if it worked, because the hypothetical situation is that the user removed that addon following a crash.
Remove the addon, and you'd also be removing the code which would be checking for said flag anyway. So there isn't really a point, heh, and if you aren't removing the addon it'll just resume proper functionality the next time you start the game.

btw, probably a stupid question: X-ing out of the game improperly exits the game and doesn't save saved variables, right? I can imagine a lot of less knowledgeable players doing just that in the same way that people remove usb devices without doing the whole "remove safely" thing first.

semlar 01-11-18 08:57 PM

Quote:

Originally Posted by Ammako (Post 326464)
btw, probably a stupid question: X-ing out of the game improperly exits the game and doesn't save saved variables, right? I can imagine a lot of less knowledgeable players doing just that in the same way that people remove usb devices without doing the whole "remove safely" thing first.

Alt-F4ing out of the game does not prevent it from writing to the disk before it exits, unless it crashes during the process.

aallkkaa 01-14-18 02:19 AM

EDIT: What I say bellow is WRONG. See Ammako's reply immediately bellow for details.

Quote:

Originally Posted by Torhal (Post 326463)
Improper exit means the game crashed, which means no disk write.

You can set the flag to work reversely. I.e.:
1. Check the saved flag, say "cleanExit", and do the necessary fixups if it's false or nil;
2. Set cleanExit to false upon PLAYER_LOGIN;
3. Change the CVars and whatnot;
4. Set cleanExit to true on PLAYER_LOGOUT.
The absence of write on game crash implies NO evidence of a clean exit.

Ammako 01-14-18 08:07 AM

Quote:

Originally Posted by aallkkaa (Post 326488)
You can set the flag to work reversely. I.e.:
1. Check the saved flag, say "cleanExit", and do the necessary fixups if it's false or nil;
2. Set cleanExit to false upon PLAYER_LOGIN;
3. Change the CVars and whatnot;
4. Set cleanExit to true on PLAYER_LOGOUT.
The absence of write on game crash implies NO evidence of a clean exit.

Game crash = no disk write, including step 2.

You could have that variable set to true at login, change it to false at step 2. Game crashes, the change isn't saved, and it will still be set to true.

Saved Variables don't get written to until you reload/logout/exit the game, no matter how many changes you make.

Kakjens 01-15-18 01:43 AM

Ammako, could you reword your example? At least for me, it sounded confusing.
Edit. OK, this should be more clear:
During ADDON_LOADED event cleanExit obtains the saved value (for example, true). In step 2 the value of cleanExit is changed to false. However, game crashes and the new value of cleanExit isn't saved.
Could detection of crash be attempted by using /played?

aallkkaa 01-15-18 06:45 PM

Quote:

Originally Posted by Ammako (Post 326490)
Saved Variables don't get written to until you reload/logout/exit the game, no matter how many changes you make.

Darn, you're right! I had completelly forgotten that!

X33STORM 02-17-18 09:01 AM

Something is amiss, some cvars are not being enforced it seems.
Maybe i fucked something up?

If anyone is able to fix it?
Ideally it should enforce only on login and reload.

X33STORM.lua

Code:

local function eventHandler(self,event,...)

-- Floating Combat Text
SetCVar("enableFloatingCombatText", 1)
SetCVar("floatingCombatTextFloatMode", 1)
SetCVar("floatingCombatTextAllSpellMechanics", 0)
SetCVar("floatingCombatTextAuras", 0)
SetCVar("floatingCombatTextCombatDamage", 1)
SetCVar("floatingCombatTextCombatHealing", 1)
SetCVar("floatingCombatTextCombatDamageAllAutos", 1)
SetCVar("floatingCombatTextCombatDamageDirectionalScale", 0.3)
SetCVar("floatingCombatTextCombatDamageDirectionalOffset", 13)
SetCVar("floatingCombatTextCombatHealingAbsorbSelf", 0)
SetCVar("floatingCombatTextCombatHealingAbsorbTarget", 1)
SetCVar("floatingCombatTextCombatLogPeriodicSpells", 1)
SetCVar("floatingCombatTextCombatState", 1)
SetCVar("floatingCombatTextComboPoints", 1)
SetCVar("floatingCombatTextDamageReduction", 0)
SetCVar("floatingCombatTextDodgeParryMiss", 1)
SetCVar("floatingCombatTextFriendlyHealers", 0)
SetCVar("floatingCombatTextHonorGains", 1)
SetCVar("floatingCombatTextLowManaHealth", 0)
SetCVar("floatingCombatTextEnergyGains", 0)
SetCVar("floatingCombatTextPeriodicEnergyGains", 0)
SetCVar("floatingCombatTextPetMeleeDamage", 1)
SetCVar("floatingCombatTextPetSpellDamage", 1)
SetCVar("floatingCombatTextReactives", 0)
SetCVar("floatingCombatTextRepChanges", 0)
SetCVar("floatingCombatTextSpellMechanics", 1)
SetCVar("floatingCombatTextSpellMechanicsOther", 1)

-- Nameplate Settings
SetCVar("ShowClassColorInFriendlyNameplate", 1)
SetCVar("nameplateMaxDistance", 65)
SetCVar("nameplateShowAll", 1)
SetCVar("nameplateShowSelf", 0)
SetCVar("nameplateShowOnlyNames", 0)
SetCVar("nameplateShowDebuffsOnFriendly", 1)
--SetCVar("nameplateShowFriendlyNPCs", 1)
SetCVar("nameplateShowEnemies", 1)
SetCVar("nameplateShowFriends", 1)
SetCVar("NameplateMotion", 1)
SetCVar("nameplateLargeTopInset", -1)
SetCVar("nameplateOtherTopInset", -1)
SetCVar("nameplateLargeBottomInset", -1)
SetCVar("nameplateOtherBottomInset", -1)
SetCVar("nameplateHorizontalScale", 1)
SetCVar("nameplateOverlapV", 0.45)
SetCVar("nameplateOverlapH", 0.8)

-- Misc
SetCVar("autoLootDefault", 1)
SetCVar("TargetNearestUseNew", 0)
SetCVar("showQuestTrackingTooltips", 1)

-- Camera
SetCVar("cameraDistanceMaxZoomFactor", 2.6)
SetCVar("test_cameraDynamicPitch", 1)
SetCVar("test_cameraTargetFocusEnemyEnable", 0)
SetCVar("test_cameraDynamicPitchBaseFovPad", 0.45)
SetCVar("test_cameraDynamicPitchBaseFovPadDownScale", 0.25)
SetCVar("test_cameraDynamicPitchBaseFovPadFlying", 0.65)
SetCVar("test_cameraHeadMovementDeadZone", 0.01)

-- Mouse
SetCVar("rawMouseEnable", 1)
SetCVar("rawMouseAccelerationEnable", 0)
SetCVar("rawMouseRate", 500)
SetCVar("rawMouseResolution", 600)

--SetCVar("", 1)

end

local frame = CreateFrame("Frame","CVarSet")
UIParent:UnregisterEvent("EXPERIMENTAL_CVAR_CONFIRMATION_NEEDED")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent",eventHandler)


Ammako 02-17-18 09:04 AM

In a situation like this, you should be more specific about what's not working.

X33STORM 02-17-18 09:50 AM

Quote:

Originally Posted by Ammako (Post 326957)
In a situation like this, you should be more specific about what's not working.

In AIO i can see which cvars was set by what, and i've found cvars set by the override dependencies XCT+, AIO itself and blizzard options.

A recent non-cvar change i had to add, after adding camera cvars to the addon.was this:

UIParent:UnregisterEvent("EXPERIMENTAL_CVAR_CONFIRMATION_NEEDED")

Might be that, dunno.

--------

Does this line mean on character login and reload?
I was thinking i might need to add some PLAYER_LOGIN stuff too?

frame:RegisterEvent("PLAYER_ENTERING_WORLD")

Phanx 02-19-18 09:36 AM

Quote:

Originally Posted by X33STORM (Post 326958)
I was thinking i might need to add some PLAYER_LOGIN stuff too?

My personal UI setup addon sets CVars only on PLAYER_LOGIN, does not register or unregister events on any other frames, and does not name any dependencies, optional or otherwise. This has worked for years and years, including when I had AdvancedInterfaceOptions installed, though I never used the "enforce" option Semlar mentioned earlier in this thread.

X33STORM 02-19-18 09:58 AM

Quote:

Originally Posted by Phanx (Post 326972)
My personal UI setup addon sets CVars only on PLAYER_LOGIN, does not register or unregister events on any other frames, and does not name any dependencies, optional or otherwise. This has worked for years and years, including when I had AdvancedInterfaceOptions installed, though I never used the "enforce" option Semlar mentioned earlier in this thread.

As i use AIO and XCT+ to apply some loose settings, the dependencies as i understand it, overrides any settings set by my addon that they have.

The addon is named X33STORM, and alphabetically it should override any addons named from 1 > 9 and A > W. Could name it differently i guess, what is the last loaded symbol/number/letter ? !Z9 or something?

As to register/unregister, i don't even know what they mean.. Just got a template from someone online, and put my own stuff in it.

Could i see your addon you think?

Ammako 02-19-18 10:10 AM

I reiterate, you should be more specific about what's not working. Just "some things aren't working" doesn't really help anyone figure out what may be wrong.

You might as well try and add a delay using C_Timer.After on those vars. Ghetto solution, but if it works.

X33STORM 02-19-18 10:31 AM

Quote:

Originally Posted by Ammako (Post 326975)
I reiterate, you should be more specific about what's not working. Just "some things aren't working" doesn't really help anyone figure out what may be wrong.

You might as well try and add a delay using C_Timer.After on those vars. Ghetto solution, but if it works.

I'm sorry, i am not actually sure anymore.
I might just be it doesn't apply the cvars on ui reload, leaving me to think it wasn't working.

Just looking for the event name for ui reload i suppose then, which i can't seem to find.

frame:RegisterEvent("PLAYER_LOGIN")
Maybe?

I don't know lua or C** i'm afraid.. I really should take some time to learn what i need to know, to do what i want, just lazy i guess.

Phanx 02-19-18 10:46 AM

Let's start over. Your original post implies, but doesn't actually say, that the code you posted isn't working the way you expect. Is it working as expected, or not? If it is working, what is the question you actually want answered? If it's not working, how is it not working -- what are you expecting it to do, and what actually happens instead?

Ammako 02-19-18 11:07 AM

There is no event for reload, it just fires PLAYER_ENTERING_WORLD again (maybe some others, but that one is your best bet.)

That event also fires whenever you go through a loading screen, on entering/exiting instances, for instance. Pun intended :]

jeffy162 02-19-18 01:22 PM

You don't have to know C++ to write addons for WoW. Lua and XML is all you need to know.

Phanx 02-20-18 10:14 AM

Quote:

Originally Posted by jeffy162 (Post 326984)
You don't have to know C++ to write addons for WoW. Lua and XML is all you need to know.

You don't need to know anything about XML either unless you're writing secure templates, which you (general "you" that applies to anyone who will ever read this post) will almost certainly never do; in 12+ years of writing WoW addons I have done that once. Everything else that can be done in XML can also be done in Lua.

Phanx 02-20-18 10:29 AM

Anyway, back on topic, @X33STORM if you can't just set your CVars through Advanced Interface Options and your current code isn't working, here is the code I've been using to set my CVars for about a decade without any problems:

https://github.com/phanx-wow/PhanxUI...ster/CVars.lua

jeffy162 02-20-18 03:49 PM

@Phanx - I know, I know. My memory is totally shot, now, and I couldn't remember what XML was (basically) used for :o . Thank you for clearing that up.


All times are GMT -6. The time now is 11:05 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI