Quantcast Classic Addon Questions - WoWInterface
Thread Tools Display Modes
11-23-19, 11:06 PM   #1
Skimo
A Murloc Raider
 
Skimo's Avatar
Join Date: Sep 2019
Posts: 5
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!!
  Reply With Quote
11-23-19, 11:09 PM   #2
Skimo
A Murloc Raider
 
Skimo's Avatar
Join Date: Sep 2019
Posts: 5
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()
  Reply With Quote
11-24-19, 12:12 AM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,215
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.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 11-24-19 at 12:23 AM.
  Reply With Quote
11-24-19, 12:47 AM   #4
Skimo
A Murloc Raider
 
Skimo's Avatar
Join Date: Sep 2019
Posts: 5
Originally Posted by Fizzlemizz View Post
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!
  Reply With Quote

WoWInterface » Classic - AddOns, Compliations, Macros » Classic - AddOn Help/Support » Classic Addon Questions

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