• You've discovered RedGuides 📕 an EverQuest multi-boxing community 🛡️🧙🗡️. We want you to play several EQ characters at once, come join us and say hello! 👋
  • IS THIS SITE UGLY? Change the look. To dismiss this notice, click the X --->

Question - LUA: auto-recast if "Your spell fizzles!" (1 Viewer)

Joined
Mar 20, 2024
RedCents
264¢
I am trying to code with Lua a small script to automatically reattempt your latest spell cast if you get the dreaded "Your spell fizzles!" message prompted in the chat window. Unfortunately, I cant figure out how to retrieve the actual spell that's just fizzled (meaning the latest spell being cast)

Any insights on how that could be achieved?
 
I am trying to code with Lua a small script to automatically reattempt your latest spell cast if you get the dreaded "Your spell fizzles!" message prompted in the chat window. Unfortunately, I cant figure out how to retrieve the actual spell that's just fizzled (meaning the latest spell being cast)

Any insights on how that could be achieved?

Set two events. The first for" you begin to cast #1#..... " (this is not exact)

Have this event store the name of the spell..

Set the second for the fizzle event. If it fizzles, recast the spell that was stored..
 
Set two events. The first for" you begin to cast #1#..... " (this is not exact)

Have this event store the name of the spell..

Set the second for the fizzle event. If it fizzles, recast the spell that was stored..

Thank you, very useful.

I have created the two events, but I am struggling to pass the variable SpellName from Event A ("You begin to cast XXXXX") to Event B ("Your spell fizzles!"). In event A, the variable does correctly register the spell name. However, when I try to use the variable in Event B, the value is always "nil".

I believe that I need to define SpellName as a global variable in Event A, and then retrieve it from Event B using the instruction "retrieve". However, as a non-programmer, I am failing to make sense of the available documentation.

Any insights on how to set that global variable and how to retrieve it, please?
 
A quick pseudocode as I'm not on an EQ system atm.

Lua:
local last_spell_name = nil

local function OnSpellCast(line, spell_name)
    last_spell_name = spell_name
end

local function OnFizzle(line)
   if (last_spell_name ~= nil) then
       cast(last_spell_name)
   end
end
 
A quick pseudocode as I'm not on an EQ system atm.

Lua:
local last_spell_name = nil

local function OnSpellCast(line, spell_name)
    last_spell_name = spell_name
end

local function OnFizzle(line)
   if (last_spell_name ~= nil) then
       cast(last_spell_name)
   end
end

Thank you. Unfortunately, the 2nd function always prints last_spell_name as nil.

Just to make sure I understand your previous post: I am supposed to apply the following code in the first "You begin casting #1#" Lua event...

Lua:
local last_spell_name = nil

local function OnSpellCast(line, spell_name)
    last_spell_name = spell_name
end

And the second bit in the second "Your spell fizzles!" Lua event...

Lua:
local function OnFizzle(line)
   if (last_spell_name ~= nil) then
       cast(last_spell_name)
   end
   print(last_spell_name)
end

Correct? Because I did just that and the value of last_spell_name always prints as nil :(
 
The sample I put was just to show how data from one method/event can be used from another.

You'll still need to get your events working correctly.

Have an event, and test that the actual OnSpellCast method is being called. Look at other Lua scripts on your system to see how they work with mq.event.

mq.event('EventName', 'The Pattern #1#!', OnSpellCast)
 
Thank you. Unfortunately, the 2nd function always prints last_spell_name as nil.

Just to make sure I understand your previous post: I am supposed to apply the following code in the first "You begin casting #1#" Lua event...

Lua:
local last_spell_name = nil

local function OnSpellCast(line, spell_name)
    last_spell_name = spell_name
end

And the second bit in the second "Your spell fizzles!" Lua event...

Lua:
local function OnFizzle(line)
   if (last_spell_name ~= nil) then
       cast(last_spell_name)
   end
   print(last_spell_name)
end

Correct? Because I did just that and the value of last_spell_name always prints as nil :(

I am just waking up so this will be sloppy, but putting it all together you would get.

The mq.event lines may not be 100% accurate on wording for the two events. But this will cause casting to fire the "OnSpellCast" event which causes the variable last_spell_name to be set to the spell being cast. this variable is outside of the scope of other functions, so it will be accessible by all functions. The second function "OnFizzle" will fire upon a spell fizzle, and will cast the name of the spell in last_spell_name (if the value is not nil).

The main loop runs indefinitely and every 200ms causes the script to check if any of it's events have fired off.

Lua:
local last_spell_name = nil

local function OnSpellCast(line, spell_name)
    last_spell_name = spell_name
end

local function OnFizzle(line)
   if (last_spell_name ~= nil) then
       cast(last_spell_name)
   end
   print(last_spell_name)
end

mq.event('casting', "You begin casting #1#", OnSpellCast)
mq.event('fizzle', "Your spell fizzles.", OnFizzle)

local function main()
    while true do
        mq.delay(200)
        mq.doevents()
    end
end
 
Lua:
local last_spell_name = nil
local function OnSpellCast(line, spell_name)
    last_spell_name = spell_name
end
local function OnFizzle(line)
   if (last_spell_name ~= nil) then
       cast(last_spell_name)
   end
   print(last_spell_name)
end
mq.event('casting', "You begin casting #1#.", OnSpellCast)
mq.event('fizzle', "Your spell fizzles!", OnFizzle)
local function main()
    while true do
        mq.delay(200)
        mq.doevents()
    end
end

Thank you very much.

I am using LEM, which requires a "trigger" text to be defined. In this case, I use: You begin casting #1#. Upon loading your code above (I corrected a couple of typos), MQ2 throws the same error I have been getting all along: Lua.14: attempt to index global 'mq' (a nil value).
 
OMG I just found out what the problem is... It's not in the code, which works as it should. The problem is that the message "You begin casting XXXXXX" is only prompted when a spell is cast successfully, but NOT when it fizzles! Therefore, the value stored in the global variable LastSpellCast is NOT updated when the spell fizzles - instead, it keeps the value of the latest spell that had been successfully cast prior to the fizzle! The end result of that is that my code, upon a fizzle, attempts to recast the successful spell prior to the fizzle, not the spell that has actually fizzled.

See screenshot attached, where I was alternating (manually casting) Force Shield and Death Peace. You will observe at the top of the screenshot that Force Shield was successfully cast (and successfully stored in the global variable LastSpellCast). Right afterwards, I fizzled Death Peace a few times. Please note that there's no "You begin casting Death Peace" prompted in the screen, so the value of the global variable never updated from "Force Shield" to "Death Peace". The proof is that the print(LastSpellCast) command keeps printing on screen "[MQ2] Force Shield" even though I was indeed casting (fizzling) Death Peace.

So... it seems like we cannot use Text Events to capture the value of LastCastSpell upon a fizzle.

Can you think of any alternative way?
 

Attachments

  • Screenshot-2024-03-29-090609.jpg
    Screenshot-2024-03-29-090609.jpg
    145.7 KB · Views: 0
Last edited:
you could use the above 2 event example but instead of checking for you begin casting check for an announce
then have your character announce the spell into some channel when casting everytime
 
Question - LUA: auto-recast if "Your spell fizzles!"

Users who are viewing this thread

Back
Top