You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
6.3 KiB

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, December 26, 2019, 8:20 AM -->
<!-- MuClient version 5.07-pre -->
<muclient>
<plugin
name="SlotStats"
author="Crowley"
id="8df191366dbc56f8e3ec6c1c"
language="Lua"
purpose="Displays stats for playing Slots"
save_state="y"
date_written="2019-12-26 08:18:35"
requires="4.80"
version="1.0"
>
</plugin>
<!-- Get our standard constants -->
<include name="constants.lua"/>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
group="Slots"
match="^You put ([\d,]+) coins into the machine and spin!$"
regexp="y"
script="slotStart"
sequence="100"
>
</trigger>
<trigger
group="Slots"
match="^Congratulations! You win ([\d,]+) gold coins!$"
name="slotWin"
regexp="y"
script="slotsWin"
sequence="100"
>
</trigger>
<trigger
group="Slots"
match="^Sorry, you're not a winner\. Try again soon!$"
name="noWin"
regexp="y"
script="noPay"
sequence="100"
>
</trigger>
<trigger
group="Slots"
match="^Game pays: ([\d,]+) credits"
name="gameCredits"
regexp="y"
script="creditsData"
sequence="100"
>
</trigger>
</triggers>
<!-- Aliases -->
<aliases>
<alias
match="^slot(?:s|S)tats$"
enabled="y"
regexp="y"
group="Slots"
script="showStats"
sequence="100"
>
</alias>
<alias
match="^slot(?:d|D)ata$"
enabled="y"
regexp="y"
group="Slots"
script="showData"
sequence="100"
>
</alias>
<alias
match="^slot(?:r|R)eset$"
enabled="y"
regexp="y"
group="Slots"
script="resetSlots"
sequence="100"
>
</alias>
<alias
match="^slot(?:h|H)elp$"
enabled="y"
regexp="y"
group="Slots"
script="showHelp"
sequence="100"
>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
require 'commas'
require 'serialize'
require 'tprint'
function resetSlots()
SetVariable("slotTries", 0)
SetVariable("coinsSpent", 0)
SetVariable("slotPay", 0)
creditsTable = {}
SetVariable("creditsTable", serialize.save("creditsTable"))
end
function OnPluginInstall()
if not GetVariable("slotTries") then
SetVariable("slotTries", 0)
end
if not GetVariable("coinsSpent") then
SetVariable("coinsSpent", 0)
end
if not GetVariable("slotPay") then
SetVariable("slotPay", 0)
end
if not GetVariable("creditsTable") then
creditsTable = {}
else
assert(loadstring(GetVariable("creditsTable"))) ()
end
ColourNote("white", "blue", "Type '", "yellow", "blue", "slotStats", "white", "blue", "' to view stats. Type '", "yellow", "blue", "slotData", "white", "blue", "' to show other data.")
end
function slotStart(name, line, args)
EnableTrigger("noWin")
EnableTrigger("slotWin")
EnableTrigger("gameCredits")
SetVariable("slotTries", tonumber(GetVariable("slotTries")) + 1)
local current, spent = tonumber(GetVariable("coinsSpent")), string.gsub(args[1], ",", "")
local totalSpent = current + tonumber(spent)
SetVariable("coinsSpent", totalSpent)
end
function slotsWin(name, line, args)
EnableTrigger("noWin", false)
EnableTrigger("slotWin", false)
EnableTrigger("gameCredits", false)
local current, pay = tonumber(GetVariable("slotPay")), string.gsub(args[1], ",", "")
local totalPay = current+tonumber(pay)
SetVariable("slotPay", totalPay)
end
function noPay(name, line, args)
EnableTrigger("noWin", false)
EnableTrigger("slotWin", false)
end
function showStats()
local spent, pay, tries = tonumber(GetVariable("coinsSpent")), tonumber(GetVariable("slotPay")), tonumber(GetVariable("slotTries"))
local aheadBehind = ""
local aheadBehindColour = "cyan"
local difference = pay-spent
print(string.rep("=",79))
ColourNote("white", "", "You have spent ", "yellow", "", commas(spent), "white", "", " gold coins over ", "cyan", "", commas(tries), "white", "", " spins, winning ", "yellow", "", commas(pay), "white", "", " gold.")
if difference < 0 then
aheadBehind = "behind"
aheadBehindColour = "red"
difference = 0-difference
elseif difference > 0 then
aheadBehind = "ahead of"
aheadBehindColour = "green"
elseif difference == 0 then
aheadBehind = "even with"
end
ColourNote("white", "", "You are ", aheadBehindColour, "", aheadBehind, "white", "", " the House by ", "yellow", "", commas(difference), "white", "", " gold.")
ColourNote("white", "", "Average winnings: ", "yellow", "", commas(math.floor(pay/tries)), "white", "", " gold.")
print(string.rep("=", 79))
end
function creditsData(name, line, args)
if not creditsTable then creditsTable = {} end
local creditsEarned = string.gsub(args[1], ",", "") .. "c"
if not creditsTable[creditsEarned] then
creditsTable[creditsEarned] = 1
else
creditsTable[creditsEarned] = creditsTable[creditsEarned] + 1
end
SetVariable("creditsTable", serialize.save("creditsTable"))
end
function showData()
local sortTable = {}
if tonumber(GetVariable("slotTries")) > 0 then
for i,v in pairs(creditsTable) do
table.insert(sortTable, {credits = string.gsub(i, "c", ""), times = v})
end
table.sort(sortTable, function (a, b) return a.times > b.times end)
print(string.rep("=", 79))
for _,v in ipairs(sortTable) do
creditsStr = v.credits .. " credits"
if creditsStr == "0 credits" then
winCredits = tonumber(GetVariable("slotTries")) - v.times
winCredits = string.format("%.1f", 100*(winCredits/tonumber(GetVariable("slotTries")))) .. "%"
end
creditsStr = creditsStr .. string.rep(" ", 15-#creditsStr) .. ": "
ColourNote("white", "", creditsStr, "cyan", "", v.times, "green", "", " (" .. string.format("%.1f", 100*(tonumber(v.times)/tonumber(GetVariable("slotTries")))) .. "%)")
end
print("")
ColourNote("white", "", "Win percentage: ", "green", "", winCredits or "0.0%")
print(string.rep("=", 79))
else
ColourNote("white", "blue", "You have not logged any slots data yet!")
end
end
function showHelp()
print("slotreset: Resets your slot data")
print("slotstats: Displays winnings")
print("slotdata: Displays percentages")
end
]]>
</script>
</muclient>