Craft Addon

Language: JP EN DE FR
New Items
2023-11-19
users online
Forum » Windower » Support » Craft addon
Craft addon
 Carbuncle.Gabvanstronger
Offline
Server: Carbuncle
Game: FFXI
Posts: 48
By Carbuncle.Gabvanstronger 2020-04-16 03:17:51
Link | Quote | Reply
 
Hey guys,

I'm discovering the Windower Craft addon and I really enjoy it. But there's something that itches me :

I've been adding info to the recipe file so that when I write //craft find "this", I know the synth type and lvl. This lets me know when I can craft the Bat Wings, Pebble and Hare Meat of this world without always opening ffxiclopedia of bg-wiki before npc'ing them. But I realised that it only looks for recipe NAMES and not ingredient.

For example : //craft find "Revival Root" gives no result even though they're ingredients of Bloody Blade or Bloody Bolt Head (to name a few).

I've been poking around the lua to make it search for ingredients too but I don't know what I'm doing, I have no knowledge of coding or anything but I'd love this "ingame notebook" to work !
I didn't break my addon yet, but I'd love if someone knew a magic luacode to make it search for ingredients too !

I had a hunch that the thing to add would go somewhere near :
Code
local function handle_find(query, details)
    local query = query:lower()
    notice("Searching for recipes containing %s":format(query))
    for name, recipe in pairs(recipes) do
        if string.find(name:lower(), query) then
            notice("Found recipe - \"%s\"":format(name))
            if details then
                notice(" %s":format(recipe['crystal']))
                for _, ingredient in pairs(recipe['ingredients']) do
                    notice("  %s":format(ingredient))
                end
            end
        end
    end
end


Thaaaanks !
 Bismarck.Xurion
Offline
Server: Bismarck
Game: FFXI
user: Xurion
Posts: 693
By Bismarck.Xurion 2020-04-16 04:18:38
Link | Quote | Reply
 
Probably a different command separate from the existing one:
Code
local function handle_find_by_ingredient(query)
    local query = query:lower()
    notice("Searching all ingredients containing %s":format(query))
    for name, recipe in pairs(recipes) do
        for _, ingredient in pairs(recipe['ingredients']) do
            if string.find(ingredient:lower(), query)
                notice("%s contains %s":format(name, ingredient))
            end
        end
    end
end


Be aware, if you modify your copy, any update from the Windower repo will overwrite it.
 Carbuncle.Gabvanstronger
Offline
Server: Carbuncle
Game: FFXI
Posts: 48
By Carbuncle.Gabvanstronger 2020-04-16 11:56:13
Link | Quote | Reply
 
Ok, i'll keep a copy of my recipe.lua I guess :o
Looks like it doesn't work. I still get
Quote:
craft Notice: Searching for recipes containing revival root
(It misses a then at line 6, which I added: otherwise, I get
Quote:
craft: Lua syntax error: craft/craft.lua:746: 'then' expected near 'notice'
)
Code
local function handle_find(query, details)
    local query = query:lower()
    notice("Searching for recipes containing %s":format(query))
    for name, recipe in pairs(recipes) do
        if string.find(name:lower(), query) then
            notice("Found recipe - \"%s\"":format(name))
            if details then
                notice(" %s":format(recipe['crystal']))
                for _, ingredient in pairs(recipe['ingredients']) do
                    notice("  %s":format(ingredient))
                end
            end
        end
    end
    for ingredient, recipe in pairs(recipes) do
        if string.find(ingredient:lower(), query) then
            notice("Found ingredient - \"%s\"":format(ingredient))
            if details then
                notice(" %s":format(recipe['crystal']))
                for _, ingredient in pairs(recipe['ingredients']) do
                    notice("  %s":format(ingredient))
                end
            end
        end
    end
end


I tried that, still doesnt work. I don't know what "%s" refers to.
(Sorry for my unknowledge ... xD )

Thanks a lot for your time !
 Bismarck.Xurion
Offline
Server: Bismarck
Game: FFXI
user: Xurion
Posts: 693
By Bismarck.Xurion 2020-04-16 18:38:02
Link | Quote | Reply
 
I replaced my handle_find function with your code and it worked without error.

%s is basically string replacement. So in the following string, the two %s occurrences are replaced with Xurion and Bismarck:
"Hi I'm %s from %s":format('Xurion', 'Bismarck')

If you want this to be part of the regular search, then try this:
Code
local function handle_find(query, details)
    local query = query:lower()
    notice("Searching for recipes containing %s":format(query))
    for name, recipe in pairs(recipes) do
        if string.find(name:lower(), query) then
            notice("Found recipe - \"%s\"":format(name))
            if details then
                notice(" %s":format(recipe['crystal']))
                for _, ingredient in pairs(recipe['ingredients']) do
                    notice("  %s":format(ingredient))
                end
            end
        end
        for _, ingredient in pairs(recipe['ingredients']) do
            if string.find(ingredient:lower(), query) then
                notice('Found ingredient - "%s" in %s':format(ingredient, name))
            end
        end
    end
end


Results in:

[+]
 Carbuncle.Gabvanstronger
Offline
Server: Carbuncle
Game: FFXI
Posts: 48
By Carbuncle.Gabvanstronger 2020-04-16 22:43:43
Link | Quote | Reply
 
This is perfect, it works just as I hoped !
Now I get :


Though I realize some ingredients are in a lot of recipe, such as "ingot".. Hehe. This should be fun !

Thank you very much ^^
[+]
Log in to post.