daemitus / SomethingNeedDoing

92 stars 67 forks source link

Trying to figure out Lua script #85

Open Ditziv opened 2 years ago

Ditziv commented 2 years ago

I'm not sure where else to ask - is there any example of a working Lua script with conditional logic in there? I'm trying the following to test stuff out but to no avail. I'd appreciate any help to get started.

if (HasStatus(Meal Benefits))
then
else
yield('/send 9')
end 

I'm a JS dev, no experience with Lua, but i'd like to be able to have SND eat some food if the buff has run out if possible please? This is all i've got so far - i am still not sure on how to integrate this in to a working crafting script either. Thanks for any help!

daemitus commented 2 years ago

Your meal benefits needs to be quoted. and the specific name of the food buff, i.e. "Medicated" for potions. the /send command needs to be one of the virtualkey enums. So it should probably be "/send KEY_9"

https://github.com/goatcorp/Dalamud/blob/net5/Dalamud/Game/ClientState/Keys/VirtualKey.cs I think I added a /send menu in the help window.

On Fri, Jul 29, 2022 at 10:08 AM althaiaDev @.***> wrote:

I'm not sure where else to ask - is there any example of a working Lua script with conditional logic in there? I'm trying the following to test stuff out but to no avail. I'd appreciate any help to get started.

if (HasStatus(Meal Benefits)) then else yield('/send 9') end

I'm a JS dev, no experience with Lua, but i'd like to be able to have SND eat some food if the buff has run out if possible please? This is all i've got so far - i am still not sure on how to integrate this in to a working crafting script either. Thanks for any help!

— Reply to this email directly, view it on GitHub https://github.com/daemitus/SomethingNeedDoing/issues/85, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFMTBAI2PMXH5SN6IPNFH3VWPQVNANCNFSM55A4JA3A . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Ditziv commented 2 years ago

Thanks for the prompt response. One quick followup - does every action macro line need to be enclosed in yield?

i.e. /ac "Muscle Memory" <wait.2s>

daemitus commented 2 years ago

to send it back to the macro processor, yes. The entire macro is wrapped inside an async function, yield is just an alias for lua's coroutine.yield method.

On Fri, Jul 29, 2022 at 10:39 AM althaiaDev @.***> wrote:

Thanks for the prompt response. One quick followup - does every action macro line need to be enclosed in yield?

i.e. /ac "Muscle Memory"

— Reply to this email directly, view it on GitHub https://github.com/daemitus/SomethingNeedDoing/issues/85#issuecomment-1199420137, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFMTBGRRN65FAJOLGGRK7TVWPUKTANCNFSM55A4JA3A . You are receiving this because you commented.Message ID: @.***>

daemitus commented 2 years ago

you'll also want to drop the s on 2s. is sufficient.

On Fri, Jul 29, 2022 at 10:42 AM Raymond Lynch @.***> wrote:

to send it back to the macro processor, yes. The entire macro is wrapped inside an async function, yield is just an alias for lua's coroutine.yield method.

On Fri, Jul 29, 2022 at 10:39 AM althaiaDev @.***> wrote:

Thanks for the prompt response. One quick followup - does every action macro line need to be enclosed in yield?

i.e. /ac "Muscle Memory"

— Reply to this email directly, view it on GitHub https://github.com/daemitus/SomethingNeedDoing/issues/85#issuecomment-1199420137, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFMTBGRRN65FAJOLGGRK7TVWPUKTANCNFSM55A4JA3A . You are receiving this because you commented.Message ID: @.***>

Ditziv commented 2 years ago

Thank you! This is what I've got so far and it returned: [SND] Failure while running script: [string "chunk"]:28: ')' expected near 'within'

-- /requirestats 3684 3874 681
-- Checks for Food buff, if not then presses hotbar assigned to 9
if (HasStatus("Meal Benefits"))
then
else
yield('/send KEY_9')
end

-- Checks for Pot buff, if not then presses hotbar assigned to 0
if (HasStatus("Medicated"))
then
else
yield('/send KEY_0')
end

-- Checks for repairability, then extracts materia if applicable.
if (NeedsRepair())
then
yield('/click repair_all')
else
end

-- ASSUMES YOU HAVE "Yes Already" ENABLED FOR MATERIA EXTRACT
if(CanExtractMateria(float within = 100))
then
yield('/click retrieve_materia_begin')
yield('/click retrieve_materia_return')
else
end

-- Finds recipe 
yield('/recipe Grade 4 Artisanal Skybuilders' Company Chest') -- ADD RECIPE NAME HERE

--Crafts
yield('/craft 10')

--Craft Macro
yield('/ac "Muscle Memory" <wait.3>')
yield('/ac Manipulation <wait.2>')
yield('/ac "Final Appraisal" <wait.2>')
yield('/ac Veneration <wait.2>')
yield('/ac "Waste Not" <wait.2>')
yield('/ac Groundwork <wait.3>')
yield('/ac Groundwork <wait.3>')
yield('/ac "Final Appraisal" <wait.2>')
yield('/ac "Careful Synthesis" <wait.3>')
yield('/ac "Heart and Soul" <wait.3>')
yield('/ac "Precise Touch" <wait.3>')
yield('/ac Innovation <wait.2>')
yield('/ac "Basic Touch" <wait.3>')
yield('/ac "Standard Touch" <wait.3>')
yield('/ac "Advanced Touch" <wait.3>')
yield('/ac "Prudent Touch" <wait.3>')
yield('/ac Manipulation <wait.2>')
yield('/ac Innovation <wait.2>')
yield('/ac "Prudent Touch" <wait.3>')
yield('/ac "Basic Touch" <wait.3>')
yield('/ac "Standard Touch" <wait.3>')
yield('/ac "Advanced Touch" <wait.3>')
yield('/ac "Great Strides" <wait.2>')
yield('/ac Innovation <wait.2>')
yield('/ac Observe <wait.3>')
yield('/ac "Focused Touch" <wait.3>')
yield('/ac "Great Strides" <wait.2>')
yield('/ac "Byregot's Blessing" <wait.3>')
yield('/ac "Basic Synthesis" <wait.3>')
yield('/echo Craft finished <se.4>')

EDIT:

Tried running the script without the materia extraction in there and it returned this error:

[SND] Failure while running script: [string "chunk"]:30: ')' expected near 'Company'

How can I escape the apostrophe in the recipe name?

Additionally, it seems like the then/else isn't being obeyed as it triggered my food buff again even after I had it active.

daemitus commented 2 years ago

excess quote in yield('/recipe Grade 4 Artisanal Skybuilders' Company Chest') -- ADD RECIPE NAME HERE, needs escaping

On Fri, Jul 29, 2022 at 11:12 AM althaiaDev @.***> wrote:

Thank you! This is what I've got so far and it returned: [SND] Failure while running script: [string "chunk"]:28: ')' expected near 'within'

-- /requirestats 3684 3874 681 -- Checks for Food buff, if not then presses hotbar assigned to 9 if (HasStatus("Meal Benefits")) then else yield('/send KEY_9') end

-- Checks for Pot buff, if not then presses hotbar assigned to 0 if (HasStatus("Medicated")) then else yield('/send KEY_0') end

-- Checks for repairability, then extracts materia if applicable. if (NeedsRepair()) then yield('/click repair_all') else end

-- ASSUMES YOU HAVE "Yes Already" ENABLED FOR MATERIA EXTRACT if(CanExtractMateria(float within = 100)) then yield('/click retrieve_materia_begin') yield('/click retrieve_materia_return') else end

-- Finds recipe yield('/recipe Grade 4 Artisanal Skybuilders' Company Chest') -- ADD RECIPE NAME HERE

--Crafts yield('/craft 10')

--Craft Macro yield('/ac "Muscle Memory" ') yield('/ac Manipulation ') yield('/ac "Final Appraisal" ') yield('/ac Veneration ') yield('/ac "Waste Not" ') yield('/ac Groundwork ') yield('/ac Groundwork ') yield('/ac "Final Appraisal" ') yield('/ac "Careful Synthesis" ') yield('/ac "Heart and Soul" ') yield('/ac "Precise Touch" ') yield('/ac Innovation ') yield('/ac "Basic Touch" ') yield('/ac "Standard Touch" ') yield('/ac "Advanced Touch" ') yield('/ac "Prudent Touch" ') yield('/ac Manipulation ') yield('/ac Innovation ') yield('/ac "Prudent Touch" ') yield('/ac "Basic Touch" ') yield('/ac "Standard Touch" ') yield('/ac "Advanced Touch" ') yield('/ac "Great Strides" ') yield('/ac Innovation ') yield('/ac Observe ') yield('/ac "Focused Touch" ') yield('/ac "Great Strides" ') yield('/ac "Byregot's Blessing" ') yield('/ac "Basic Synthesis" ') yield('/echo Craft finished ')

— Reply to this email directly, view it on GitHub https://github.com/daemitus/SomethingNeedDoing/issues/85#issuecomment-1199499250, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFMTBFRFVM5KRX5U6J4ZE3VWPYFVANCNFSM55A4JA3A . You are receiving this because you commented.Message ID: @.***>

Ditziv commented 2 years ago

Much appreciated - the [SND] Failure while running script: [string "chunk"]:28: ')' expected near 'within' error is still occurring, but I made sure I copied the same syntax from the help menu. Any ideas?

daemitus commented 2 years ago

if(CanExtractMateria(float within = 100)) I'm not sure if you can do named parameters, my own lua is weak as well. just give it 100

On Fri, Jul 29, 2022 at 12:58 PM althaiaDev @.***> wrote:

Much appreciated - the [SND] Failure while running script: [string "chunk"]:28: ')' expected near 'within' error is still occurring, but I made sure I copied the same syntax from the help menu. Any ideas?

— Reply to this email directly, view it on GitHub https://github.com/daemitus/SomethingNeedDoing/issues/85#issuecomment-1199750365, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFMTBFRSD2OYBE4GCDHRVDVWQEVDANCNFSM55A4JA3A . You are receiving this because you commented.Message ID: @.***>

Ditziv commented 2 years ago

Thank you! I've got the following so far. Is there any type of logging or debugging mode I can enable? Right now what the script below does when i dont have any buffs is just use food and return this in the chat. Everything happens almost instantaneously and I have no way of seeing what step the script is on like the behavior that macros have.

[1:41 p.m.][SND] 10 crafts remaining
[1:41 p.m.]Craft finished <se.4>

Potentially relevant options I have enabled:

-- Checks for Pot buff, if not then presses hotbar assigned to 0 if (HasStatus("Medicated")) then else yield('/send KEY_0') end

-- Checks for repairability, then extracts materia if applicable. if (NeedsRepair()) then yield('/click repair_all') else end

-- ASSUMES YOU HAVE "Yes Already" ENABLED FOR MATERIA EXTRACT if(CanExtractMateria(100)) then yield('/click retrieve_materia_begin') yield('/click retrieve_materia_return') else end

-- Finds recipe yield('/recipe Grade 4 Artisanal Skybuilders\' Company Chest') -- ADD RECIPE NAME HERE

--Crafts yield('/craft 10')

--Craft Macro yield('/ac "Muscle Memory" ') yield('/ac Manipulation ') yield('/ac "Final Appraisal" ') yield('/ac Veneration ') yield('/ac "Waste Not" ') yield('/ac Groundwork ') yield('/ac Groundwork ') yield('/ac "Final Appraisal" ') yield('/ac "Careful Synthesis" ') yield('/ac "Heart and Soul" ') yield('/ac "Precise Touch" ') yield('/ac Innovation ') yield('/ac "Basic Touch" ') yield('/ac "Standard Touch" ') yield('/ac "Advanced Touch" ') yield('/ac "Prudent Touch" ') yield('/ac Manipulation ') yield('/ac Innovation ') yield('/ac "Prudent Touch" ') yield('/ac "Basic Touch" ') yield('/ac "Standard Touch" ') yield('/ac "Advanced Touch" ') yield('/ac "Great Strides" ') yield('/ac Innovation ') yield('/ac Observe ') yield('/ac "Focused Touch" ') yield('/ac "Great Strides" ') yield('/ac "Byregot\'s Blessing" ') yield('/ac "Basic Synthesis" ') yield('/echo Craft finished ')

daemitus commented 2 years ago

You could always yield echo commands.

DenL commented 2 years ago

This thread has been super informative in helping me setup my lua scripts, much appreciated! Do the yield macro lines need the wait paremeter? Or is it all ignored by the plugin as it execute lines as fast as possible?