Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GUI - Label Width and displaying Label + Figure. item.count function
#1
Have played around with the Wiki sample and using the post here http://www.mmominion.com/Thread-Problem-...3#pid35673 I was able to get it going.

Trying to create a module for practice to List out fish I select and how many I have in my inventory.

Displays to console correctly. However it does not seem to count a full stack + X instead it only counts the number in an uncompleted stack. for example I have 100 Fullmoon Sardines yet it only counts it as 1.

Also I'm having trouble getting it to generate the label + Number field like in the sample. I can only get it to display both if I concatenate them together and then I can't see it all because the field size is limited in the display. Any Way to increase the field size?

Help would be appreciated.

Code:
-- Create a new table for our code:
fishmanager= { }
-- Some local variables we use in our module:
fishmanager.running = false
fishmanager.lastticks = 0
fishmanager.fishCount = "0"



-- Whitelist fish // to convert to inbuilt whitelist / blacklist system
fishmanager.Whitelist = {
["Silver Shark"] = 4903,
["Fullmoon Sardine"] = 4898,
["HammerHead Shark"] = 4893
}

-- Initializing function, we create a new Window for our module that has 1 button and 1 field to display data:
function fishmanager.ModuleInit()
    GUI_NewWindow("fishmanager",50,50,100,10);
    GUI_NewButton("fishmanager","Turn On or Off","fishmanager.TOGGLE");
   -- GUI_NewField("fishmanager","Fish Name","My Fish :","FishList"); -- In order to display the value of this field, it must be a part of a group ("HitPoints").
    GUI_SizeWindow("fishmanager",550,450) -- This line currently required in order to properly resize and display the window. GUI_NewWindow is a little broken right now.
end

-- The function that gets called when the button is pressed:
function fishmanager.ToggleRun()
    fishmanager.running = not fishmanager.running
end

--Function to locatefish in inventory eg local item= Inventory:Get(4903)  == Silver Shark here uses Whitelist
function fishmanager.invsearch(fishName , fishID)
    local item= Inventory:Get(fishID)
        if ( item and item.count~= 0 ) then
            d("ItemID. " ..tostring(item.id))
            d("ItemName. "..item.name )
            d("ItemCount. " ..item.count)
        --    d("Shits and Giggles")

            fishmanager.fishNamelabel = tostring(item.name)
            fishmanager.fishCount = tostring(item.count)
            GUI_NewField("fishmanager", fishmanager.fishNamelabel .. " " .. fishmanager.fishCount , "Fish List")

        end

end

-- Function to udate gui list
-- If fish is whitelisted and no longer <=0 then add to fishlist in GUI
-- function fishmanager.fishlist(fishName , fishcount)
--     GUI_NewField("fishmanager",fishname,fishcount,"FishList");

-- end


-- The Mainloop function, gets called all the time by FFXIVMinion:
function fishmanager.OnUpdateHandler( Event, ticks )
-- checks if module is running and updates every approx 10 sec.
    if ( fishmanager.running and ticks - fishmanager.lastticks > 10000 ) then
        fishmanager.lastticks = ticks

-- display current inventory items of type X in console Window:
        --     fishmanager.invsearch(4903)
--            for fishName, fishID in pairs(fishmanager.Whitelist) do
--                fishmanager.invsearch(fishName , fishID)
--            end
--    end
--end

-- display current inventory items of type X in console Window:
        --     fishmanager.invsearch(4903)
            for fishName, fishID in pairs(fishmanager.Whitelist) do
                fishmanager.invsearch(fishName , fishID)
            end
    end
end




-- Registering the Event RegisterEventHandler("GUI.Update",MyModule.GUIVariableChanged)

RegisterEventHandler("Gameloop.Update",fishmanager.OnUpdateHandler) -- the normal pulse from the gameloop
RegisterEventHandler("fishmanager.TOGGLE", fishmanager.ToggleRun) -- the function that gets called when our button is pressed
RegisterEventHandler("Module.Initalize",fishmanager.ModuleInit) -- the initialization function, gets called only once at startup of the game
Reply
#2
Im not a coder but the task master has a working item count feature if you want to check that.
Reply
#3
Have managed to make some progress but still not sure how to nail the totals and have them display and update.

Simple Module attached.
Does not Count HQ items eg (Silver Sharks) perhaps HQ fish have different ID but Not sure how to Find it. (will look into this)

Can get console to add the total stacks eg. Full moon sardines on second find add to total to 100 (99+1 in stacks).

Can't get correct Numbers to show in GUI always shows value for last fish counted.. eg Hammerheads.


Learning a lot playing with this but further help would be appreciated.

[Image: fishmanager.jpg]

Sure enough need to add 100 in front of IDs for HQ eg. 1004903 HQ silver Shark 4903 normal shark.
Reply
#4
Inventory:Get(xxxx) only returns a single item (inventory slot). Inventory("itemid=xxxx") returns a table with however many stacks it found.
You'll need to add them up yourself.

Does that help?

Code:
local inv= Inventory("itemid="..fishID)
    if (inv) then
        for k,item in pairs(inv) do
            d("------------"..item.name..": "..item.count)
        end
    end


how did you get the GUI field to size correctly?

-Andrew
Reply
#5
To expand drewlt's answer:

Code:
local total = 0
local inv = Inventory("itemid="..fishID)
if (inv) then
  for k,item in pairs(inv) do
    total = total + item.count
  end
  d("------------"..fishName..": "..total)
  fishmanager.fishNamelabel = fishName
  fishmanager.fishCount = tostring(total)
end

I think that's pretty close to what you're looking for.
Reply
#6
Code:
function ItemCount(itemid)
    local itemcount = 0
    
    --Look through regular bags first.
    for x=0,3 do
        local inv = Inventory("type="..tostring(x))
        for i, item in pairs(inv) do
            if (item.id == itemid) then
                itemcount = itemcount + item.count
            end
        end
    end
    
    --Look through equipped items bag.
    local inv = Inventory("type=1000")
    for i, item in pairs(inv) do
        if (item.id == itemid) then
            itemcount = itemcount + 1
        end
    end
    
    --Look through armory bags for off-hand through wrists
    for x=3200,3209 do
        local inv = Inventory("type="..tostring(x))
        for i, item in pairs(inv) do
            if (item.id == itemid) then
                itemcount = itemcount + 1
            end
        end
    end
    
    --Look through rings armory bag.
    local inv = Inventory("type=3300")
    for i, item in pairs(inv) do
        if (item.id == itemid) then
            itemcount = itemcount + 1
        end
    end
    
    --Look through soulstones armory bag.
    local inv = Inventory("type=3400")
    for i, item in pairs(inv) do
        if (item.id == itemid) then
            itemcount = itemcount + 1
        end
    end
    
    --Look through weapons armory bag.
    local inv = Inventory("type=3500")
    for i, item in pairs(inv) do
        if (item.id == itemid) then
            itemcount = itemcount + 1
        end
    end
    
    --Look through quest/key items bag.
    local inv = Inventory("type=2004")
    for i, item in pairs(inv) do
        if (item.id == itemid) then
            itemcount = itemcount + item.count
        end
    end
    
    return itemcount
end

This is an expanded version I use for misc inventory item counting. For fishing you really only need the first loop, but the main ffxivminion module will use this version (and I believe already uses one with basic inventory counting). You can use the code below to test:

Code:
d(ItemCount(itemid))
Reply
#7
Thank you all for the feedback. I'll give this all a try :-)
Reply
 


Forum Jump:


Users browsing this thread: 2 Guest(s)

We help you win the game.

FFXIV Bot and More.

 

Products