Thread Tools Display Modes
04/29/14, 01:53 PM   #1
ZunaSW
Join Date: Mar 2014
Posts: 37
Making a texture hidden and not hidden if...

Hi. Sorry my english : )
I'm not sure how to do this, I know it can be done, but I'm not sure if I'm going well or I'm doing it wrong. Here is what I want to do:

My texture will be always hidden, but when the stamina is below 10% the texture will be shown. This is how I put the texture:

Code:
-- Barra de Aguante
  local wm = GetWindowManager()
  local c = wm:CreateTopLevelWindow(nil)
  c:SetDimensions(1024,128)
  c:SetAnchor(BOTTOM,GuiRoot,BOTTOM,0,0)
  --Textura de la barra de aguante
  c.icon = wm:CreateControl(nil, c, CT_TEXTURE)
  c.icon:SetTexture("Addon/tex/tex1.dds")
  c.icon:SetAnchorFill(c)
I used this "tutorial" and now I can understand how to put textures: http://www.esoui.com/downloads/info33-zTextureTest.html But not how to "call" them to do something later. I'm not sure if I'm explaining well what I want to say. In some moment you will have to "call" your texture to be shown, for example in Papyrus of Skyrim (I'll put a example similar of what I want to do in the Addon):
Code:
Event OnCellLoad()
	MyNPC.enable()
EndEvent
That "MyNPC" is "called" in a property. And I'm trying to find something like that, I know you can't do it because this is not the Creation Kit and this is all write and write and write codes, but it has to be a way to call that texture, and then it will become possible to shown or not shown. I tried with this:

Code:
local function SHStaminaBar()
-- Barra de Aguante
	local wm = GetWindowManager()
	local c = wm:CreateTopLevelWindow(nil)
	local staminabar = SHStamina(WINDOW_MANAGER:CreateTopLevelWindow("stamina") )
		 staminabar:SetHidden(true)
		 staminabar:SetDimensions(1024,128)
                 staminabar:SetAnchor(BOTTOMRIGHT,GuiRoot,BOTTOMRIGHT,0,0)
		 staminabar:SetTexture("Addon/tex/tex1.dds")
		 staminabar:SetAnchorFill(c)
		 staminabar:SetAlpha(1.0)
		if (ZO_PlayerAttributeStamina < 10)
			staminabar:SetHidden(false)
		end	 
 return window
end
But no way, it's giving me an error for that "staminabar:SetHidden(false)".
How to do this?

Thanks!
  Reply With Quote
04/29/14, 02:23 PM   #2
Harven
 
Harven's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 135
Hey,
To call something later use the events as I explain it below.

I think it's giving you the error becase the function SHStamina is not defined, so your local variable staminabar is nil when you try to call SetHidden(). Change the line to:

Code:
staminabar = WINDOW_MANAGER:CreateTopLevelWindow("stamina") --make it global
Then write another function and register it to some combat event, for example EVENT_COMBAT_EVENT:

Code:
local function MyOnCombatEvent()
end

EVENT_MANAGER:RegisterForEvent(some_name, EVENT_COMBAT_EVENT, MyOnCombatEvent)
The function MyOnCombatEvent will be called by the game in response to combat events.

In the MyOnCombatEvent() function get player's current stamina and when it's below 10% show the "texture":

Code:
local function MyOnCombatEvent()
-- get player's max stamina
-- get player's current stamina

    local stamina_perc = cur_stamina/max_stamina*100
    if stamina_perc < 10  then
        staminabar:SetHidden(false)
    else
        staminabar:SetHidden(true)
    end
end
You should look in to the API docs to find a function that will return player's stamina levels.

Last edited by Harven : 04/30/14 at 07:38 AM.
  Reply With Quote
04/30/14, 09:36 AM   #3
ZunaSW
Join Date: Mar 2014
Posts: 37
Thanks! I'll try with that
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Making a texture hidden and not hidden if...


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off