Re: Damage Counter script errors
Posted: Fri Feb 14, 2014 5:19 am
Still cant find the problem...
if not CritCounter then
CritCounter = {
_totalHits = 0,
_loaded = false,
_enabled = true,
}
local cc = CritCounter
display("Loading Crit Table")
cc._critTable = {}
cc._critTable["pathetic"] = 0
cc._critTable["weak"] = 0
cc._critTable["punishing"] = 0
cc._critTable["surprising"] = 0
cc._critTable["amazing"] = 0
cc._critTable["astonishing"] = 0
cc._critTable["mauling"] = 0
cc._critTable["decimating"] = 0
cc._critTable["devastating"] = 0
cc._critTable["pulverizing"] = 0
cc._critTable["maiming"] = 0
cc._critTable["eviscerating"] = 0
cc._critTable["mutilating"] = 0
cc._critTable["disemboweling"] = 0
cc._critTable["dismembering"] = 0
cc._critTable["massacring"] = 0
cc._critTable["mangling"] = 0
cc._critTable["demolishing"] = 0
cc._critTable["obliterating"] = 0
cc._critTable["annihilating"] = 0
cc._critTable["eradicating"] = 0
cc._critTable["vaporizing"] = 0
cc._critTable["destructive"] = 0
cc._critTable["extreme"] = 0
cc._critTable["porcine"] = 0
cc._critTable["divine"] = 0
cc._critTable["daunting"] = 0
cc._critTable["terminal"] = 0
cc._critLast = {}
cc._critLast["pathetic"] = 0
cc._critLast["weak"] = 0
cc._critLast["punishing"] = 0
cc._critLast["surprising"] = 0
cc._critLast["amazing"] = 0
cc._critLast["astonishing"] = 0
cc._critLast["mauling"] = 0
cc._critLast["decimating"] = 0
cc._critLast["devastating"] = 0
cc._critLast["pulverizing"] = 0
cc._critLast["maiming"] = 0
cc._critLast["eviscerating"] = 0
cc._critLast["mutilating"] = 0
cc._critLast["disemboweling"] = 0
cc._critLast["dismembering"] = 0
cc._critLast["massacring"] = 0
cc._critLast["mangling"] = 0
cc._critLast["demolishing"] = 0
cc._critLast["obliterating"] = 0
cc._critLast["annihilating"] = 0
cc._critLast["eradicating"] = 0
cc._critLast["vaporizing"] = 0
cc._critLast["destructive"] = 0
cc._critLast["extreme"] = 0
cc._critLast["porcine"] = 0
cc._critLast["divine"] = 0
cc._critLast["daunting"] = 0
cc._critLast["terminal"] = 0
cc._critDisplayOrder = { "pathetic" , "weak" , "punishing" , "surprising" , "amazing" , "astonishing" ,
"mauling" , "decimating" , "devastating" , "pulverizing" , "maiming" ,
"eviscerating" , "mutilating" , "disemboweling" , "dismembering" ,
"massacring" , "mangling" , "demolishing" , "obliterating" , "annihilating" ,
"eradicating" , "vaporizing" , "destructive" , "extreme" , "porcine" ,
"divine" , "daunting" , "terminal" }
cc._critNames = {}
cc._critNames["pathetic"] = "pathetic"
cc._critNames["weak"] = "weak"
cc._critNames["punishing"] = "punishing"
cc._critNames["surprising"] = "surprising"
cc._critNames["amazing"] = "amazing"
cc._critNames["astonishing"] = "astonishing"
cc._critNames["mauling MAULING MAULING* MAULING** MAULING***"] = "mauling"
cc._critNames["decimating DECIMATING DECIMATING* DECIMATING** DECIMATING***"] = "decimating"
cc._critNames["devastating DEVASTATING DEVASTATING* DEVASTATING** DEVASTATING***"] = "devastating"
cc._critNames["pulverizing PULVERIZING PULVERIZING* PULVERIZING** PULVERIZING***"] = "pulverizing"
cc._critNames["maiming MAIMING MAIMING* MAIMING** MAIMING***"] = "maiming"
cc._critNames["eviscerating EVISCERATING EVISCERATING* EVISCERATING** EVISCERATING***"] = "eviscerating"
cc._critNames["mutilating MUTILATING MUTILATING* MUTILATING** MUTILATING***"] = "mutilating"
cc._critNames["disemboweling DISEMBOWELING DISEMBOWELING* DISEMBOWELING** DISEMBOWELING***"] = "disemboweling"
cc._critNames["dismembering DISMEMBERING DISMEMBERING* DISMEMBERING** DISMEMBERING***"] = "dismembering"
cc._critNames["massacring MASSACRING MASSACRING* MASSACRING** MASSACRING***"] = "massacring"
cc._critNames["mangling MANGLING MANGLING* MANGLING** MANGLING***"] = "mangling"
cc._critNames["demolishing DEMOLISHING DEMOLISHING* DEMOLISHING** DEMOLISHING***"] = "demolishing"
cc._critNames["obliterating OBLITERATING OBLITERATING* OBLITERATING** OBLITERATING***"] = "obliterating"
cc._critNames["annihilating ANNIHILATING ANNIHILATING* ANNIHILATING** ANNIHILATING*** ANNIHILATING***< ANNIHILATING***<< ANNIHILATING***<<< ANNIHILATING***<<<<"] = "annihilating"
cc._critNames["eradicating ERADICATING ERADICATING* ERADICATING** ERADICATING*** ERADICATING***< ERADICATING***<< ERADICATING***<<< ERADICATING***<<<<"] = "eradicating"
cc._critNames["vaporizing VAPORIZING VAPORIZING* VAPORIZING** VAPORIZING*** VAPORIZING***< VAPORIZING***<< VAPORIZING***<<< VAPORIZING***<<<<"] = "vaporizing"
cc._critNames["destructive DESTRUCTIVE DESTRUCTIVE* DESTRUCTIVE** DESTRUCTIVE*** DESTRUCTIVE**** DESTRUCTIVE****< DESTRUCTIVE****<< DESTRUCTIVE****<<< DESTRUCTIVE****<<<< DESTRUCTIVE***<<<<= DESTRUCTIVE**<<<<== DESTRUCTIVE*<<<<=== DESTRUCTIVE<<<<===="] = "destructive"
cc._critNames["extreme EXTREME EXTREME* EXTREME** EXTREME*** EXTREME**** EXTREME****< EXTREME****<< EXTREME****<<< EXTREME****<<<< EXTREME***<<<<= EXTREME**<<<<== EXTREME*<<<<=== EXTREME<<<<===="] = "extreme"
cc._critNames["porcine PORCINE PORCINE* PORCINE** PORCINE*** PORCINE***< PORCINE***<< PORCINE***<<< PORCINE***<<<<"] = "porcine"
cc._critNames["divine"] = "divine"
cc._critNames["daunting"] = "daunting"
cc._critNames["terminal"] = "terminal"
end
function CritCounter:Enable(enable)
self._enabled = enable
cecho("\n<light_grey>[ <yellow>DAMAGE REPORT <light_grey>]: Counter has been ")
if enable then cecho("<light_grey>enabled!")
else cecho("<light_grey>disabled!") end
echo("\n")
end
function CritCounter:Load(force)
if self._loaded and not force then return end
local loadTable = {}
if string.char(getMudletHomeDir():byte()) == "/" then _sep = "/" else _sep = "\\" end
local l_SettingsFile = getMudletHomeDir() .. _sep .. "CritCounter.lua"
if (io.exists(l_SettingsFile)) then
table.load(l_SettingsFile, loadTable)
end
if not loadTable.critTable or not loadTable.totalHits or not loadTable.critLast then
cecho("<red>Failed to load DAMAGE REPORT saved data!")
cecho("<white>Ignore this warning if you have just")
cecho("<white> installed the counter")
return
end
self._critTable = loadTable.critTable
self._totalHits = loadTable.totalHits
self._critLast = loadTable.critLast
self._loaded = true
end
function CritCounter:Save()
if string.char(getMudletHomeDir():byte()) == "/" then _sep = "/" else _sep = "\\" end
local l_SettingsFile = getMudletHomeDir() .. _sep .. "CritCounter.lua"
local savetable = {}
savetable.critTable = self._critTable
savetable.totalHits = self._totalHits
savetable.critLast = self._critLast
table.save(l_SettingsFile, savetable)
end
function CritCounter:display()
local totalcrits = 0
for _, num in pairs(self._critTable) do
totalcrits = totalcrits + num
end
local critrate = self._totalHits == 0 and 0 or (totalcrits / self._totalHits) * 100
cecho("\n<grey>" .. string.rep("-", 31) .. "[ <yellow>DAMAGE REPORT:<grey> ]" .. string.rep("-", 31) .. "\n\n")
cecho("<RoyalBlue>Total hits: <white>" .. self._totalHits .. "\n")
cecho("<RoyalBlue>Total crits: <white>" .. totalcrits .. "\n")
cecho("<RoyalBlue>Total crit-rate: <white>" .. string.format("%.3f", critrate) .. "\n")
cecho("\n\n<DarkGreen>Statistics:\n")
for _, crit in ipairs(self._critDisplayOrder) do
local rate = totalcrits == 0 and 0.0 or (self._critTable[crit] / totalcrits) * 100
if not crit then print("NIL VARIABLE: crit") end
if not self._critTable[crit] then
print("NIL VARIABLE: self._critTable[crit]")
display(crit)
display(self._critTable)
end
if not rate then print("NIL VARIABLE: rate") end
if not self._critLast[crit] then print("NIL VARIABLE: self._critLast[crit]") end
local format_str = "<light_goldenrod_yellow>%-20s<white>%s <LimeGreen>[ %-8.3f ] - %s hits ago!\n"
local line = string.format(format_str,crit,self._critTable[crit],rate,self._critLast[crit])
cecho(line)
end
cecho("\n<grey>" .. string.rep("-", 80) .. "\n")
end
function CritCounter:Reset()
for crit, _ in pairs(self._critTable) do
self._critTable[crit] = 0
self._critLast[crit] = 0
end
self._totalHits = 0
self:Save()
cecho("\n<light_grey>[ <yellow>DAMAGE REPORT <light_grey>]: Counter has been reset!")
end
function CritCounter:AddHit()
if not self._enabled then return end
self._totalHits = self._totalHits + 1
for crit, _ in pairs(self._critLast) do
self._critLast[crit] = self._critLast[crit] + 1
end
end
function CritCounter:AddCrit(type)
if not self._enabled or not type then return end
type = self._critNames[type]
self._critTable[type] = self._critTable[type] + 1
self._critLast[type] = 0
self:Save()
end
CritCounter:Load()
if not CritCounter then
CritCounter = {
_totalHits = 0,
_loaded = false,
_enabled = true,
}
local cc = CritCounter
display("Loading Crit Table")
cc._critTable = {}
cc._critTable["pathetic"] = 0
cc._critTable["weak"] = 0
cc._critTable["punishing"] = 0
cc._critTable["surprising"] = 0
cc._critTable["amazing"] = 0
cc._critTable["astonishing"] = 0
cc._critTable["mauling"] = 0
cc._critTable["decimating"] = 0
cc._critTable["devastating"] = 0
cc._critTable["pulverizing"] = 0
cc._critTable["maiming"] = 0
cc._critTable["eviscerating"] = 0
cc._critTable["mutilating"] = 0
cc._critTable["disemboweling"] = 0
cc._critTable["dismembering"] = 0
cc._critTable["massacring"] = 0
cc._critTable["mangling"] = 0
cc._critTable["demolishing"] = 0
cc._critTable["obliterating"] = 0
cc._critTable["annihilating"] = 0
cc._critTable["eradicating"] = 0
cc._critTable["vaporizing"] = 0
cc._critTable["destructive"] = 0
cc._critTable["extreme"] = 0
cc._critTable["porcine"] = 0
cc._critTable["divine"] = 0
cc._critTable["daunting"] = 0
cc._critTable["terminal"] = 0
cc._critLast = {}
cc._critLast["pathetic"] = 0
cc._critLast["weak"] = 0
cc._critLast["punishing"] = 0
cc._critLast["surprising"] = 0
cc._critLast["amazing"] = 0
cc._critLast["astonishing"] = 0
cc._critLast["mauling"] = 0
cc._critLast["decimating"] = 0
cc._critLast["devastating"] = 0
cc._critLast["pulverizing"] = 0
cc._critLast["maiming"] = 0
cc._critLast["eviscerating"] = 0
cc._critLast["mutilating"] = 0
cc._critLast["disemboweling"] = 0
cc._critLast["dismembering"] = 0
cc._critLast["massacring"] = 0
cc._critLast["mangling"] = 0
cc._critLast["demolishing"] = 0
cc._critLast["obliterating"] = 0
cc._critLast["annihilating"] = 0
cc._critLast["eradicating"] = 0
cc._critLast["vaporizing"] = 0
cc._critLast["destructive"] = 0
cc._critLast["extreme"] = 0
cc._critLast["porcine"] = 0
cc._critLast["divine"] = 0
cc._critLast["daunting"] = 0
cc._critLast["terminal"] = 0
cc._critDisplayOrder = { "pathetic" , "weak" , "punishing" , "surprising" , "amazing" , "astonishing" ,
"mauling" , "decimating" , "devastating" , "pulverizing" , "maiming" ,
"eviscerating" , "mutilating" , "disemboweling" , "dismembering" ,
"massacring" , "mangling" , "demolishing" , "obliterating" , "annihilating" ,
"eradicating" , "vaporizing" , "destructive" , "extreme" , "porcine" ,
"divine" , "daunting" , "terminal" }
cc._critNames = {}
cc._critNames["pathetic"] = "pathetic"
cc._critNames["weak"] = "weak"
cc._critNames["punishing"] = "punishing"
cc._critNames["surprising"] = "surprising"
cc._critNames["amazing"] = "amazing"
cc._critNames["astonishing"] = "astonishing"
cc._critNames["mauling MAULING MAULING* MAULING** MAULING***"] = "mauling"
cc._critNames["decimating DECIMATING DECIMATING* DECIMATING** DECIMATING***"] = "decimating"
cc._critNames["devastating DEVASTATING DEVASTATING* DEVASTATING** DEVASTATING***"] = "devastating"
cc._critNames["pulverizing PULVERIZING PULVERIZING* PULVERIZING** PULVERIZING***"] = "pulverizing"
cc._critNames["maiming MAIMING MAIMING* MAIMING** MAIMING***"] = "maiming"
cc._critNames["eviscerating EVISCERATING EVISCERATING* EVISCERATING** EVISCERATING***"] = "eviscerating"
cc._critNames["mutilating MUTILATING MUTILATING* MUTILATING** MUTILATING***"] = "mutilating"
cc._critNames["disemboweling DISEMBOWELING DISEMBOWELING* DISEMBOWELING** DISEMBOWELING***"] = "disemboweling"
cc._critNames["dismembering DISMEMBERING DISMEMBERING* DISMEMBERING** DISMEMBERING***"] = "dismembering"
cc._critNames["massacring MASSACRING MASSACRING* MASSACRING** MASSACRING***"] = "massacring"
cc._critNames["mangling MANGLING MANGLING* MANGLING** MANGLING***"] = "mangling"
cc._critNames["demolishing DEMOLISHING DEMOLISHING* DEMOLISHING** DEMOLISHING***"] = "demolishing"
cc._critNames["obliterating OBLITERATING OBLITERATING* OBLITERATING** OBLITERATING***"] = "obliterating"
cc._critNames["annihilating ANNIHILATING ANNIHILATING* ANNIHILATING** ANNIHILATING*** ANNIHILATING***< ANNIHILATING***<< ANNIHILATING***<<< ANNIHILATING***<<<<"] = "annihilating"
cc._critNames["eradicating ERADICATING ERADICATING* ERADICATING** ERADICATING*** ERADICATING***< ERADICATING***<< ERADICATING***<<< ERADICATING***<<<<"] = "eradicating"
cc._critNames["vaporizing VAPORIZING VAPORIZING* VAPORIZING** VAPORIZING*** VAPORIZING***< VAPORIZING***<< VAPORIZING***<<< VAPORIZING***<<<<"] = "vaporizing"
cc._critNames["destructive DESTRUCTIVE DESTRUCTIVE* DESTRUCTIVE** DESTRUCTIVE*** DESTRUCTIVE**** DESTRUCTIVE****< DESTRUCTIVE****<< DESTRUCTIVE****<<< DESTRUCTIVE****<<<< DESTRUCTIVE***<<<<= DESTRUCTIVE**<<<<== DESTRUCTIVE*<<<<=== DESTRUCTIVE<<<<===="] = "destructive"
cc._critNames["extreme EXTREME EXTREME* EXTREME** EXTREME*** EXTREME**** EXTREME****< EXTREME****<< EXTREME****<<< EXTREME****<<<< EXTREME***<<<<= EXTREME**<<<<== EXTREME*<<<<=== EXTREME<<<<===="] = "extreme"
cc._critNames["porcine PORCINE PORCINE* PORCINE** PORCINE*** PORCINE***< PORCINE***<< PORCINE***<<< PORCINE***<<<<"] = "porcine"
cc._critNames["divine"] = "divine"
cc._critNames["daunting"] = "daunting"
cc._critNames["terminal"] = "terminal"
end
function CritCounter:Enable(enable)
self._enabled = enable
cecho("\n<light_grey>[ <yellow>DAMAGE REPORT <light_grey>]: Counter has been ")
if enable then cecho("<light_grey>enabled!")
else cecho("<light_grey>disabled!") end
echo("\n")
end
function CritCounter:Load(force)
if self._loaded and not force then return end
local loadTable = {}
if string.char(getMudletHomeDir():byte()) == "/" then _sep = "/" else _sep = "\\" end
local l_SettingsFile = getMudletHomeDir() .. _sep .. "CritCounter.lua"
if (io.exists(l_SettingsFile)) then
table.load(l_SettingsFile, loadTable)
end
if not loadTable.critTable or not loadTable.totalHits or not loadTable.critLast then
cecho("<red>Failed to load DAMAGE REPORT saved data!")
cecho("<white>Ignore this warning if you have just")
cecho("<white> installed the counter")
return
end
self._critTable = loadTable.critTable
self._totalHits = loadTable.totalHits
self._critLast = loadTable.critLast
self._loaded = true
end
function CritCounter:Save()
if string.char(getMudletHomeDir():byte()) == "/" then _sep = "/" else _sep = "\\" end
local l_SettingsFile = getMudletHomeDir() .. _sep .. "CritCounter.lua"
local savetable = {}
savetable.critTable = self._critTable
savetable.totalHits = self._totalHits
savetable.critLast = self._critLast
table.save(l_SettingsFile, savetable)
end
function CritCounter:display()
local totalcrits = 0
for _, num in pairs(self._critTable) do
totalcrits = totalcrits + num
end
local critrate = self._totalHits == 0 and 0 or (totalcrits / self._totalHits) * 100
cecho("\n<grey>" .. string.rep("-", 31) .. "[ <yellow>DAMAGE REPORT:<grey> ]" .. string.rep("-", 31) .. "\n\n")
cecho("<RoyalBlue>Total hits: <white>" .. self._totalHits .. "\n")
cecho("<RoyalBlue>Total crits: <white>" .. totalcrits .. "\n")
cecho("<RoyalBlue>Total crit-rate: <white>" .. string.format("%.3f", critrate) .. "\n")
cecho("\n\n<DarkGreen>Statistics:\n")
for _, crit in ipairs(self._critDisplayOrder) do
local rate = totalcrits == 0 and 0.0 or (self._critTable[crit] / totalcrits) * 100
if not crit then print("NIL VARIABLE: crit") end
if not self._critTable[crit] then
print("NIL VARIABLE: self._critTable[crit]")
display(crit)
display(self._critTable)
end
if not rate then print("NIL VARIABLE: rate") end
if not self._critLast[crit] then print("NIL VARIABLE: self._critLast[crit]") end
local format_str = "<light_goldenrod_yellow>%-20s<white>%s <LimeGreen>[ %-8.3f ] - %s hits ago!\n"
local line = string.format(format_str,crit,self._critTable[crit],rate,self._critLast[crit])
cecho(line)
end
cecho("\n<grey>" .. string.rep("-", 80) .. "\n")
end
function CritCounter:Reset()
for crit, _ in pairs(self._critTable) do
self._critTable[crit] = 0
self._critLast[crit] = 0
end
self._totalHits = 0
self:Save()
cecho("\n<light_grey>[ <yellow>DAMAGE REPORT <light_grey>]: Counter has been reset!")
end
function CritCounter:AddHit()
if not self._enabled then return end
self._totalHits = self._totalHits + 1
for crit, _ in pairs(self._critLast) do
self._critLast[crit] = self._critLast[crit] + 1
end
end
function CritCounter:AddCrit(type)
if not self._enabled or not type then return end
type = self._critNames[type]
self._critTable[type] = self._critTable[type] + 1
self._critLast[type] = 0
self:Save()
end
CritCounter:Load()