-- 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) -- usual mods by yepyepyep4711 (Botspeed, share, desc, mail, typos ;p, and TempBan instead of disconnect. Ah yes outcommented the boot as well, uncomment it to see the animation) gb = 1024 * 1024 * 1024 -- name, mail, speed, description and share of the bot Bot= "-KickBattle-" bot_email = "KickBattle@koeln.de" bot_speed = "4711 kbs" bot_descr = "!kickhelp für die hilfe" bot_share_size = 47.11 * gb -- filename from the file with all the words (file has to be in the ScoresFolder - see below) 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 -- make this anything but nil to promote my website. promo = yes ----------------------------------------------------------------- -- 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 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 } fDataFile = fScoresFolder.."/"..fScoresFile function Main() frmHub:RegBot(Bot) my_info_string = "$MyINFO $ALL "..Bot.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"..bot_email.."$"..bot_share_size.."$" readfrom(fScoresFolder.."/"..fLangFile) while 1 do local line = read() if line == nil then break end tinsert(tGame.tWords, line) end writeto() if readfrom(fDataFile) then dofile(fDataFile) readfrom() else execute("mkdir "..fScoresFolder) Save() end end function ShowHelp(user) local line = "\r\n\r\n---------------------------------------------------------------\r\n" line = line.." KickBattle 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.." KickBattle top 10\r\n" line = line.."---------------------------------------------------------------\r\n" end if Tmp[i] then line = line.." "..i.." goal(s)\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(tScoresFolder.."/"..fLangFile) for i=1,getn(tGame.tWords) do write(tGame.tWords[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 GetWords(vic) local Get = 0 local line = nil 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.tWords) do if tGame.tWords[i] == word then return "\r\n"..word.." failed" end end tinsert(tGame.tWords, word) return "\r\n"..word.." added" end function AddWords(words) words = gsub(words, "(%S+)", function(word) return DoAddWord(word) end) SaveWords() return words end function DoDeleteWord(word) for i=1, getn(tGame.tWords) do if tGame.tWords[i] == word then tremove(tGame.tWords, 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() 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.." tried to cheat!! That cost him/her "..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 --DoBoot(vic) --uncomment to see the boot animation SendToAll(Bot, "G O A L ! ! ! "..user.sName.." has kicked "..vic.." and scored! His/Her current score is: "..Scores(user).."|") vix:SendPM(Bot, "You have been kicked because: "..tGame.tReason[vic].."|") tGame.tReason[vic] = nil tGame.tContesters = nil tGame.tContesters = {} tGame.tVicCount[(vic)] = nil tremove(tGame.tOrder, 1) if getn(tGame.tOrder) ~= 0 then SendToAll(Bot, "New game started, the ball is: "..tGame.tOrder[1].." the magic words are: "..ShowWords().."|") else SendToAll(Bot, "No balls left. Game ended! See you next game :-).|") tGame.iOnOff = nil end vix:TempBan() 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.." tried to cheat!! That cost him/her "..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 tagged 'the ball' by "..user.sName.." in KickBattle for the following reason: "..why.."|") SendToAll(Bot, "The magic words are: "..words.."|") else return vic.." has been tagged 'the ball' by "..user.sName.." in KickBattle for the following reason: "..why.."|" end tGame.tReason[vic]=why if getn(tGame.tOrder) ~= 0 then tGame.iOnOff = 1 end else return vic.." is already 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 tGame.iOnOff then DoGame(user, data) end else if cmd == "!kickbattle" then return ShowTop() elseif cmd == "!kickhelp" then return ShowHelp(user) elseif tGame.iOnOff then DoGame(user, data) end end end function DataArrival(user, data) 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 NewUserConnected(user) user:SendData( my_info_string ) end OpConnected = NewUserConnected 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