WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Classic - AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=179)
-   -   Classic Addon Questions (https://www.wowinterface.com/forums/showthread.php?t=57698)

Skimo 11-23-19 11:06 PM

Classic Addon Questions
 
So i've been trying to import 3d models by myself since weakauras classic no longer has the feature, and I'm speficially looking to have either movable (and lockable) or pre-positioned 3d models of my target and my player character loaded behind my player and target unitframes. I have loaded the player/target models no problem, but as far as i'm aware they aren't being updated, so the target only appears when I manually run the script in-game when targetting something. On to the questions:

1. How can I make my player model update when I change gear, or even change animations in a combat event?

2. How can I make my target model update when I switch targets, or disappear when I have no target?

bonus points: Is there anyway to cutoff the model at the waist, so only the top half of my character is displayed above the unitframe?

If you have any suggestions on how I could answer some of these questions, I'd love to hear them. I am new to programming altogether so I may ask for clarification!! Thanks!!

Skimo 11-23-19 11:09 PM

I forgot to include what I have so far, here it is!


local model = CreateFrame("PlayerModel", nil, UIParent)
model:SetSize(150, 200)
model:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
model:SetUnit("player")
model:SetCamera(2)
model:SetFacing(30)
model:RefreshCamera()
model:Show()

local model = CreateFrame("PlayerModel", nil, UIParent)
model:SetSize(150, 200)
model:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
model:SetUnit("target")
model:SetCamera(2)
model:RefreshCamera()
model:Show()

Fizzlemizz 11-24-19 12:12 AM

Something like:
Lua Code:
  1. local units = {}
  2. units.player = CreateFrame("PlayerModel", nil, UIParent)
  3. units.player:SetSize(150, 200)
  4. units.player:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  5. units.player:SetUnit("player")
  6. units.player:SetCamera(2)
  7. units.player:SetFacing(30)
  8. units.player:RefreshCamera()
  9. units.player:Show()
  10.  
  11. units.target = CreateFrame("PlayerModel", nil, UIParent)
  12. units.target:SetSize(150, 200)
  13. units.target:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  14. units.target:SetUnit("target")
  15. units.target:SetCamera(2)
  16. units.target:RefreshCamera()
  17. units.target:Show()
  18.  
  19. units.target:SetScript("OnEvent", function(self, event, ...)
  20.     if event == "PLAYER_TARGET_CHANGED" then
  21.         if UnitExists("target") then
  22.             self:SetUnit("target")
  23.             self:Show()
  24.         else
  25.             self:Hide()
  26.         end
  27.         return
  28.     end
  29.     local unit = ...
  30.     local unitframe = units[unit]
  31.     if unitframe then
  32.         unitframe:SetUnit(unit)
  33.     end
  34. end)
  35.  
  36. units.target:RegisterEvent("UNIT_MODEL_CHANGED")
  37. units.target:RegisterEvent("UNIT_PORTRAIT_UPDATE")
  38. units.target:RegisterEvent("PLAYER_TARGET_CHANGED")
The target frame traps the events for both models and checks against the unit parameter (for the UNIT_ events) for which one is being effected by the event then looks up the units table to find if and which frame to update.

You can use the model:SetPortraitZoom() and SetPosition() methods zoom/move the model within the frame.

Skimo 11-24-19 12:47 AM

Quote:

Originally Posted by Fizzlemizz (Post 334645)
Something like:
Lua Code:
  1. local units = {}
  2. units.player = CreateFrame("PlayerModel", nil, UIParent)
  3. units.player:SetSize(150, 200)
  4. units.player:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  5. units.player:SetUnit("player")
  6. units.player:SetCamera(2)
  7. units.player:SetFacing(30)
  8. units.player:RefreshCamera()
  9. units.player:Show()
  10.  
  11. units.target = CreateFrame("PlayerModel", nil, UIParent)
  12. units.target:SetSize(150, 200)
  13. units.target:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  14. units.target:SetUnit("target")
  15. units.target:SetCamera(2)
  16. units.target:RefreshCamera()
  17. units.target:Show()
  18.  
  19. units.target:SetScript("OnEvent", function(self, event, ...)
  20.     if event == "PLAYER_TARGET_CHANGED" then
  21.         if UnitExists("target") then
  22.             self:SetUnit("target")
  23.             self:Show()
  24.         else
  25.             self:Hide()
  26.         end
  27.         return
  28.     end
  29.     local unit = ...
  30.     local unitframe = units[unit]
  31.     if unitframe then
  32.         unitframe:SetUnit(unit)
  33.     end
  34. end)
  35.  
  36. units.target:RegisterEvent("UNIT_MODEL_CHANGED")
  37. units.target:RegisterEvent("UNIT_PORTRAIT_UPDATE")
  38. units.target:RegisterEvent("PLAYER_TARGET_CHANGED")
The target frame traps the events for both models and checks against the unit parameter (for the UNIT_ events) for which one is being effected by the event then looks up the units table to find if and which frame to update.

You can use the model:SetPortraitZoom() and SetPosition() methods zoom/move the model within the frame.


Oh my god! Fizzlemizz, you are seriously my inspiration for addon dev to begin with!! I’ve been using DUF for a lot of my UI projects for such a long time. I honestly couldn’t have asked for a better response from a better person. To be honest, I thought about reaching out to you with my questions but I didn’t want to bother you. Thanks so much for taking the time to reply. I’ll hit the drawing board with this new info, thanks a ton!


All times are GMT -6. The time now is 09:32 PM.

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