Soandso2
Well-known member
- Joined
- Mar 13, 2023
- RedCents
- 937¢
As per usual I try to do things myself, because it is fun. I made a Lua to help me max my mage magic skills. I run it every other time or so that I level up. But there is an issue. No syntax errors or things like that, but it is something else. It has to do with cast and recast times and adding a delay, since I presume that the Lua loop does not halt and wait once the command to /cast is used. The whole thing actually works, except for the statistics part, where I get way too many "you cast this spell this many times". I have added several debug print in the casting loop, and I see that they print too many times. The Lua in its entirety is posted below. And the problems are in the highlighted area. The "casted" counter goes up too fast. Not sure what I am doing wrong. I dont see anything work logic wise but still something makes it not run as expected.
EDIT: It seems like it was the delays that were long enough. I changed the addition to the delays (highlighted below) from 250 to 1000 and all seems to work as expected.
[CODE lang="Lua" highlight="115-126"]mq = require('mq')
require("../includes/utils")
local mSkillSpells = {
["Alteration"]="Renew Elements",
["Abjuration"]="Minor Shielding",
["Conjuration"]="Summon Dagger",
["Divination"]="True North",
["Evocation"]="Burst of Flame"
}
local mCasted = {
["Alteration"]=0,
["Abjuration"]=0,
["Conjuration"]=0,
["Divination"]=0,
["Evocation"]=0
}
local mSkillUps = {
["Alteration"]=0,
["Abjuration"]=0,
["Conjuration"]=0,
["Divination"]=0,
["Evocation"]=0,
["Specialize Alteration"]=0,
["Specialize Abjure"]=0,
["Specialize Conjuration"]=0,
["Specialize Divination"]=0,
["Specialize Evocation"]=0
}
local function skillUp(line,sSkill)
mSkillUps[sSkill] = mSkillUps[sSkill]+1
print("\ag"..sSkill.." skill up!")
end
local firstSpell = me.Gem(1)()
local myName = me.CleanName()
local petName = pet.CleanName()
local castDelay = 0
local recastDelay = 0
print("\ayTime for magic skills practice!")
print("\arWarning:\aw Anything on the cursor will be destroyed! You have 10 seconds to abort!")
mq.delay(10000)
if cursor.ID() then
mq.cmd("/destroy")
end
mq.delay(1000)
print("\awSpell in gem slot one was: \ag"..firstSpell)
print("\awMy name is: \ag"..myName)
print("\awPet name is: \ag"..petName)
print ("\ayStarting the run...")
mq.event("skillup","You have become better at #1#!#*#",skillUp)
for mSkill, mSpell in pairs(mSkillSpells) do
if cursor.ID() then
mq.cmd("/destroy")
end
mq.delay(1000)
castDelay = mq.TLO.Spell(mSpell).CastTime() + 250
recastDelay = mq.TLO.Spell(mSpell).RecastTime() +250
if me.Skill(mSkill)() ~= me.SkillCap(mSkill)() then
if cursor.ID() then
mq.cmd("/destroy")
end
print ("\ay"..mSkill)
mq.cmdf("/memspellslot 1 %s",mSpell)
mq.delay(10000)
print("\aw Memorized \ag"..mSpell)
print("\awCurrent skill level: \ag"..me.Skill(mSkill)().."\aw, skill cap: \am"..me.SkillCap(mSkill)())
while me.Skill(mSkill)() ~= me.SkillCap(mSkill)() do
if mSkill == "Alteration" then
if target.CleanName() ~= petName then
print ("\aoTarget was not "..petName)
mq.cmd("/target "..petName)
print ("\awTargeted \ag"..petName)
end
elseif mSkill == "Abjuration" then
if target.CleanName() ~= myName then
print ("\aoTarget was not "..myName)
mq.cmd("/target "..myName)
print ("\awTargeted \agmyself")
end
elseif mSkill == "Evocation" then
if target.CleanName() ~= petName then
print ("\aoTarget was not "..petName)
mq.cmd("/target "..petName)
print ("\awTargeted \ag"..petName)
end
end
mq.cmd("/cast 1")
print("Casting delay: "..castDelay)
mq.delay(castDelay)
mCasted[mSkill] = mCasted[mSkill]+1
print(mSkill.." cast " .. mCasted[mSkill] .. " times")
if cursor.ID() then
mq.cmd("/destroy")
end
print("Recasting delay: "..recastDelay)
mq.delay(recastDelay)
mq.doevents()
end
else
print ("\aw"..mSkill.." maxed, let's try another one...")
end
end
if me.Gem(1)() ~= firstSpell then
mq.cmdf("/memspellslot 1 %s",firstSpell)
print("\awMemorized: \ag"..firstSpell)
end
print("\ayStatistics")
for key, value in pairs(mCasted) do
if value == 0 then
print("\aw"..key.." not cast, probably already maxed")
else
print("\aw"..key..": Cast "..mCasted[key].." times, "..mSkillUps[key].." skill ups ("..tonumber(string.format("%.2f", (mSkillUps[key]/mCasted[key]*100))).."%)")
end
end
print("\awSpecialize Abjuration: "..mSkillUps["Specialize Abjuration"].. " skill ups")
print("\awSpecialize Alteration: "..mSkillUps["Specialize Alteration"].. " skill ups")
print("\awSpecialize Conjuration: "..mSkillUps["Specialize Conjuration"].. " skill ups")
print("\awSpecialize Divination: "..mSkillUps["Specialize Divination"].. " skill ups")
print("\awSpecialize Evocation: "..mSkillUps["Specialize Evocation"].. " skill ups")
print("\ayMagic practice is over for this time!")[/CODE]
EDIT: It seems like it was the delays that were long enough. I changed the addition to the delays (highlighted below) from 250 to 1000 and all seems to work as expected.
Lua:
castDelay = mq.TLO.Spell(mSpell).CastTime() + 1000
recastDelay = mq.TLO.Spell(mSpell).RecastTime() +1000
[CODE lang="Lua" highlight="115-126"]mq = require('mq')
require("../includes/utils")
local mSkillSpells = {
["Alteration"]="Renew Elements",
["Abjuration"]="Minor Shielding",
["Conjuration"]="Summon Dagger",
["Divination"]="True North",
["Evocation"]="Burst of Flame"
}
local mCasted = {
["Alteration"]=0,
["Abjuration"]=0,
["Conjuration"]=0,
["Divination"]=0,
["Evocation"]=0
}
local mSkillUps = {
["Alteration"]=0,
["Abjuration"]=0,
["Conjuration"]=0,
["Divination"]=0,
["Evocation"]=0,
["Specialize Alteration"]=0,
["Specialize Abjure"]=0,
["Specialize Conjuration"]=0,
["Specialize Divination"]=0,
["Specialize Evocation"]=0
}
local function skillUp(line,sSkill)
mSkillUps[sSkill] = mSkillUps[sSkill]+1
print("\ag"..sSkill.." skill up!")
end
local firstSpell = me.Gem(1)()
local myName = me.CleanName()
local petName = pet.CleanName()
local castDelay = 0
local recastDelay = 0
print("\ayTime for magic skills practice!")
print("\arWarning:\aw Anything on the cursor will be destroyed! You have 10 seconds to abort!")
mq.delay(10000)
if cursor.ID() then
mq.cmd("/destroy")
end
mq.delay(1000)
print("\awSpell in gem slot one was: \ag"..firstSpell)
print("\awMy name is: \ag"..myName)
print("\awPet name is: \ag"..petName)
print ("\ayStarting the run...")
mq.event("skillup","You have become better at #1#!#*#",skillUp)
for mSkill, mSpell in pairs(mSkillSpells) do
if cursor.ID() then
mq.cmd("/destroy")
end
mq.delay(1000)
castDelay = mq.TLO.Spell(mSpell).CastTime() + 250
recastDelay = mq.TLO.Spell(mSpell).RecastTime() +250
if me.Skill(mSkill)() ~= me.SkillCap(mSkill)() then
if cursor.ID() then
mq.cmd("/destroy")
end
print ("\ay"..mSkill)
mq.cmdf("/memspellslot 1 %s",mSpell)
mq.delay(10000)
print("\aw Memorized \ag"..mSpell)
print("\awCurrent skill level: \ag"..me.Skill(mSkill)().."\aw, skill cap: \am"..me.SkillCap(mSkill)())
while me.Skill(mSkill)() ~= me.SkillCap(mSkill)() do
if mSkill == "Alteration" then
if target.CleanName() ~= petName then
print ("\aoTarget was not "..petName)
mq.cmd("/target "..petName)
print ("\awTargeted \ag"..petName)
end
elseif mSkill == "Abjuration" then
if target.CleanName() ~= myName then
print ("\aoTarget was not "..myName)
mq.cmd("/target "..myName)
print ("\awTargeted \agmyself")
end
elseif mSkill == "Evocation" then
if target.CleanName() ~= petName then
print ("\aoTarget was not "..petName)
mq.cmd("/target "..petName)
print ("\awTargeted \ag"..petName)
end
end
mq.cmd("/cast 1")
print("Casting delay: "..castDelay)
mq.delay(castDelay)
mCasted[mSkill] = mCasted[mSkill]+1
print(mSkill.." cast " .. mCasted[mSkill] .. " times")
if cursor.ID() then
mq.cmd("/destroy")
end
print("Recasting delay: "..recastDelay)
mq.delay(recastDelay)
mq.doevents()
end
else
print ("\aw"..mSkill.." maxed, let's try another one...")
end
end
if me.Gem(1)() ~= firstSpell then
mq.cmdf("/memspellslot 1 %s",firstSpell)
print("\awMemorized: \ag"..firstSpell)
end
print("\ayStatistics")
for key, value in pairs(mCasted) do
if value == 0 then
print("\aw"..key.." not cast, probably already maxed")
else
print("\aw"..key..": Cast "..mCasted[key].." times, "..mSkillUps[key].." skill ups ("..tonumber(string.format("%.2f", (mSkillUps[key]/mCasted[key]*100))).."%)")
end
end
print("\awSpecialize Abjuration: "..mSkillUps["Specialize Abjuration"].. " skill ups")
print("\awSpecialize Alteration: "..mSkillUps["Specialize Alteration"].. " skill ups")
print("\awSpecialize Conjuration: "..mSkillUps["Specialize Conjuration"].. " skill ups")
print("\awSpecialize Divination: "..mSkillUps["Specialize Divination"].. " skill ups")
print("\awSpecialize Evocation: "..mSkillUps["Specialize Evocation"].. " skill ups")
print("\ayMagic practice is over for this time!")[/CODE]
Last edited:

