PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: nErBoS on 27 July, 2004, 21:24:32

Title: Slot Machine
Post by: nErBoS on 27 July, 2004, 21:24:32
Hi,

Have fun guys...

--## Slot Machine
--## Idea given by DJ-Valhala
--## Made by nErBoS
--## Commands:
--## +account - Creates an account with your nick
--## +status - Show the Status of your account
--## +rank - Show the TOP10 of the Slot Machine Game
--## +loan - Ask for more Credits to the Bank
--## +repay - Repay the credits own to the Bank
--## +play - Play in the Slot Machine

sBot = "Slot-Machine"

arrResults = {
["BAR"] = 100,
["7"] = 50,
["@"] = 25,
["$"] = 10,
["?"] = 5,
["?"] = 3,
["&"] = 1,
}
arrAux = {
100,
50,
25,
10,
5,
3,
1,
}
arrCredit = {}
fCredit = "credit.dat"

--## Configuration ##--

iCredit = 50 -- Number of Credits that user will have in the beginnig
iCreditPlay = 2 -- Number of Credits tha a user needs to play
iCreditLoan = 1000 -- Number of Credits that a user can loan
uLaterPtokax = 0 -- 0 if you are using a Ptokax version 0.3.3.0 or higher
-- 1 if you are using a Ptokax version lower then 0.3.3.0

--## END ##--

function Main()
frmHub:RegBot(sBot)
LoadFromFile(fCredit)
end

function OnExit()
SaveToFile(fCredit , arrCredit , "arrCredit")
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "+account") then
CreateAcount(user)
return 1
elseif(cmd == "+status") then
SeeStatus(user)
return 1
elseif (cmd == "+rank") then
SeeRanking(user)
return 1
elseif (cmd == "+loan") then
LoanCredits(user, data)
return 1
elseif (cmd == "+repay") then
RepayLoan(user, data)
return 1
elseif (cmd == "+play") then
PlaySM(user)
return 1
end
end
end

function CreateAcount(user)
if (arrCredit[user.sName] == nil) then
arrCredit[user.sName] = {}
arrCredit[user.sName]["Credit"] = iCredit
arrCredit[user.sName]["Loan"] = 0
user:SendPM(sBot, "You have been giving a account with 50 credits. Have FUN !!")
if (uLaterPtokax == 1) then
OnExit()
end
else
user:SendPM(sBot, "You already have a acount, type +status to see yout account status.")
end
end

function SeeStatus(user)
local sTmp = ""
if (arrCredit[user.sName] ~= nil) then
sTmp = sTmp.."\t\t--## "..user.sName.." Account ##--\r\n\r\n"
sTmp = sTmp.."\t\tYour Credit: "..arrCredit[user.sName]["Credit"].."\r\n"
sTmp = sTmp.."\t\tYour have Loan: "..arrCredit[user.sName]["Loan"].."\r\n"
sTmp = sTmp.."\t\tYour Position in the Ranking: "..UserPosition(user.sName).."\r\n"
else
sTmp = "You don't have an account, to create one type +account."
end
user:SendPM(sBot, sTmp)
end

function UserPosition(nick)
local pos,count,usr,aux = 1,arrCredit[nick]["Credit"]-arrCredit[nick]["Loan"]
for usr, aux in arrCredit do
local usrCount = arrCredit[usr]["Credit"]-arrCredit[usr]["Loan"]
if (usr ~= nick and usrCount > count) then
pos = pos + 1
end
end
return pos
end

function SeeRanking(user)
local sTmp,pos,top,usr,aux = "The Top 10 Ranking of Slot Machine:\r\n\r\n",1,10
if (NumberOfPlayers() == 0) then
user:SendPM(sBot, "There aren't any players for the moment.")
return 0
elseif (NumberOfPlayers() < top) then
top = tonumber(NumberOfPlayers())
end
while pos < top+1 do
for usr, aux in arrCredit do
if (pos == UserPosition(usr)) then
sTmp = sTmp..pos.."\tNick: "..usr.."   --## Credit: "..arrCredit[usr]["Credit"].." Loan: "..arrCredit[usr]["Loan"].." ##--\r\n"
break
end
end
pos = pos + 1
end
user:SendPM(sBot, sTmp)
end

function NumberOfPlayers()
local count,usr,aux = 0
for usr, aux in arrCredit do
count = count + 1
end
return count
end

function LoanCredits(user, data)
local s,e,credit = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (credit == nil or tonumber(credit) == nil) then
user:SendPM(sBot, "Syntax Error, +loan , you must write a number in the credit.")
elseif (arrCredit[user.sName] ~= nil) then
if (arrCredit[user.sName]["Loan"] + tonumber(credit) > 1000) then
user:SendPM(sBot, "You can't make any more loan you have obtain the max loan that is "..iCreditLoan.." Credits.")
else
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] + tonumber(credit)
arrCredit[user.sName]["Loan"] = arrCredit[user.sName]["Loan"] + tonumber(credit)
user:SendPM(sBot, "You have been loan "..credit.." Credits.")
if (uLaterPtokax == 1) then
OnExit()
end
end
else
user:SendPM(sBot, "You don't have a acount, type +account to create one.")
end
end

function RepayLoan(user, data)
local s,e,credit = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (credit == nil or tonumber(credit) == nil) then
user:SendPM(sBot, "Syntax Error, +repay , you must write a number in the credit.")
elseif (arrCredit[user.sName] ~= nil) then
if (tonumber(credit) > arrCredit[user.sName]["Loan"]) then
user:SendPM(sBot, "You are repaying more then you own.")
else
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] - tonumber(credit)
arrCredit[user.sName]["Loan"] = arrCredit[user.sName]["Loan"] - tonumber(credit)
user:SendPM(sBot, "You have repay "..credit.." Credits.")
if (uLaterPtokax == 1) then
OnExit()
end
end
else
user:SendPM(sBot, "You don't have a acount, type +account to create one.")
end
end

function PlaySM(user)
if (arrCredit[user.sName] ~= nil) then
if (arrCredit[user.sName]["Credit"] < 2) then
user:SendPM(sBot, "You don't have enough credits to play in Slot Machine. You need "..iCreditPlay.." Credits to play.")
else
local sSMDraw = ""
sSMDraw = sSMDraw.."You have "..arrCredit[user.sName]["Credit"].." Credits\r\n\r\n"
sSMDraw = sSMDraw.."\t             _________\r\n"
sSMDraw = sSMDraw.."\t           /                   \\\r\n"
sSMDraw = sSMDraw.."\t          !  Good Luck  !\r\n"
sSMDraw = sSMDraw.."\t    ___!___________!___\r\n"
sSMDraw = sSMDraw.."\t  /                                    \\\r\n"
sSMDraw = sSMDraw.."\t /       SLOT MACHINE      \\\r\n"
sSMDraw = sSMDraw.."\t !    ________________      !\r\n"
sSMDraw = sSMDraw.."\t !   !          !          !           !    !\r\n"
local draw,won = DealGame()
sSMDraw = sSMDraw..draw
sSMDraw = sSMDraw.."\t !   !_____!_____!_____ !    !\r\n"
sSMDraw = sSMDraw.."\t !                                          !\r\n"
sSMDraw = sSMDraw.."\t !                                          !\r\n"
sSMDraw = sSMDraw.."\t !            _________            !\r\n"
sSMDraw = sSMDraw.."\t !           !_________!           !\r\n"
sSMDraw = sSMDraw.."\t !                                          !\r\n"
sSMDraw = sSMDraw.."\t !_____________________!\r\n\r\n"
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] + tonumber(won)
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] - iCreditPlay
sSMDraw = sSMDraw.."Now you have "..arrCredit[user.sName]["Credit"].." Credits.\r\n"
user:SendPM(sBot, sSMDraw)
if (uLaterPtokax == 1) then
OnExit()
end
end
else
user:SendPM(sBot, "You don't have a acount, type +account to create one.")
end
end

function DealGame()
local play1,play2,play3,draw,won = arrAux[random(1, getn(arrAux))],arrAux[random(1, getn(arrAux))],arrAux[random(1, getn(arrAux))],""
draw = draw.."\t !   ! "..DrawSimbol(play1).." ! "..DrawSimbol(play2).."  ! "..DrawSimbol(play3).."  !    !\r\n"
if (tonumber(play1) == tonumber(play2) and tonumber(play1) == tonumber(play3)) then
return draw,play1
elseif (tonumber(play1) == tonumber(play2) or tonumber(play2) == tonumber(play3)) then
return draw,iCreditPlay
else
return draw,0
end
end

function DrawSimbol(number)
number = tonumber(number)
if (number == 100) then
return "BAR"
elseif (number == 25) then
return "  @  "
elseif (number == 5) then
return "   ?  "
elseif (number == 50) then
return "   7   "
elseif (number == 10) then
return "   $  "
elseif (number == 1) then
return "   &   "
else
local simbol,num
for simbol, num in arrResults do
if (tonumber(num) == number) then
return "   "..simbol.."   "
end
end
end
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";
sTmp = ""

sTmp = sTmp..sTab..sTableName.." = {\n"

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end

sTmp = sTmp..",\n"
end

sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Best regards, nErBoS
Title: Cool
Post by: Smulf on 27 July, 2004, 21:36:08
HA! Cool script nErBoS, i'm sure that you realy did have fun making that one:D And also thx for the idea-maker DJ-Valhala !

I can't quiet understand when u are writing: uLaterPtokax = 0 -- 0 if you are using a Ptokax version 0.3.3.0 or higher
-- 1 if you are using a Ptokax version lower then 0.3.3.0
 

I'm using 0.3.2.6 TD4 and it works... No offence just a question for one that don't know the answer:)

Thx for it:)
Title:
Post by: nErBoS on 27 July, 2004, 23:07:06
Hi,

It works almost the same for all version, the difference is to save the tables there is on more function in 0.3.3.0 that is very useful, so for the other versions it has to be save other way so if you are using TD4 better use uLaterPtokax = 1 or else you can lose the information of the accounts of your users  :))  ;)

Best regards, nErBoS
Title:
Post by: Smulf on 29 July, 2004, 16:22:48
Okay, thx
Title:
Post by: witch on 29 July, 2004, 20:48:17
..hmmm i thout it was my idea  :rolleyes:
Title:
Post by: witch on 29 July, 2004, 21:53:17
..but Thanx nErBoS for the script!!! Working Great !!! I tested !!!  :D
Title:
Post by: nErBoS on 29 July, 2004, 23:42:09
Hi,

Little fix...

--## Slot Machine 1.0
--## Idea given by witch and requested by DJ-Valhala
--## Fixed a Bug in Rank (thanks DJ-Valhala)
--## Made by nErBoS
--## Commands:
--## +account - Creates an account with your nick
--## +status - Show the Status of your account
--## +rank - Show the TOP10 of the Slot Machine Game
--## +loan - Ask for more Credits to the Bank
--## +repay - Repay the credits own to the Bank
--## +play - Play in the Slot Machine

sBot = "Slot-Machine"

arrResults = {
["BAR"] = 100,
["7"] = 50,
["@"] = 25,
["$"] = 10,
["?"] = 5,
["?"] = 3,
["&"] = 1,
}
arrAux = {
100,
50,
25,
10,
5,
3,
1,
}
arrCredit = {}
fCredit = "credit.dat"

--## Configuration ##--

iCredit = 50 -- Number of Credits that user will have in the beginnig
iCreditPlay = 2 -- Number of Credits tha a user needs to play
iCreditLoan = 1000 -- Number of Credits that a user can loan
uLaterPtokax = 0 -- 0 if you are using a Ptokax version 0.3.3.0 or higher
-- 1 if you are using a Ptokax version lower then 0.3.3.0

--## END ##--

function Main()
frmHub:RegBot(sBot)
LoadFromFile(fCredit)
end

function OnExit()
SaveToFile(fCredit , arrCredit , "arrCredit")
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "+account") then
CreateAcount(user)
return 1
elseif(cmd == "+status") then
SeeStatus(user)
return 1
elseif (cmd == "+rank") then
SeeRanking(user)
return 1
elseif (cmd == "+loan") then
LoanCredits(user, data)
return 1
elseif (cmd == "+repay") then
RepayLoan(user, data)
return 1
elseif (cmd == "+play") then
PlaySM(user)
return 1
end
end
end

function CreateAcount(user)
if (arrCredit[user.sName] == nil) then
arrCredit[user.sName] = {}
arrCredit[user.sName]["Credit"] = iCredit
arrCredit[user.sName]["Loan"] = 0
user:SendPM(sBot, "You have been giving a account with 50 credits. Have FUN !!")
if (uLaterPtokax == 1) then
OnExit()
end
else
user:SendPM(sBot, "You already have a acount, type +status to see yout account status.")
end
end

function SeeStatus(user)
local sTmp = ""
if (arrCredit[user.sName] ~= nil) then
sTmp = sTmp.."\t\t--## "..user.sName.." Account ##--\r\n\r\n"
sTmp = sTmp.."\t\tYour Credit: "..arrCredit[user.sName]["Credit"].."\r\n"
sTmp = sTmp.."\t\tYour have Loan: "..arrCredit[user.sName]["Loan"].."\r\n"
sTmp = sTmp.."\t\tYour Position in the Ranking: "..UserPosition(user.sName).."\r\n"
else
sTmp = "You don't have an account, to create one type +account."
end
user:SendPM(sBot, sTmp)
end

function UserPosition(nick)
local pos,count,tableAux,usr,aux,usrCount = 1,arrCredit[nick]["Credit"]-arrCredit[nick]["Loan"],{}
for usr, aux in arrCredit do
usrCount = arrCredit[usr]["Credit"]-arrCredit[usr]["Loan"]
if (usr ~= nick and CheckMacth(tableAux,usrCount) == 0 and usrCount > count) then
tableAux[usrCount] = 1
pos = pos + 1
end
end
tableAux = nil
return pos
end

function CheckMacth(table, value)
if (type(table) == "table") then
local number,aux
for number, aux in table do
if (tonumber(number) == tonumber(value)) then
return 1
end
end
end
return 0
end

function SeeRanking(user)
local sTmp,pos,top,match,usr,aux = "The Top 10 Ranking of Slot Machine:\r\n\r\n",1,10,0
if (NumberOfPlayers() == 0) then
user:SendPM(sBot, "There aren't any players for the moment.")
return 0
elseif (NumberOfPlayers() < top) then
top = tonumber(NumberOfPlayers())
end
while pos < top+1 do
for usr, aux in arrCredit do
if (pos == UserPosition(usr)) then
if (match == 0) then
sTmp = sTmp..pos
end
sTmp = sTmp.."\tNick: "..usr.."   --## Credit: "..arrCredit[usr]["Credit"].." Loan: "..arrCredit[usr]["Loan"].." ##--\r\n"
match = 1
end
end
match = 0
pos = pos + 1
end
user:SendPM(sBot, sTmp)
end

function NumberOfPlayers()
local count,usr,aux = 0
for usr, aux in arrCredit do
count = count + 1
end
return count
end

function LoanCredits(user, data)
local s,e,credit = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (credit == nil or tonumber(credit) == nil) then
user:SendPM(sBot, "Syntax Error, +loan , you must write a number in the credit.")
elseif (arrCredit[user.sName] ~= nil) then
if (arrCredit[user.sName]["Loan"] + tonumber(credit) > 1000) then
user:SendPM(sBot, "You can't make any more loan you have obtain the max loan that is "..iCreditLoan.." Credits.")
else
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] + tonumber(credit)
arrCredit[user.sName]["Loan"] = arrCredit[user.sName]["Loan"] + tonumber(credit)
user:SendPM(sBot, "You have been loan "..credit.." Credits.")
if (uLaterPtokax == 1) then
OnExit()
end
end
else
user:SendPM(sBot, "You don't have a acount, type +account to create one.")
end
end

function RepayLoan(user, data)
local s,e,credit = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (credit == nil or tonumber(credit) == nil) then
user:SendPM(sBot, "Syntax Error, +repay , you must write a number in the credit.")
elseif (arrCredit[user.sName] ~= nil) then
if (tonumber(credit) > arrCredit[user.sName]["Loan"]) then
user:SendPM(sBot, "You are repaying more then you own.")
else
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] - tonumber(credit)
arrCredit[user.sName]["Loan"] = arrCredit[user.sName]["Loan"] - tonumber(credit)
user:SendPM(sBot, "You have repay "..credit.." Credits.")
if (uLaterPtokax == 1) then
OnExit()
end
end
else
user:SendPM(sBot, "You don't have a acount, type +account to create one.")
end
end

function PlaySM(user)
if (arrCredit[user.sName] ~= nil) then
if (arrCredit[user.sName]["Credit"] < 2) then
user:SendPM(sBot, "You don't have enough credits to play in Slot Machine. You need "..iCreditPlay.." Credits to play.")
else
local sSMDraw = ""
sSMDraw = sSMDraw.."You have "..arrCredit[user.sName]["Credit"].." Credits\r\n\r\n"
sSMDraw = sSMDraw.."\t             _________\r\n"
sSMDraw = sSMDraw.."\t           /                   \\\r\n"
sSMDraw = sSMDraw.."\t          !  Good Luck  !\r\n"
sSMDraw = sSMDraw.."\t    ___!___________!___\r\n"
sSMDraw = sSMDraw.."\t  /                                    \\\r\n"
sSMDraw = sSMDraw.."\t /       SLOT MACHINE      \\\r\n"
sSMDraw = sSMDraw.."\t !    ________________      !\r\n"
sSMDraw = sSMDraw.."\t !   !          !          !           !    !\r\n"
local draw,won = DealGame()
sSMDraw = sSMDraw..draw
sSMDraw = sSMDraw.."\t !   !_____!_____!_____ !    !\r\n"
sSMDraw = sSMDraw.."\t !                                          !\r\n"
sSMDraw = sSMDraw.."\t !                                          !\r\n"
sSMDraw = sSMDraw.."\t !            _________            !\r\n"
sSMDraw = sSMDraw.."\t !           !_________!           !\r\n"
sSMDraw = sSMDraw.."\t !                                          !\r\n"
sSMDraw = sSMDraw.."\t !_____________________!\r\n\r\n"
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] + tonumber(won)
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] - iCreditPlay
sSMDraw = sSMDraw.."You have WON "..won.." Credits.\r\n"
sSMDraw = sSMDraw.."Now you have "..arrCredit[user.sName]["Credit"].." Credits.\r\n"
user:SendPM(sBot, sSMDraw)
if (uLaterPtokax == 1) then
OnExit()
end
end
else
user:SendPM(sBot, "You don't have a acount, type +account to create one.")
end
end

function DealGame()
local play1,play2,play3,draw,won = arrAux[random(1, getn(arrAux))],arrAux[random(1, getn(arrAux))],arrAux[random(1, getn(arrAux))],""
draw = draw.."\t !   ! "..DrawSimbol(play1).." ! "..DrawSimbol(play2).."  ! "..DrawSimbol(play3).."  !    !\r\n"
if (tonumber(play1) == tonumber(play2) and tonumber(play1) == tonumber(play3)) then
return draw,play1
elseif (tonumber(play1) == tonumber(play2) or tonumber(play2) == tonumber(play3)) then
return draw,iCreditPlay
else
return draw,0
end
end

function DrawSimbol(number)
number = tonumber(number)
if (number == 100) then
return "BAR"
elseif (number == 25) then
return "  @  "
elseif (number == 5) then
return "   ?  "
elseif (number == 50) then
return "   7   "
elseif (number == 10) then
return "   $  "
elseif (number == 1) then
return "   &   "
else
local simbol,num
for simbol, num in arrResults do
if (tonumber(num) == number) then
return "   "..simbol.."   "
end
end
end
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";
sTmp = ""

sTmp = sTmp..sTab..sTableName.." = {\n"

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end

sTmp = sTmp..",\n"
end

sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Don't want to see sad pepole in here, have fun.

Best regards, nErBoS
Title:
Post by: witch on 30 July, 2004, 00:32:48
BETTER  :D
Title:
Post by: D-J Valhala on 30 July, 2004, 10:39:01
:D
Title: probs with Slot machine game script
Post by: MovieMaster on 01 August, 2004, 15:49:50
Syntax error: function arguments expected;
  last token read: `:' at line 13 in file

I get this error message when I try to run the game.  :(

I run Ptokax 0.330 15.25. What is wrong?? I would really like to get this game to work, because I really like slot machine games.  8)
Title: try this way
Post by: odyny on 08 August, 2004, 07:00:33
QuoteOriginally posted by MovieMaster
Syntax error: function arguments expected;
  last token read: `:' at line 13 in file

I get this error message when I try to run the game.  :(

I run Ptokax 0.330 15.25. What is wrong?? I would really like to get this game to work, because I really like slot machine games.  8)



hehehe i think you have selected this way:

code:----------------------------------------------------------------------------------## Slot Machine 1.0
--## Idea given by witch and requested by DJ-Valhala
--## Fixed a Bug in Rank (thanks DJ-Valhala)
--## Made by nErBoS
--## Commands:
--##   +account   - Creates an account with your nick
--##   +status      - Show the Status of your account
--##   +rank      - Show the TOP10 of the Slot Machine Game
--##   +loan    - Ask for more Credits to the Bank
--##   +repay    - Repay the credits own to the Bank
--##   +play      - Play in the Slot Machine

sBot = "Slot-Machine"
....................scripts continues...............

you just have to ctrl C ctrl V this way:
## Slot Machine 1.0
--## Idea given by witch and requested by DJ-Valhala
--## Fixed a Bug in Rank (thanks DJ-Valhala)
--## Made by nErBoS
--## Commands:
--##   +account   - Creates an account with your nick
--##   +status      - Show the Status of your account
--##   +rank      - Show the TOP10 of the Slot Machine Game
--##   +loan    - Ask for more Credits to the Bank
--##   +repay    - Repay the credits own to the Bank
--##   +play      - Play in the Slot Machine

sBot = "Slot-Machine"
...................scripts continues...........

 :)
Title:
Post by: nErBoS on 12 August, 2004, 18:09:56
Hi,

The problem should be in the Bot Name, maybe you forgot to put the name with "bot_name"

Best regards, nErBoS

Back to my vacations :)
Title:
Post by: (UK)Ridaz on 12 August, 2004, 18:42:37
Great work, i love it.

Think i would like to see Jackpot winners announced in main chat if possible?

Maybe something like this?
*********************************************
               J A C K P O T       W I N N E R

  (UK)Ridaz has just scooped the top prize of xxx Credits.

                   Why not join him by typing

+account                 - Creates an account with your nick
+status      - Show the Status of your account
+rank      - Show the TOP10 of the Slot Machine Game
+loan    - Ask for more Credits to the Bank
+repay    - Repay the credits own to the Bank
+play      - Play in the Slot Machine
*********************************************
I have also altered my "+play" to "z" as its easier to type when your playing fast.

Many Thanks
Ridaz.
Title:
Post by: nErBoS on 12 August, 2004, 18:45:16
Hi,

Yes i can add that, when i get back i will do that. Its faster using CTRL+C and CTRL+V  :D  :P

Best regards, nErBoS
Title:
Post by: (UK)Ridaz on 12 August, 2004, 18:53:06
:D  :D  :D
I was using CTRL+C and CTRL+V but i've already had to loan 500 credits and my fingers are aching   :]

Was trying to get a good score before my Ops get home ;)

Many Many Thanks,
Ridaz
Title:
Post by: nErBoS on 15 August, 2004, 21:24:51
Hi,

Have fun...

--## Slot Machine 1.1
--## Idea given by witch and requested by DJ-Valhala
--## Winner Anounce idea given by (UK)Ridaz
--## Fixed a Bug in Rank (thanks DJ-Valhala)
--## Made by nErBoS
--## Commands:
--## +account - Creates an account with your nick
--## +status - Show the Status of your account
--## +rank - Show the TOP10 of the Slot Machine Game
--## +loan - Ask for more Credits to the Bank
--## +repay - Repay the credits own to the Bank
--## +play - Play in the Slot Machine

sBot = "Slot-Machine"

arrResults = {
["BAR"] = 100,
["7"] = 50,
["@"] = 25,
["$"] = 10,
["?"] = 5,
["?"] = 3,
["&"] = 1,
}
arrAux = {
100,
50,
25,
10,
5,
3,
1,
}
arrCredit = {}
fCredit = "credit.dat"

--## Configuration ##--

iCredit = 50 -- Number of Credits that user will have in the beginnig
iCreditPlay = 2 -- Number of Credits tha a user needs to play
iCreditLoan = 1000 -- Number of Credits that a user can loan
uLaterPtokax = 0 -- 0 if you are using a Ptokax version 0.3.3.0 or higher
-- 1 if you are using a Ptokax version lower then 0.3.3.0

--## END ##--

function Main()
frmHub:RegBot(sBot)
LoadFromFile(fCredit)
end

function OnExit()
SaveToFile(fCredit , arrCredit , "arrCredit")
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "+account") then
CreateAcount(user)
return 1
elseif(cmd == "+status") then
SeeStatus(user)
return 1
elseif (cmd == "+rank") then
SeeRanking(user)
return 1
elseif (cmd == "+loan") then
LoanCredits(user, data)
return 1
elseif (cmd == "+repay") then
RepayLoan(user, data)
return 1
elseif (cmd == "+play") then
PlaySM(user)
return 1
end
end
end

function CreateAcount(user)
if (arrCredit[user.sName] == nil) then
arrCredit[user.sName] = {}
arrCredit[user.sName]["Credit"] = iCredit
arrCredit[user.sName]["Loan"] = 0
user:SendPM(sBot, "You have been giving a account with 50 credits. Have FUN !!")
if (uLaterPtokax == 1) then
OnExit()
end
else
user:SendPM(sBot, "You already have a acount, type +status to see yout account status.")
end
end

function SeeStatus(user)
local sTmp = ""
if (arrCredit[user.sName] ~= nil) then
sTmp = sTmp.."\t\t--## "..user.sName.." Account ##--\r\n\r\n"
sTmp = sTmp.."\t\tYour Credit: "..arrCredit[user.sName]["Credit"].."\r\n"
sTmp = sTmp.."\t\tYour have Loan: "..arrCredit[user.sName]["Loan"].."\r\n"
sTmp = sTmp.."\t\tYour Position in the Ranking: "..UserPosition(user.sName).."\r\n"
else
sTmp = "You don't have an account, to create one type +account."
end
user:SendPM(sBot, sTmp)
end

function UserPosition(nick)
local pos,count,tableAux,usr,aux,usrCount = 1,arrCredit[nick]["Credit"]-arrCredit[nick]["Loan"],{}
for usr, aux in arrCredit do
usrCount = arrCredit[usr]["Credit"]-arrCredit[usr]["Loan"]
if (usr ~= nick and CheckMacth(tableAux,usrCount) == 0 and usrCount > count) then
tableAux[usrCount] = 1
pos = pos + 1
end
end
tableAux = nil
return pos
end

function CheckMacth(table, value)
if (type(table) == "table") then
local number,aux
for number, aux in table do
if (tonumber(number) == tonumber(value)) then
return 1
end
end
end
return 0
end

function SeeRanking(user)
local sTmp,pos,top,match,usr,aux = "The Top 10 Ranking of Slot Machine:\r\n\r\n",1,10,0
if (NumberOfPlayers() == 0) then
user:SendPM(sBot, "There aren't any players for the moment.")
return 0
elseif (NumberOfPlayers() < top) then
top = tonumber(NumberOfPlayers())
end
while pos < top+1 do
for usr, aux in arrCredit do
if (pos == UserPosition(usr)) then
if (match == 0) then
sTmp = sTmp..pos
end
sTmp = sTmp.."\tNick: "..usr.."   --## Credit: "..arrCredit[usr]["Credit"].." Loan: "..arrCredit[usr]["Loan"].." ##--\r\n"
match = 1
end
end
match = 0
pos = pos + 1
end
user:SendPM(sBot, sTmp)
end

function NumberOfPlayers()
local count,usr,aux = 0
for usr, aux in arrCredit do
count = count + 1
end
return count
end

function LoanCredits(user, data)
local s,e,credit = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (credit == nil or tonumber(credit) == nil) then
user:SendPM(sBot, "Syntax Error, +loan , you must write a number in the credit.")
elseif (arrCredit[user.sName] ~= nil) then
if (arrCredit[user.sName]["Loan"] + tonumber(credit) > 1000) then
user:SendPM(sBot, "You can't make any more loan you have obtain the max loan that is "..iCreditLoan.." Credits.")
else
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] + tonumber(credit)
arrCredit[user.sName]["Loan"] = arrCredit[user.sName]["Loan"] + tonumber(credit)
user:SendPM(sBot, "You have been loan "..credit.." Credits.")
if (uLaterPtokax == 1) then
OnExit()
end
end
else
user:SendPM(sBot, "You don't have a acount, type +account to create one.")
end
end

function RepayLoan(user, data)
local s,e,credit = strfind(data, "%b<>%s+%S+%s+(%S+)")
if (credit == nil or tonumber(credit) == nil) then
user:SendPM(sBot, "Syntax Error, +repay , you must write a number in the credit.")
elseif (arrCredit[user.sName] ~= nil) then
if (tonumber(credit) > arrCredit[user.sName]["Loan"]) then
user:SendPM(sBot, "You are repaying more then you own.")
else
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] - tonumber(credit)
arrCredit[user.sName]["Loan"] = arrCredit[user.sName]["Loan"] - tonumber(credit)
user:SendPM(sBot, "You have repay "..credit.." Credits.")
if (uLaterPtokax == 1) then
OnExit()
end
end
else
user:SendPM(sBot, "You don't have a acount, type +account to create one.")
end
end

function PlaySM(user)
if (arrCredit[user.sName] ~= nil) then
if (arrCredit[user.sName]["Credit"] < 2) then
user:SendPM(sBot, "You don't have enough credits to play in Slot Machine. You need "..iCreditPlay.." Credits to play.")
else
local sSMDraw = ""
sSMDraw = sSMDraw.."You have "..arrCredit[user.sName]["Credit"].." Credits\r\n\r\n"
sSMDraw = sSMDraw.."\t             _________\r\n"
sSMDraw = sSMDraw.."\t           /                   \\\r\n"
sSMDraw = sSMDraw.."\t          !  Good Luck  !\r\n"
sSMDraw = sSMDraw.."\t    ___!___________!___\r\n"
sSMDraw = sSMDraw.."\t  /                                    \\\r\n"
sSMDraw = sSMDraw.."\t /       SLOT MACHINE      \\\r\n"
sSMDraw = sSMDraw.."\t !    ________________      !\r\n"
sSMDraw = sSMDraw.."\t !   !          !          !           !    !\r\n"
local draw,won = DealGame()
sSMDraw = sSMDraw..draw
sSMDraw = sSMDraw.."\t !   !_____!_____!_____ !    !\r\n"
sSMDraw = sSMDraw.."\t !                                          !\r\n"
sSMDraw = sSMDraw.."\t !                                          !\r\n"
sSMDraw = sSMDraw.."\t !            _________            !\r\n"
sSMDraw = sSMDraw.."\t !           !_________!           !\r\n"
sSMDraw = sSMDraw.."\t !                                          !\r\n"
sSMDraw = sSMDraw.."\t !_____________________!\r\n\r\n"
if (tonumber(won) == arrResults["BAR"]) then
JackPot(user)
end
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] + tonumber(won)
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] - iCreditPlay
sSMDraw = sSMDraw.."You have WON "..won.." Credits.\r\n"
sSMDraw = sSMDraw.."Now you have "..arrCredit[user.sName]["Credit"].." Credits.\r\n"
user:SendPM(sBot, sSMDraw)
if (uLaterPtokax == 1) then
OnExit()
end
end
else
user:SendPM(sBot, "You don't have a acount, type +account to create one.")
end
end

function JackPot(user)
local sTmp = "\r\n\r\n*********************************************\r\n"
sTmp = sTmp.."J A C K P O T W I N N E R\r\n\r\n"  
sTmp = sTmp..user.sName.." has just scooped the top prize of "..arrResults["BAR"].." Credits.\r\n\r\n"
sTmp = sTmp.."Why not join him by typing\r\n\r\n"
sTmp = sTmp.."+account - Creates an account with your nick\r\n"  
sTmp = sTmp.."+status - Show the Status of your account\r\n"  
sTmp = sTmp.."+rank - Show the TOP10 of the Slot Machine Game\r\n"  
sTmp = sTmp.."+loan - Ask for more Credits to the Bank\r\n"  
sTmp = sTmp.."+repay - Repay the credits own to the Bank\r\n"  
sTmp = sTmp.."+play - Play in the Slot Machine\r\n"  
sTmp = sTmp.."*********************************************\r\n"
SendToAll(sBot, sTmp)
end

function DealGame()
local play1,play2,play3,draw,won = arrAux[random(1, getn(arrAux))],arrAux[random(1, getn(arrAux))],arrAux[random(1, getn(arrAux))],""
draw = draw.."\t !   ! "..DrawSimbol(play1).." ! "..DrawSimbol(play2).."  ! "..DrawSimbol(play3).."  !    !\r\n"
if (tonumber(play1) == tonumber(play2) and tonumber(play1) == tonumber(play3)) then
return draw,play1
elseif (tonumber(play1) == tonumber(play2) or tonumber(play2) == tonumber(play3)) then
return draw,iCreditPlay
else
return draw,0
end
end

function DrawSimbol(number)
number = tonumber(number)
if (number == 100) then
return "BAR"
elseif (number == 25) then
return "  @  "
elseif (number == 5) then
return "   ?  "
elseif (number == 50) then
return "   7   "
elseif (number == 10) then
return "   $  "
elseif (number == 1) then
return "   &   "
else
local simbol,num
for simbol, num in arrResults do
if (tonumber(num) == number) then
return "   "..simbol.."   "
end
end
end
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";
sTmp = ""

sTmp = sTmp..sTab..sTableName.." = {\n"

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end

sTmp = sTmp..",\n"
end

sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

Best regards, nErBoS
Title:
Post by: (UK)Ridaz on 17 August, 2004, 17:46:16
Big thanks to nErBoS.

Got it up and running and just won a Jackpot too.
keep up the good work.


Ridaz
Title:
Post by: Sarpanch on 21 November, 2004, 20:34:39
Like the script 1 thing tho wen i restart the hub it looses all its rankings anyway of keeping them lyk the chat stats?
Title:
Post by: nErBoS on 21 November, 2004, 21:20:14
Hi,

Do you have this configurated ???...

uLaterPtokax = 0 -- 0 if you are using a Ptokax version 0.3.3.0 or higher
-- 1 if you are using a Ptokax version lower then 0.3.3.0

Best regards, nErBoS
Title:
Post by: Sarpanch on 22 November, 2004, 00:00:15
Ohh Thanks maet i didnt see that ive got it now thanks alot!!
Title:
Post by: Anna on 20 May, 2005, 15:59:59
sorry for confusing all of ya by reactivating yet another old script thread about one armed bandits :D just trying to find the best one...

Anyone up for converting this to lua 5?
Title:
Post by: Dessamator on 20 May, 2005, 16:23:31
--## Slot Machine 1.1
--## Idea given by witch and requested by DJ-Valhala
--## Winner Anounce idea given by (UK)Ridaz
--## Fixed a Bug in Rank (thanks DJ-Valhala)
--## Made by nErBoS
--## lua 5 by Dessamator
--## Commands:
--## +account - Creates an account with your nick
--## +status - Show the Status of your account
--## +rank - Show the TOP10 of the Slot Machine Game
--## +loan - Ask for more Credits to the Bank
--## +repay - Repay the credits own to the Bank
--## +play - Play in the Slot Machine

sBot = "Slot-Machine"

arrResults = {
["BAR"] = 100,
["7"] = 50,
["@"] = 25,
["$"] = 10,
["?"] = 5,
["€"] = 3,
["&"] = 1,
}
arrAux = {
100,
50,
25,
10,
5,
3,
1,
}
arrCredit = {}
fCredit = "credit.dat"

--## Configuration ##--

iCredit = 50 -- Number of Credits that user will have in the beginnig
iCreditPlay = 2 -- Number of Credits tha a user needs to play
iCreditLoan = 1000 -- Number of Credits that a user can loan
uLaterPtokax = 0 -- 0 if you are using a Ptokax version 0.3.3.0 or higher
-- 1 if you are using a Ptokax version lower then 0.3.3.0

--## END ##--

function Main()
frmHub:RegBot(sBot)
LoadFromFile(fCredit)
end

function OnExit()
SaveToFile(fCredit , arrCredit , "arrCredit")
end

function ChatArrival(user, data)
data = string.sub(data,1,string.len(data)-1)
s,e,cmd = string.find(data, "%b<>%s+(%S+)")
if (cmd == "+account") then
CreateAcount(user)
return 1
elseif(cmd == "+status") then
SeeStatus(user)
return 1
elseif (cmd == "+rank") then
SeeRanking(user)
return 1
elseif (cmd == "+loan") then
LoanCredits(user, data)
return 1
elseif (cmd == "+repay") then
RepayLoan(user, data)
return 1
elseif (cmd == "+play") then
PlaySM(user)
return 1
end
end
function ToArrival(user,data)
if (string.sub(data,1,5+string.len(sBot)) == "$To: "..sBot) then
ChatArrival(user,data)
end
end

function CreateAcount(user)
if (arrCredit[user.sName] == nil) then
arrCredit[user.sName] = {}
arrCredit[user.sName]["Credit"] = iCredit
arrCredit[user.sName]["Loan"] = 0
user:SendPM(sBot, "You have been giving a account with 50 credits. Have FUN !!")
if (uLaterPtokax == 1) then
OnExit()
end
else
user:SendPM(sBot, "You already have a acount, type +status to see yout account status.")
end
end

function SeeStatus(user)
local sTmp = ""
if (arrCredit[user.sName] ~= nil) then
sTmp = sTmp.."\t\t--## "..user.sName.." Account ##--\r\n\r\n"
sTmp = sTmp.."\t\tYour Credit: "..arrCredit[user.sName]["Credit"].."\r\n"
sTmp = sTmp.."\t\tYour have Loan: "..arrCredit[user.sName]["Loan"].."\r\n"
sTmp = sTmp.."\t\tYour Position in the Ranking: "..UserPosition(user.sName).."\r\n"
else
sTmp = "You don't have an account, to create one type +account."
end
user:SendPM(sBot, sTmp)
end

function UserPosition(nick)
local pos,count,tableAux,usr,aux,usrCount = 1,arrCredit[nick]["Credit"]-arrCredit[nick]["Loan"],{}
for usr, aux in arrCredit do
usrCount = arrCredit[usr]["Credit"]-arrCredit[usr]["Loan"]
if (usr ~= nick and CheckMacth(tableAux,usrCount) == 0 and usrCount > count) then
tableAux[usrCount] = 1
pos = pos + 1
end
end
tableAux = nil
return pos
end

function CheckMacth(table, value)
if (type(table) == "table") then
local number,aux
for number, aux in table do
if (tonumber(number) == tonumber(value)) then
return 1
end
end
end
return 0
end

function SeeRanking(user)
local sTmp,pos,top,match,usr,aux = "The Top 10 Ranking of Slot Machine:\r\n\r\n",1,10,0
if (NumberOfPlayers() == 0) then
user:SendPM(sBot, "There aren't any players for the moment.")
return 0
elseif (NumberOfPlayers() < top) then
top = tonumber(NumberOfPlayers())
end
while pos < top+1 do
for usr, aux in arrCredit do
if (pos == UserPosition(usr)) then
if (match == 0) then
sTmp = sTmp..pos
end
sTmp = sTmp.."\tNick: "..usr.."   --## Credit: "..arrCredit[usr]["Credit"].." Loan: "..arrCredit[usr]["Loan"].." ##--\r\n"
match = 1
end
end
match = 0
pos = pos + 1
end
user:SendPM(sBot, sTmp)
end

function NumberOfPlayers()
local count,usr,aux = 0
for usr, aux in arrCredit do
count = count + 1
end
return count
end

function LoanCredits(user, data)
local s,e,credit = string.find(data, "%b<>%s+%S+%s+(%S+)")
if (credit == nil or tonumber(credit) == nil) then
user:SendPM(sBot, "Syntax Error, +loan , you must write a number in the credit.")
elseif (arrCredit[user.sName] ~= nil) then
if (arrCredit[user.sName]["Loan"] + tonumber(credit) > 1000) then
user:SendPM(sBot, "You can't make any more loan you have obtain the max loan that is "..iCreditLoan.." Credits.")
else
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] + tonumber(credit)
arrCredit[user.sName]["Loan"] = arrCredit[user.sName]["Loan"] + tonumber(credit)
user:SendPM(sBot, "You have been loan "..credit.." Credits.")
if (uLaterPtokax == 1) then
OnExit()
end
end
else
user:SendPM(sBot, "You don't have a acount, type +account to create one.")
end
end

function RepayLoan(user, data)
local s,e,credit = string.find(data, "%b<>%s+%S+%s+(%S+)")
if (credit == nil or tonumber(credit) == nil) then
user:SendPM(sBot, "Syntax Error, +repay , you must write a number in the credit.")
elseif (arrCredit[user.sName] ~= nil) then
if (tonumber(credit) > arrCredit[user.sName]["Loan"]) then
user:SendPM(sBot, "You are repaying more then you own.")
else
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] - tonumber(credit)
arrCredit[user.sName]["Loan"] = arrCredit[user.sName]["Loan"] - tonumber(credit)
user:SendPM(sBot, "You have repay "..credit.." Credits.")
if (uLaterPtokax == 1) then
OnExit()
end
end
else
user:SendPM(sBot, "You don't have a acount, type +account to create one.")
end
end

function PlaySM(user)
if (arrCredit[user.sName] ~= nil) then
if (arrCredit[user.sName]["Credit"] < 2) then
user:SendPM(sBot, "You don't have enough credits to play in Slot Machine. You need "..iCreditPlay.." Credits to play.")
else
local sSMDraw = ""
sSMDraw = sSMDraw.."You have "..arrCredit[user.sName]["Credit"].." Credits\r\n\r\n"
sSMDraw = sSMDraw.."\t             _________\r\n"
sSMDraw = sSMDraw.."\t           /                   \\\r\n"
sSMDraw = sSMDraw.."\t          !  Good Luck  !\r\n"
sSMDraw = sSMDraw.."\t    ___!___________!___\r\n"
sSMDraw = sSMDraw.."\t  /                                    \\\r\n"
sSMDraw = sSMDraw.."\t /       SLOT MACHINE      \\\r\n"
sSMDraw = sSMDraw.."\t !    ________________      !\r\n"
sSMDraw = sSMDraw.."\t !   !          !          !           !    !\r\n"
local draw,won = DealGame()
sSMDraw = sSMDraw..draw
sSMDraw = sSMDraw.."\t !   !_____!_____!_____ !    !\r\n"
sSMDraw = sSMDraw.."\t !                                          !\r\n"
sSMDraw = sSMDraw.."\t !                                          !\r\n"
sSMDraw = sSMDraw.."\t !            _________            !\r\n"
sSMDraw = sSMDraw.."\t !           !_________!           !\r\n"
sSMDraw = sSMDraw.."\t !                                          !\r\n"
sSMDraw = sSMDraw.."\t !_____________________!\r\n\r\n"
if (tonumber(won) == arrResults["BAR"]) then
JackPot(user)
end
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] + tonumber(won)
arrCredit[user.sName]["Credit"] = arrCredit[user.sName]["Credit"] - iCreditPlay
sSMDraw = sSMDraw.."You have WON "..won.." Credits.\r\n"
sSMDraw = sSMDraw.."Now you have "..arrCredit[user.sName]["Credit"].." Credits.\r\n"
user:SendPM(sBot, sSMDraw)
if (uLaterPtokax == 1) then
OnExit()
end
end
else
user:SendPM(sBot, "You don't have a acount, type +account to create one.")
end
end

function JackPot(user)
local sTmp = "\r\n\r\n*********************************************\r\n"
sTmp = sTmp.."J A C K P O T W I N N E R\r\n\r\n"  
sTmp = sTmp..user.sName.." has just scooped the top prize of "..arrResults["BAR"].." Credits.\r\n\r\n"
sTmp = sTmp.."Why not join him by typing\r\n\r\n"
sTmp = sTmp.."+account - Creates an account with your nick\r\n"  
sTmp = sTmp.."+status - Show the Status of your account\r\n"  
sTmp = sTmp.."+rank - Show the TOP10 of the Slot Machine Game\r\n"  
sTmp = sTmp.."+loan - Ask for more Credits to the Bank\r\n"  
sTmp = sTmp.."+repay - Repay the credits own to the Bank\r\n"  
sTmp = sTmp.."+play - Play in the Slot Machine\r\n"  
sTmp = sTmp.."*********************************************\r\n"
SendToAll(sBot, sTmp)
end

function DealGame()
local play1,play2,play3,draw,won = arrAux[math.random(1, table.getn(arrAux))],arrAux[math.random(1, table.getn(arrAux))],arrAux[math.random(1, table.getn(arrAux))],""
draw = draw.."\t !   ! "..DrawSimbol(play1).." ! "..DrawSimbol(play2).."  ! "..DrawSimbol(play3).."  !    !\r\n"
if (tonumber(play1) == tonumber(play2) and tonumber(play1) == tonumber(play3)) then
return draw,play1
elseif (tonumber(play1) == tonumber(play2) or tonumber(play2) == tonumber(play3)) then
return draw,iCreditPlay
else
return draw,0
end
end

function DrawSimbol(number)
number = tonumber(number)
if (number == 100) then
return "BAR"
elseif (number == 25) then
return "  @  "
elseif (number == 5) then
return "   ?  "
elseif (number == 50) then
return "   7   "
elseif (number == 10) then
return "   $  "
elseif (number == 1) then
return "   &   "
else
local simbol,num
for simbol, num in arrResults do
if (tonumber(num) == number) then
return "   "..simbol.."   "
end
end
end
end

function Serialize(tTable, sTableName, sTab)
        assert(tTable, "tTable equals nil");
        assert(sTableName, "sTableName equals nil");

        assert(type(tTable) == "table", "tTable must be a table!");
        assert(type(sTableName) == "string", "sTableName must be a string!");

        sTab = sTab or "";
        sTmp = ""

        sTmp = sTmp..sTab..sTableName.." = {\n"

        for key, value in tTable do
                local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);

                if(type(value) == "table") then
                        sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
                else
                        local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
                        sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
                end

                sTmp = sTmp..",\n"
        end

        sTmp = sTmp..sTab.."}"
        return sTmp
end

function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
        handle:write(Serialize(table, tablename))
handle:flush()
        handle:close()
end
function LoadFromFile(file)
local handle = io.open(file,"r")
        if (handle ~= nil) then
                dofile(file)
handle:flush()
handle:close()
        end

end


Done,
enjoy :)
Title:
Post by: Anna on 20 May, 2005, 17:41:24
:) thanx

Looks like it works like a charm, tested it a bit and no probs for me :D
Title:
Post by: Dessamator on 20 May, 2005, 19:26:48
QuoteOriginally posted by Anna
:) thanx

Looks like it works like a charm, tested it a bit and no probs for me :D

ur welcome , :)