Thread Tools Display Modes
04-30-15, 09:45 PM   #1
Noix
A Fallenroot Satyr
Join Date: Oct 2014
Posts: 20
LUA for Image spawn When targeting

Might not be clear. BUT!!!!!

Trying to work a LUA code to spawn an image (i could explain more) when i target someone..

Here is the LUA i'm using atm

function ()
if UnitClass("player") and UnitPower("player") > 0
then
return true
end
return false
end

What this code is doing is displaying the texture (Image) that are random set of numbers (Texture are numbers)

I'm trying find a way so its not always showing. (it shows always cuz of "if UnitClass('player") ) is there way i can change "UnitClass" to like "Target" so when i target something this image spawns.

Lol this might sound shaddy if so i can link images for better explain.
  Reply With Quote
04-30-15, 09:51 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Are you sure you're not looking for UnitExists("target")?
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
04-30-15, 10:01 PM   #3
Noix
A Fallenroot Satyr
Join Date: Oct 2014
Posts: 20
Originally Posted by Fizzlemizz View Post
Are you sure you're not looking for UnitExists("target")?
Hmm that sounds about right. Would it work on friendly targets as well? (going to try it now on my coding)


Basicly the code is designed to spawn next image (this for weak auras i should of said) depending on health ..

Example of the code.

function ()
local unit = "player"
local current_mp, max_mp = UnitPower(unit), UnitPowerMax(unit)
local percent_mp = current_mp / max_mp * 100
local tens = math.floor(current_mp / max_mp * 10) * 10
local ones = math.floor(percent_mp - tens)
if UnitClass("player") and UnitPower("player") > 0 and ones == 7
then
return true
end
return false
end

So would i change it to look like this :

function ()
local unit = "player"
local current_mp, max_mp = UnitPower(unit), UnitPowerMax(unit)
local percent_mp = current_mp / max_mp * 100
local tens = math.floor(current_mp / max_mp * 10) * 10
local ones = math.floor(percent_mp - tens)
if UnitExists("player") and UnitPower("player") > 0 and ones == 7
then
return true
end
return false
end

Last edited by Noix : 04-30-15 at 10:05 PM.
  Reply With Quote
04-30-15, 10:08 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,322
You might be looking for the PLAYER_TARGET_CHANGED event that fires when you change/clear your target. This and checking UnitExists() will give you the desired effect.

Lua Code:
  1. -- This is our texture
  2. local tex=UIParent:CreateTexture(nil,"BACKGROUND");
  3. tex:SetPoint("CENTER");--   Center in UIParent
  4. tex:SetTexture(1,1,1);--    You can pass RGB values instead of a texture path string to show solid colors
  5. tex:SetSize(32,32);--   Sets size to 32x32
  6. tex:Hide();--   Initially set our texture to be hidden
  7.  
  8. -- We need to set up an event listener to trigger from our event
  9. local eframe=CreateFrame("Frame");--    This will help us capture events
  10. eframe:RegisterEvent("PLAYER_TARGET_CHANGED");--    Register our event
  11. eframe:SetScript("OnEvent",function()-- Event handler
  12. --  We don't need to check which event fired since we only registered for one
  13.     tex:SetShown(UnitExists("target"));--   Show/Hide our texture according to if our target exists
  14. end);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
04-30-15, 10:13 PM   #5
Noix
A Fallenroot Satyr
Join Date: Oct 2014
Posts: 20
Well the main idea of this code i made for each image is to track my mana without it disapearing .. it works well but i have to be in combat.. testing the UnitExists change instead of UnitClass and it seems to be working how i want.

(its a redesign of a weak aura that someone made). for priest



If UnitExists('player') will it always show the texture ? regardless if i have target or not?

Last edited by Noix : 04-30-15 at 10:16 PM.
  Reply With Quote
04-30-15, 10:17 PM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
A list of valid unitid's can be found here.

If UnitExists('player') will it always show the texture ? regardless if i have target or not?
Yes
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
04-30-15, 10:18 PM   #7
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,322
Honestly, checking UnitExists("player") is always going to return true and UnitClass("player") will always return a string that evaluates as a true condition. What puzzles me is what are you trying to check there? Essentially, it's useless to have those functions there in the first place.

Edit: If you run UnitExists("player"), it's checking to see if you exist, you need to use UnitExists("target") instead.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
04-30-15, 10:24 PM   #8
Noix
A Fallenroot Satyr
Join Date: Oct 2014
Posts: 20
Well right now what it does is checks how much mana i have..
IE: 98% mana ... Texture would spawn 98 (number for the %).

So basicly what this code is doing for each of the 22 Textures (each texture has number from 00 - 100) is showing a new texture base on mana. i could link the code for Weak aura and you can look at the coding for each texture. (if that would help) but you would need the texture file...

Also this is from designed Weak aura for (prob heard of it) SilverUI. i'm basicly redoing code for target (that would display the health of the target) changing it to Mana for myself (Power).

If that make sense

Image of the Weak Aura ui (Right side 100 is heath of target - Left side 100 is Your health) Changing Right side
http://s.cdn.wowinterface.com/preview/pvw64973.jpg


VIdeo of the UI
https://www.youtube.com/watch?v=LJQmwx4iqbk

The person who made it i ask if i could customize it more for other classes and i have for lots of classes but for healing its sorta hard since i need find the right lua (or what needs to be change in lua) for it to work off mana part. Thus far i have gotten the right desire with 2 issues
1. It displays when not in combat always.
2. It will display in combat only
Thats only by check marking (in Weak Aura settings) In combat or out of combat. rest of the coding is fine. that i know for sure.

Last edited by Noix : 04-30-15 at 10:31 PM. Reason: Fix wording
  Reply With Quote
04-30-15, 10:31 PM   #9
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
You have two (or four?) sets of two images for target and player mana (and health?).

The player images you would just need to show on PLAYER_ENTERING_WORLD or ADDON_LOADED events and never hide and the target would be intially hidden and show/hide on PLAYER_TARGET_CHANGED depending on UnitExists('target') as SDPhantom showed.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 04-30-15 at 10:40 PM.
  Reply With Quote
04-30-15, 10:35 PM   #10
Noix
A Fallenroot Satyr
Join Date: Oct 2014
Posts: 20
Originally Posted by Fizzlemizz View Post
You have two (or four?) sets of two images for tagert and player mana (and health?).

The player images you would just need to show on PLAYER_ENTERING_WORLD or ADDON_LOADED events and never hide and the target would show/hide on PLAYER_TARGET_CHANGED depending on UnitExists('target')
Sorry had to re-edit my post but no 2.

Left side is YOUR HEALTH - Right side is TARGET HEALTH. and its 2 images side my side
IE: for 98 ----- 9 = 1image ---- 8 = 1image (total of 2 images) but thats not issue tho.. its coding being use to display the images .. I have it set to show My MANA already (VIA: Power coding). its just i want to hide the image if .... A: Not in combat .... and show when i target someone (regardless if in combat or not.)
  Reply With Quote
04-30-15, 10:37 PM   #11
Noix
A Fallenroot Satyr
Join Date: Oct 2014
Posts: 20
See i did this code for 100%
function ()
if UnitExists("player", "target") and UnitHealth("target") > 0
then
return true
end
return false
end

Right now.. .When i'm not targeting anything it wont show anything. but as soon as i target a dummy it shows the 100% for my health (this includes in combat)
  Reply With Quote
04-30-15, 10:47 PM   #12
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
UnitExists only accepts one parameter so UnitExists("player", "target") is always going to return true. you need to handle them seperately.

Honestly you major problem lies further up the code chain and you won't get anywhere concentrating just on this function. We need to see more code.

Edit: It sounds like you want two seperate conditions
1: to hide player mana at 0 and show at anything else
2: to show target mana when a target is selected and hide it when the target is de-selected.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 04-30-15 at 10:53 PM.
  Reply With Quote
04-30-15, 11:00 PM   #13
Noix
A Fallenroot Satyr
Join Date: Oct 2014
Posts: 20
Originally Posted by Fizzlemizz View Post
UnitExists only accepts one parameter so UnitExists("player", "target") is always going to return true. you need to handle them seperately.

Honestly you major problem lies further up the code chain and you won't get anywhere concentrating just on this function. We need to see more code.

Edit: It sounds like you want two seperate conditions
1: to hide player mana at 0 and show at anything else
2: to show target mana when a target is selected and hide it when the target is de-selected.

Well see thing i dont understand. Health code is working just fine. but on mana side code (same code only change is UnitPower("player") is not working how i thought...


Targeting Healing dummy (it always shows 0-2 health)
Health Code for myself. (so atm shows i have 100% health.

function ()
if UnitExists("player", "target") and UnitHealth("target") > 0
then
return true
end
return false
end


Mana Code (i have 100% mana targeting dummy still) This again for myself
function ()
if UnitExists("player", "target") and UnitPower("player") > 0
then
return true
end
return false
end


Ok when i deselect "Healing dummy" health Texture (or coding that i posted) will make the Texture disapear. but the Mana one still stays on screen when it should do samething.

Sorry for late edit ..... If i change mana coding to
if UnitExists("player", "target") and UnitPower("target") > 0
it will never display at all unless the target has mana (Right) an i want it to track my mana not targets.

Last edited by Noix : 04-30-15 at 11:06 PM.
  Reply With Quote
04-30-15, 11:20 PM   #14
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Code:
function ()
    if UnitHealth("player") > 0 then -- the player always exists
        return true -- player health is > 0
    end
    return false -- player health is 0
end

function ()
    if UnitPower("player") > 0 then -- the player always exists
        return true -- player mana is > 0
    end
    return false -- player mana is 0
end

Code:
function ()
    if UnitExists("target") and UnitPower("target") > 0 then
        return true  -- target exists and target mana is > 0
    end
    return false  -- target does not exists or target mana is 0
end

function ()
    if UnitExists("target") and UnitHealth("target") > 0 then
        return true -- target exists and target health is > 0
    end
    return false  -- target does not exists or target health is 0
end
Pick the functions you need for mana or health for player or target.

Edit: UnitExists("player", "target") is the same as UnitExists("player") (will always return true).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 04-30-15 at 11:59 PM.
  Reply With Quote
04-30-15, 11:25 PM   #15
sirann
A Flamescale Wyrmkin
Join Date: Mar 2007
Posts: 142
Can you reexplain what exactly youre trying to do. You want to track your mana, if the player even has mana (dk's rogues, warriors, sometimes druids need not apply) if you're targeting something?

Lua Code:
  1. local f = CreateFrame('Frame', nil, UIParent)
  2. f:SetSize(25, 25)
  3. f:SetPoint('CENTER', UIParent, 'CENTER')
  4.  
  5. local text = f:CreateFontString(nil, 'OVERLAY')
  6. text:SetAllPoints()
  7. text:SetFont(PATHTOFONTHERE, 12, 'OUTLINEMONOCHROME')
  8. text:SetJustifyH('LEFT')
  9. text:SetJustifyV('BOTTOM')
  10.  
  11. f:RegisterEvent('PLAYER_TARGET_CHANGED')
  12. f:RegisterUnitEvent('UNIT_DISPLAYPOWER', 'player')
  13. local x
  14.  
  15. f:SetScript('OnEvent', function(self, event, ...)
  16.     if UnitPowerType('player') == 0 and UnitExists('target') then --player either shapeshifted and now has mana, and a target, or the player changed targets and has mana, show the texture
  17.         x = 100*(UnitPower('player')/UnitPowerMax('player')
  18.         x = format('%.0f%%', x)
  19.         text:SetText(x)
  20.     else
  21.         text:SetText('')
  22.     end
  23. end)

This will show your mana with a % sign if you have mana and a target.

Last edited by sirann : 04-30-15 at 11:36 PM.
  Reply With Quote
04-30-15, 11:53 PM   #16
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,322
Originally Posted by Noix View Post
I have it set to show My MANA already (VIA: Power coding). its just i want to hide the image if .... A: Not in combat .... and show when i target someone (regardless if in combat or not.)
So basically, show/hide based on combat and always show if you have a target. Do you want this for both health and mana displays? If so, just a single function should work for both.

Code:
function() return InCombatLockdown() or UnitExists("target"); end
Note this compresses the if...then block to a straight boolean return since this conditional is evaluating to boolean values anyway. InCombatLockdown() checks if you specifically are in combat. This is what determines if you are able to manipulate protected frames and is more reliable than using UnitAffectingCombat("player") since it also triggers when you proximity aggro something.

The logic behind this is to show if either condition is true, which falls in line with what was requested.





Originally Posted by sirann View Post
Can you reexplain what exactly youre trying to do.
He's trying to modify the behavior of an existing addon.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 05-01-15 at 12:13 AM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » LUA for Image spawn When targeting

Thread Tools
Display Modes

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