Thread Tools Display Modes
11-28-15, 06:10 AM   #1
Endzeit
A Deviate Faerie Dragon
Join Date: Aug 2015
Posts: 12
C_Garrison.GetFollowers(2)

Hello,

i want to track all my Ships with classNames. Everytime i go the Shipyard i want a print in chat like:
# Transporter: 1
# Destroyer: 2
# Total: 3/10

Lua Code:
  1. GossipFrame:SetScript( "OnShow", function()
  2. if UnitName("target") == "Solog Roark" then
  3.     local destroyer = 0 -- id59
  4.     local schlachtschiff = 0 --id56
  5.     local uboot = 0 --id62
  6.     local traeger = 0 --id60
  7.     local transporter = 0 --id58
  8.     local ships = C_Garrison.GetFollowers(2)
  9.         for k,_ in ipairs(ships) do
  10.      if ships[k].classSpec == 59 then destroyer = destroyer + 1; end
  11.     if ships[k].classSpec == 56 then schlachtschiff = schlachtschiff + 1; end
  12.     if ships[k].classSpec == 62 then uboot = uboot + 1; end
  13.     if ships[k].classSpec == 60 then traeger = traeger + 1; end
  14.     if ships[k].classSpec == 58 then transporter = transporter + 1; end
  15.         end
  16.   print("Destroyer: " .. destroyer)
  17.   print("Schlachtschiff: " .. schlachtschiff)
  18.     print("uboot: " .. uboot)
  19.     print("traeger: " .. traeger)
  20.         print("transporter: " .. transporter)
  21. end
  22. end)

Ship Builder is working.

Shipyard Table not:

Error:
Code:
Message: Interface\AddOns\Endzeit\modules\ships.lua:26: attempt to index global 'GarrisonShipyardFrame' (a nil value)
Time: 11/28/15 15:09:11
Count: 1
Stack: Interface\AddOns\Endzeit\modules\ships.lua:26: in main chunk

Locals: (*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index global 'GarrisonShipyardFrame' (a nil value)"
Code:
Lua Code:
  1. GarrisonShipyardFrame:SetScript( "OnShow", function()
  2.     local destroyer = 0 -- id59
  3.     local schlachtschiff = 0 --id56
  4.     local uboot = 0 --id62
  5.     local traeger = 0 --id60
  6.     local transporter = 0 --id58
  7.     local ships = C_Garrison.GetFollowers(2)
  8.         for k,_ in ipairs(ships) do
  9.      if ships[k].classSpec == 59 then destroyer = destroyer + 1; end
  10.     if ships[k].classSpec == 56 then schlachtschiff = schlachtschiff + 1; end
  11.     if ships[k].classSpec == 62 then uboot = uboot + 1; end
  12.     if ships[k].classSpec == 60 then traeger = traeger + 1; end
  13.     if ships[k].classSpec == 58 then transporter = transporter + 1; end
  14.         end
  15.   print("Destroyer: " .. destroyer)
  16.   print("Schlachtschiff: " .. schlachtschiff)
  17.     print("uboot: " .. uboot)
  18.     print("traeger: " .. traeger)
  19.         print("transporter: " .. transporter)
  20. end)

Last edited by Endzeit : 11-28-15 at 08:10 AM.
  Reply With Quote
11-28-15, 12:44 PM   #2
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
The GarrisonShipyardFrame doesn't exist until the Blizzard_GarrisonUI is loaded, so your AddOn should have this in its ToC file:

Code:
## LoadOnDemand: 1
## LoadsWith: Blizzard_GarrisonUI
Additionally, your code's formatting makes it difficult to understand and you should be using an if-elseif chain so you aren't checking for matches after you've already found one. This isn't exactly how I'd write it, but since I just woke up here's a slightly cleaned up version:

lua Code:
  1. GossipFrame:SetScript( "OnShow", function()
  2.     if UnitName("target") == "Solog Roark" then
  3.         local destroyer = 0 -- id59
  4.         local schlachtschiff = 0 --id56
  5.         local uboot = 0 --id62
  6.         local traeger = 0 --id60
  7.         local transporter = 0 --id58
  8.         local ships = C_Garrison.GetFollowers(2)
  9.  
  10.         for k,_ in ipairs(ships) do
  11.             local classSpec = ships[k].classSpec
  12.  
  13.             if classSpec == 59 then
  14.                 destroyer = destroyer + 1
  15.             elseif classSpec == 56 then
  16.                 schlachtschiff = schlachtschiff + 1
  17.             elseif classSpec == 62 then
  18.                 uboot = uboot + 1
  19.             elseif classSpec == 60 then
  20.                 traeger = traeger + 1
  21.             elseif classSpec == 58 then
  22.                 transporter = transporter + 1
  23.             end
  24.         end
  25.  
  26.         print("Destroyer: " .. destroyer)
  27.         print("Schlachtschiff: " .. schlachtschiff)
  28.         print("uboot: " .. uboot)
  29.         print("traeger: " .. traeger)
  30.         print("transporter: " .. transporter)
  31.     end
  32. end)
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
11-28-15, 04:46 PM   #3
Endzeit
A Deviate Faerie Dragon
Join Date: Aug 2015
Posts: 12
i change some code and try to formate better.. this is working so far. There is no event for Opening Garrison Table or?


Lua Code:
  1. function CheckShipyard(self)
  2.     local Destroyer = 0 -- id59
  3.     local Battleship = 0 --id56
  4.     local Submarine = 0 --id62
  5.     local Carrier = 0 --id60
  6.     local Transport = 0 --id58
  7.     local ships = C_Garrison.GetFollowers(2)
  8.     local _,_,_,_,_,rank = C_Garrison.GetOwnedBuildingInfo(98)
  9.     local maxfollower = 0
  10.     local activefollower = C_Garrison.GetNumFollowers(2)
  11.    
  12.     if rank == 1 then
  13.         maxfollower = 6
  14.     elseif rank == 2 then
  15.         maxfollower = 8
  16.     elseif rank == 3 then
  17.         maxfollower = 10
  18.     end
  19.    
  20.         for k,_ in ipairs(ships) do
  21.         local classSpec = ships[k].classSpec
  22.             if classSpec == 58 then
  23.                 Transport = Transport + 1
  24.             elseif classSpec == 59 then
  25.                 Destroyer = Destroyer + 1
  26.             elseif classSpec == 56 then
  27.                 Battleship = Battleship + 1
  28.             elseif classSpec == 62 then
  29.                 Submarine = Submarine + 1
  30.             elseif classSpec == 60 then
  31.                 Carrier = Carrier + 1
  32.             end
  33.         end
  34.        
  35.     local color = {
  36.     { r=1, g=0, b=0,}, --red
  37.     { r=1, g=1, b=0,}, --yellow
  38.     { r=0, g=1, b=0,}, --green
  39.     { r=0, g=1, b=0,}, --green
  40.     { r=0, g=1, b=0,}, --green
  41.     { r=0, g=1, b=0,}, --green
  42.     }
  43.         DEFAULT_CHAT_FRAME:AddMessage(" ");
  44.         DEFAULT_CHAT_FRAME:AddMessage("# |TInterface\\ICONS\\inv_garrison_cargoship.blp:12|t " ..           "Transport: " .. Transport, color[Transport+1].r, color[Transport+1].g, color[Transport+1].b);
  45.         DEFAULT_CHAT_FRAME:AddMessage("# |TInterface\\ICONS\\ships_ability_depthcharges.blp:12|t " ..       "Destroyer: " .. Destroyer, color[Destroyer+1].r, color[Destroyer+1].g, color[Destroyer+1].b);
  46.         DEFAULT_CHAT_FRAME:AddMessage("# |TInterface\\ICONS\\ships_ability_armorpiercingammo.blp:12|t " ..  "Battleship: " .. Battleship, color[Battleship+1].r, color[Battleship+1].g, color[Battleship+1].b);
  47.         DEFAULT_CHAT_FRAME:AddMessage("# |TInterface\\ICONS\\ships_ability_stealth.blp:12|t " ..            "Submarine: " .. Submarine, color[Submarine+1].r, color[Submarine+1].g, color[Submarine+1].b);
  48.         DEFAULT_CHAT_FRAME:AddMessage("# |TInterface\\ICONS\\ships_ability_bombers.blp:12|t " ..            "Carrier: " .. Carrier, color[Carrier+1].r, color[Carrier+1].g, color[Carrier+1].b);
  49.         if activefollower < maxfollower then
  50.         DEFAULT_CHAT_FRAME:AddMessage("# |TInterface\\DialogFrame\\UI-Dialog-Icon-AlertNew.png:12|t Total: " .. activefollower .. "/" .. maxfollower, 1, 0, 0);
  51.         else
  52.         DEFAULT_CHAT_FRAME:AddMessage("# |TInterface\\RAIDFRAME\\ReadyCheck-Ready.png:12|t Total: " .. activefollower .. "/" .. maxfollower, 0, 1, 0);
  53.         end
  54.         DEFAULT_CHAT_FRAME:AddMessage(" ");    
  55. end
  56.  
  57. local a = CreateFrame( "Frame" )
  58. a:RegisterEvent("ZONE_CHANGED_NEW_AREA")
  59. a:RegisterEvent("GOSSIP_SHOW")
  60. a:RegisterEvent("PLAYER_ENTERING_WORLD")
  61. a:RegisterEvent("GARRISON_FOLLOWER_ADDED")
  62. a:RegisterEvent("GARRISON_FOLLOWER_REMOVED")
  63. a:SetScript( "OnEvent", function( self, event )
  64. local areaid = GetCurrentMapAreaID();
  65. if ((event == "ZONE_CHANGED_NEW_AREA") or (event == "PLAYER_ENTERING_WORLD")) and ((areaid == 976) or (areaid == 941)) then
  66.     CheckShipyard()
  67. end
  68.  
  69. if (event == "GOSSIP_SHOW") and UnitName("target") == "Solog Roark" then
  70.     CheckShipyard()
  71. end
  72.  
  73. if (event == "GARRISON_FOLLOWER_ADDED")  then
  74.     CheckShipyard()
  75. end
  76. if (event == "GARRISON_FOLLOWER_REMOVED") then
  77.     CheckShipyard()
  78. end
  79. end)

my color table is not perfekt.. but i dont know how it makes better.
With 0 ships = red
With 1 ships = yellow
with 2+ ships = green
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » C_Garrison.GetFollowers(2)


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