------------------------------------ -- kickbattle V2 -- now works by words instead of counting to make it a harder challange -- needs a data file with the words (1 word per line) -- saves the scores -- datafiles need a folder (default set to "public_kick") -- enjoy plop (http://www.plop.nl) ------------------------------------ ------ V2.1 -- boot anim can be disabled -- couple bug fixes (thx yepyepyep4711/plop) ------ V2.2 -- fixed error on random. -- added, hub check can nominate ball's again. ------ V2.3 -- fixed spelling error on the filename -- fixed forgot to change Save to SaveScores on the function Main ------ V2.4 -- fixed balls can't kick balls anymore, -- should solve the bug causing the script to freeze when they try. --- ------------------------------------ -- name of the bot Bot= "-KickBattle-" -- filename from the word with all the files fLangFile = "kickbattle[E].txt" -- the folder which kick battle uses for the datafiles fScoresFolder = "public_kick" -- amount of words used in the game per ball iAmount = 3 -- the punishment for cheating iPunish = 5 -- play with hubcheck. use 1 to enable, nil 2 disable. iHubCheck = 1 iMaxHubs = 50 -- make this anything but nil to promote my website. promo = nil -- show boot animation. use 1 to enable, nil 2 disable. Boot = nil ----------------------------------------------------------------- -- don't change things below this line if you know what your doing ----------------------------------------------------------------- -- filename for the scores file (don't change) fScoresFile = "kickbattle.lua" tGame = { tWords = {}, -- array with the words for during the game tVicCount = {},-- victems={table of words} tContesters = {}, -- gamers={table words 2 go) tOrder = {}, -- order of the balls tReason = {}, -- reasons for the balls tScores = {}, -- yep the scores from the players tBWords = {} -- the full array words for the game } fDataFile = fScoresFolder.."/"..fScoresFile function Main() frmHub:RegBot(Bot) readfrom(fScoresFolder.."/"..fLangFile) while 1 do local line = read() if line == nil then break end tinsert(tGame.tWords, line) tinsert(tGame.tBWords, line) end writeto() if readfrom(fDataFile) then dofile(fDataFile) readfrom() else execute("mkdir "..fScoresFolder) SaveScores() end end function ShowHelp(user) local line = "\r\n\r\n---------------------------------------------------------------\r\n" line = line.." Kick battle help menu\r\n" line = line.."---------------------------------------------------------------\r\n" if user.bOperator then line = line.." !ball \t- Nominates the given username as ball.\r\n" line = line.." !addwords \t- Adds the given words to the word file (multiple words per command posible).\r\n" line = line.." !delwords \t- Removes the given words to the word file (multiple words per command posible).\r\n" end line = line.." !kickbattle\t\t- Shows the top 10 players.\r\n" line = line.."---------------------------------------------------------------\r\n" line = line.." The basics of the game are really simple.\r\n" line = line.." The fastest user who types all the magic words scores and kicks the ball.\r\n" line = line.." But more then 1 word per line is considered cheating!!\r\n" line = line.." This gives a penalty of "..iPunish.." points getting subtracted from your score!\r\n" line = line.."---------------------------------------------------------------\r\n" if promo then line = line.." Check ¦ http://www.plop.nl ¦ for more scripts!" end return line end function ShowTop() local Tmp = {} local line local c,d = 0,0 for a,b in tGame.tScores do if Tmp[b] then Tmp[b]=(Tmp[b].." / "..a) else Tmp[b]=a end if b > c then c = b end end if c ~= 0 then for i=c,1, -1 do if line == nil then line = "\r\n\r\n---------------------------------------------------------------\r\n" line = line.." Kick battle top 10\r\n" line = line.."---------------------------------------------------------------\r\n" end if Tmp[i] then line = line.." "..i.." scored\t"..Tmp[i]..".\r\n" d = d + 1 if d == 10 then break end end end line = line.."---------------------------------------------------------------\r\n" else line = "no stats yet" end return line end function SaveWords() writeto(fScoresFolder.."/"..fLangFile) for i=1,getn(tGame.tBWords) do write(tGame.tBWords[i].."\n") end writeto() end function SaveScores() local t = nil writeto(fDataFile) write("tGame.tScores={") for a,b in tGame.tScores do if t == nil then write("\n["..format("%q", a).."]="..b) t = 1 else write(",\n["..format("%q", a).."]="..b) end end write("\n}") writeto() end function Scores(user) if tGame.tScores[user.sName] then tGame.tScores[user.sName] = tGame.tScores[user.sName] +1 else tGame.tScores[user.sName] = 1 end SaveScores() return tGame.tScores[user.sName] end function PunishScores(user) if tGame.tScores[user.sName] then tGame.tScores[user.sName] = tGame.tScores[user.sName] - iPunish else tGame.tScores[user.sName] = (0-iPunish) end SaveScores() return tGame.tScores[user.sName] end function ShowWords() local line = nil for a,b in tGame.tVicCount[tGame.tOrder[1]] do if line == nil then line = a else line = line.." / "..a end end return line end function RebuildWords() tGame.tWords = nil tGame.tWords = {} for i=1, getn(tGame.tBWords) do tinsert(tGame.tWords, tGame.tBWords[i]) end end function GetWords(vic) local Get = 0 local line = nil if getn(tGame.tWords) < iAmount then RebuildWords() end local tTmp = tGame.tWords tGame.tVicCount[vic] = {} for i=1,iAmount do iTmp = random(1,getn(tTmp)) Get = tTmp[iTmp] tGame.tVicCount[vic][Get] = 1 if line == nil then line = tTmp[iTmp] else line = line.." / "..tTmp[iTmp] end tremove(tTmp, iTmp) end return line end function DoAddWord(word) for i=1, getn(tGame.tBWords) do if tGame.tBWords[i] == word then return "\r\n"..word.." failed" end end tinsert(tGame.tBWords, word) return "\r\n"..word.." added" end function AddWords(words) words = gsub(words, "(%S+)", function(word) return DoAddWord(word) end) SaveWords() RebuildWords() return words end function DoDeleteWord(word) for i=1, getn(tGame.tBWords) do if tGame.tBWords[i] == word then tremove(tGame.tBWords, i) return "\r\n"..word.." removed" end end return "\r\n"..word.." failed" end function DeleteWords(words) words = gsub(words, "(%S+)", function(word) return DoDeleteWord(word) end) SaveWords() RebuildWords() return words end function CheckCheat(word) for a,b in tGame.tVicCount[(tGame.tOrder[1])] do if a == word then return word end end return "" end function DoGame(user, data) local s,e,word = strfind(data, "%b<>%s*(%S+)") if tGame.tContesters[user.sName] then if tGame.tContesters[user.sName][word] then local s,e,words = strfind(data, "%b<>%s+(.*)") words = gsub(words, "(%S+)", function(word) return CheckCheat(word) end) local words,count = gsub(words, "%S+", "" ) if count > 1 then SendToAll(Bot, user.sName.." tryed to cheat!! that costed him "..iPunish.." points!! his/her current score is: "..PunishScores(user).."|" ) else tGame.tContesters[user.sName][word]=nil tGame.tContesters[user.sName]["counter"]=tGame.tContesters[user.sName]["counter"] - 1 if tGame.tContesters[user.sName]["counter"] == 0 then if GetItemByName(tGame.tOrder[1]) then local vix = GetItemByName(tGame.tOrder[1]) local vic = vix.sName if Boot then DoBoot(vic) end SendToAll(Bot, user.sName.." has scored. His/Her's current score is: "..Scores(user).."|") vix:SendPM(Bot, "You has been kicked because: "..tGame.tReason[vic].."|") tGame.tReason[vic] = nil tGame.tContesters = nil tGame.tContesters = {} tGame.tVicCount[(vic)] = nil tremove(tGame.tOrder, 1) if tGame.tOrder == nil or getn(tGame.tOrder) ~= 0 then SendToAll(Bot, "New game started, the ball is: "..tGame.tOrder[1].." because: "..tGame.tReason[(tGame.tOrder[1])]..". the magic words are: "..ShowWords().."|") else SendToAll(Bot, "No more balls left. Game ended!|") tGame.iOnOff = nil end vix:Disconnect() end end end end else tGame.tContesters[user.sName] ={} for a,b in tGame.tVicCount[(tGame.tOrder[1])] do tGame.tContesters[user.sName][a]=b end tGame.tContesters[user.sName]["counter"]=iAmount if tGame.tContesters[user.sName][word] then local s,e,words = strfind(data, "%b<>%s+(.*)") words = gsub(words, "(%S+)", function(word) return CheckCheat(word) end) local words,count = gsub(words, "%S+", "" ) if count > 1 then SendToAll(Bot, user.sName.." tryed to cheat!! that costed him "..iPunish.." points!! his/her current score is: "..PunishScores(user).."|" ) else tGame.tContesters[user.sName][word]=nil tGame.tContesters[user.sName]["counter"]=tGame.tContesters[user.sName]["counter"] - 1 end end end end function Commands(user, data) local s,e,cmd=strfind(data, "^%b<>%s*(%S+)") if user.bOperator then if cmd == "!ball" then local s,e,vic,why=strfind(data, "%b<>%s+%S+%s*(%S*)%s*(.*)") if vic == "" then return "I need a ball name!" elseif why == "" then return "Sorry, need a reason!" elseif GetItemByName(vic) then if tGame.tVicCount[vic] == nil then local words = GetWords(vic) tinsert(tGame.tOrder, vic) if tGame.iOnOff == nil then SendToAll(Bot, vic.." has been named the ball by "..user.sName.." in kick soccer for the following reason: "..why.."|") SendToAll(Bot, "The magic words are: "..words.."|") end tGame.tReason[vic]=why if getn(tGame.tOrder) ~= 0 then tGame.iOnOff = 1 end else return vic.." is allready a ball!" end else return "Unknown user!" end elseif cmd == "!kickbattle" then return ShowTop() elseif cmd == "!addwords" then local s,e,words = strfind(data, "%b<>%s+%S+%s*(.*)") if words == "" then return "Yep i guessed which words you wanted to add!" else return AddWords(words) end elseif cmd == "!delwords" then local s,e,words = strfind(data, "%b<>%s+%S+%s*(.*)") if words == "" then return "Yep i guessed which words you wanted to remove!" else return DeleteWords(words) end elseif cmd =="!kickhelp" then return ShowHelp(user) elseif cmd == "!hubcheck" then if iHubCheck then iHubCheck = nil return "HubCheck disabled" else iHubCheck = 1 return "HubCheck enabled" end elseif tGame.iOnOff then if tGame.tVicCount[user.sName] then return "Users kick balls. balls get kicked. so lay still untill someone kicks you!!!" else DoGame(user, data) end end else if cmd == "!kickbattle" then return ShowTop() elseif cmd == "!kickhelp" then return ShowHelp(user) elseif tGame.iOnOff then if tGame.tVicCount[user.sName] then return "Users kick balls. balls get kicked. You are a ball. So lay still untill someone kicks you!!!" else DoGame(user, data) end end end end function DataArrival(user, data) if user.sMyInfoString and user.bOperator == nil and tGame.tVicCount[user.sName] == nil then s,e,thubs=strfind(user.sMyInfoString, "H:([%d%/]+)") if thubs ~= nil then hubs = 0 if tonumber(thubs) == nil then gsub(thubs, "(%d+)", function (num) hubs = hubs +tonumber(num) end) else hubs = tonumber(thubs) end if hubs >= iMaxHubs then local words = GetWords(user.sName) tinsert(tGame.tOrder, user.sName) if tGame.iOnOff == nil then local why = "To much hub's: "..hubs SendToAll(Bot, user.sName.." has been named the ball in kick soccer for the following reason: "..why.."|") SendToAll(Bot, "The magic words are: "..words.."|") end tGame.tReason[user.sName]=why if getn(tGame.tOrder) ~= 0 then tGame.iOnOff = 1 end end end end if( strsub(data, 1, 1) == "<" ) then data = strsub(data, 1, (strlen(data)-1)) local tmp = Commands(user, data) if tmp then user:SendData(Bot, tmp.."|") return 1 end elseif(strsub(data, 1, 4) == "$To:") then local s,e,whoTo = strfind(data,"$To:%s+(%S+)") if whoTo == Bot then data=strsub(data,1,strlen(data)-1) s,e,data = strfind(data, "%$(%b<>.*)$") local tmp = Commands(user, data) if tmp then user:SendPM(Bot, tmp.."|") return 1 end end end end function UserDisconnected(user) if tGame.tVicCount[user.sName] then tGame.tVicCount[user.sName] = nil for i=1,getn(tGame.tOrder) do if tGame.tOrder[i] == user.sName then tremove(tGame.tOrder, i) if getn(tGame.tOrder) == 0 then tGame.iOnOff = nil SendToAll(Bot, user.sName.." deflated! No balls left. Game ended!|") elseif i == 1 then SendToAll(Bot, user.sName.." deflated! But we have a new ball by the name of: "..tGame.tOrder[1]..". The magic words are: "..ShowWords().."|") end end end end end OpDisconnected = UserDisconnected function DoBoot(nick) local shoe={ [1] = " ____", [2] = " /=--=]", [3] = " .--.___(: }", [4] = "( ' __ )", [5] = "'----'''===='" } local t = "" for i=1,strlen(nick) do t=t.." " end for i=1,4 do shoe[i]=t..shoe[i] end shoe[5] = nick..shoe[5] for i=(strlen(nick)+2),1, -1 do local line = "\r\n" for j=1,5 do line = line..shoe[j].."\r\n" shoe[j]=strsub(shoe[j], 2, strlen(shoe[j])) end SendToAll(Bot, line.."|") end end function NewUserConnected(user) if iHubCheck and tGame.tVicCount[user.sName] == nil then s,e,thubs=strfind(user.sMyInfoString, "H:([%d%/]+)") if thubs ~= nil then hubs = 0 if tonumber(thubs) == nil then gsub(thubs, "(%d+)", function (num) hubs = hubs +tonumber(num) end) else hubs = tonumber(thubs) end if hubs >= iMaxHubs then local words = GetWords(user.sName) tinsert(tGame.tOrder, user.sName) local why = "To much hub's: "..hubs if tGame.iOnOff == nil then SendToAll(Bot, user.sName.." has been named the ball in kick soccer for the following reason: "..why.."|") SendToAll(Bot, "The magic words are: "..words.."|") end tGame.tReason[user.sName]=why if getn(tGame.tOrder) ~= 0 then tGame.iOnOff = 1 end end end end end