Problem with OnPlayerCombat State
Hello. I try to follow this tutorial: http://wiki.esoui.com/Writing_your_first_addon
And I create a function like that: Lua Code:
But something went wrong, because when I reload UI, it already show me "Fighting!" sign. But I'm not in combat state! After killing the enemy, the sign disappears. But why It exists without fight mode just after reloadui? Why inCombat variable return 1? For example, Lua Code:
works perfectly - it shows me Entering/Exiting when it really occurs. |
Are you also hiding the indicator on startup?
|
Quote:
I have no experience in Lua, so I only following the tutorial and here is nothing about hiding it on startup. But why sign exists on startup? CombatState is 1 by default? Or default value is sth like "CombatState = nil" and it must be set to zero manually? If you can help me and show how to hide it on startup, i'll be thankful to you. Full listing:
Warning: Spoiler
|
Used pChat plugin to see what happens with inCombat veriable and saw inCombat = nil as I expected.
Okay, tried to set it to 0: Lua Code:
|
|
Can you post the indicator code pls?
|
Ok so most likely, if you're following the guide on the wiki, you have this in your XML:
<TopLevelControl name="TestPluginIndicator"> <Dimensions x="200" y="25" /> <Anchor point="BOTTOM" relativeTo="GuiRoot" relativePoint="CENTER" offsetY="-20" /> The UI will automatically be visible from the start, because that's what makes sense. If you draw something, default behaviour should be that you see it. However, you can make it hidden from the start. Change <TopLevelControl name="TestPluginIndicator"> to <TopLevelControl name="TestPluginIndicator" hidden="true">. This probably isn't the best way to handle it though. If you do this, and the player reloadsui while in combat, the indicator will be hidden. Sure, it's a rare bug but it's still a bug. Here's two ways you can fix that. 1. Check if the player is in combat in the Initialized() function, and set it visible/hidden as needed. 2. Use the <OnInitialized> field: <OnInitialized> -- LUA code here. This is where you'd check to see if the control needs to be hidden or not. </OnInitialized> Oninitialized does what you might expect: Runs the code within when the control is created.Edit: Actually, I don't think it does that. I think it runs when the addon is initialized, but I'm not sure. I'd suggest checking here: http://wiki.esoui.com/UI_XML to see what other attributes are available. A TopLevelControl will have the fields under TopLevelControl. Since it says Inherits: Control there, it also has all the fields which are listed under Control. Quote:
The value of CombatState in general has nothing to do with the visibility of the indicator. It only affects the visibility because of the code. So changing the value of combatState will do nothing, because there's no event for a variable being changed. combatState is just a variable within your code, and it has no connection at all to the indicator. Please let me know if you're still confused about this. |
Once the addon is initialized, the according function should check the combat state and set the indicator to hidden, if the player is out of combat. This behaviour is definetely strange.
|
Yes the according function should check it, but it is never called after a reloading, until the player enters or edits combat.
|
I'd set up your UI element for the indicator (testpluginIndicator) to be hidden by default on EVENT_ADD_ON_LOADED and then only ever change the display of it with your event handler for EVENT_PLAYER_COMBAT_STATE.
Only toggle the display of the element in your handler in EVENT_PLAYER_COMBAT_STATE. There's one additional issue you might run into - if you reload UI during combat, the combat state event does not fire upon reloading UI, so you need to check for combat state anytime the player is activated. You can cover this by registering an additional event handler to EVENT_PLAYER_ACTIVATED and calling your function there. That should check combat state upon activation of the player after the loading screen. |
Quote:
Code:
function testplugin:Initialize() Quote:
|
Quote:
|
Quote:
|
All times are GMT -6. The time now is 06:15 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI