• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How get the information of an item just with the type-id? (Or at least help me with the function)

Status
Not open for further replies.
Level 24
Joined
Jun 26, 2020
Messages
1,852
Hello, I'm creating a save-load system, also a menu for that, it shows what items have, for the charged items I wanna also show how many charges have, the thing is I don't know how to get if a item is charged only with the type-id so I opted to create the item for get that information, the thing is (I just notice it now) where I create the item is in a if player == GetLocalPlayer() then block causing a desync, and it would be a mess put it outside, unless you have a better solution, this is the function:
Lua:
-- This function always should be in a "if player == GetLocalPlayer() then" block
local function UpdateInformation()
    local data = PlayerDatas[LocalPlayer][Pressed[LocalPlayer]]
    if data then
        BlzFrameSetText(TooltipName, "|cffff6600Information|r")
        BlzFrameSetText(TooltipGold, "|cffFFCC00Gold: |r" .. data.gold)
        BlzFrameSetText(TooltipLumber, "|cff20bc20Lumber: |r" .. data.lumber)
        for i = 1, #data.digimons do
            local s = ""
            local inv = data.inventories[i]
            for j = 0, 5 do
                if inv.items[j] then
                    local m = CreateItem(inv.items[j], 0, 0) -- I don't know how to get the name and the class with only the type id
                    s = s .. GetItemName(m)
                    if GetItemType(m) == ITEM_TYPE_CHARGED then
                        s = s .. "(" .. inv.charges[j] .. ")"
                    end
                    RemoveItem(m)
                    if j ~= 5 then
                        s = s .. ", "
                    end
                end
            end
            BlzFrameSetText(TooltipDigimonItemsT[i-1], "|cff00ffffItems: |r" .. s)
            BlzFrameSetTexture(TooltipDigimonIconT[i-1], BlzGetAbilityIcon(data.digimons[i]), 0, true)
            BlzFrameSetText(TextTooltipLevelT[i-1], "|cffFFCC00Level " .. data.levels[i] .. "|r")
        end
    else
        BlzFrameSetText(TooltipName, "|cffff6600Empty|r")
        BlzFrameSetText(TooltipGold, "|cffFFCC00Gold:|r")
        BlzFrameSetText(TooltipLumber, "|cff20bc20Lumber:|r")
        for i = 0, 5 do
            BlzFrameSetText(TooltipDigimonItemsT[i], "|cff00ffffItems:|r")
            BlzFrameSetTexture(TooltipDigimonIconT[i], "ReplaceableTextures\\CommandButtons\\BTNCancel.blp", 0, true)
            BlzFrameSetText(TextTooltipLevelT[i], "|cffFFCC00Level 0|r")
        end
    end
end
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,537
Like what Avahor said, you can preload all of the items at the start of the game and store information about them using tables. Something like this:
Lua:
itemType = {
    classification = {},
    baseCharges = {},
    maxCharges = {}
}

function ItemTypeAdd(id)
    local m = CreateItem(id, 0, 0)
    itemType[id].classification = GetItemType(m)
    itemType[id].baseCharges = GetItemBaseCharges(m) -- not the real function
    itemType[id].maxCharges = GetItemMaxCharges(m)   -- not the real function
    RemoveItem(m)
end

function ItemTypeInit()
    ItemTypeAdd(FourCC('bspd')) -- boots of speed
    ItemTypeAdd(FourCC('wlsd')) -- wand of lightning shield
    -- etc
end
 
Status
Not open for further replies.
Top