Author Topic: StabBot 1.1 lua5  (Read 2149 times)

0 Members and 1 Guest are viewing this topic.

Offline Manon

  • Newbie
  • *
  • Posts: 6
  • Karma: +2/-0
StabBot 1.1 lua5
« on: 15 March, 2008, 19:58:01 »
this is a very cool script  ;D

http://www.thedestruction.org/lua/Lua5/StabBot1.1%20Lua5.rar

Code: [Select]
--/////////////////////////////////////////////////////////////////////////////////////////////--
--// StabBot 1.1 for ptokax td4 by ?ottledHat?.
--// i started this becasue a friend wanted a stab bot like the vb one for in his hub running yhub.. which has no scripting.
--// This originally this first script made in lua5 for bcdc client side... COMPLETLY re-done for my first ptokax td script in lua 4.
--// Converted to lua 5 for PtokaX by Madman, with NightLitch Converter
--// Thanks NightLitch for fixing the filehandling
--/////////////////////////////////////////////////////////////////////////////////////////////--
-------------------EDIT THIS JUNK BELOW-----------------------------------------------------------
sFileName = "data/StabBot/StabTable.dat" --//save file for data. path can be relative to script dir: "data/StabTable.dat"  or math.absolute: "c:\\path\\to\\file.bleh"
FloodTime = 5 --//(default)(seconds). limits users to 1 stab every x seconds. 0 = off
StatsInMain = 0 --// the bots default setting with no stats. 1 = on 0 = off (it looks the same either way.. but, only you see it if it is set to off..0)
PreFixs = {["!"] = 1, ["+"]=1, ["?"]=1,["*"]=1,["#"]=1,["^"]=1,["?"]=1,["?"]=1,["~"]=1} --//the allowed prefixes used before the Cmds..(i hate only being able to use 1)
Cmd1 = "stabs" --/the cmd to invoke the stab.
Cmd2 = "deaths" --//the cmd to invoke the total count.
Cmd3 = "stabhappy" --//the cmd to invoke the total usage.(how many times each user has used the command)
Cmd4 = "mystabs" --//the cmd to invoke personal stats. (who you have stabbed and how many times)
Cmd5 = "tgglBot" --//(ops or better only)turn the the bot on or off.
Cmd6 = "tgglMain"  --//(ops or better only)turn the main chat stats on or off.
Cmd7 = "shelp" --// tells users what te commands are... + ops what Cmd5, Cmd6, Cmd8, & Cmd9 are...
Cmd8 = "clrstabs" --//ops may clear any. users only their own. (personal usage data only.. not death count or total usage)
Cmd9 = "setflood" --//(ops or better only)the time in seconds. limits users to 1 stab every x seconds.
-------------------DON'T MESS AORUND BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING!----------------
--/////////////////////////////////////////////////////////////////////////////////////////////--
-------------------------
local f,e = io.open( sFileName, "a+" ) --//Error handle.. makes sure save file and dir exist...
if f then
f:write("")
f:close()
else --//and if it doesn't.. make the path, then the file.
local _,_,path = string.find(sFileName, "(.+[/_\\]).+$")
if path ~= nil then
os.execute("mkdir ".."\""..string.gsub(path, "/", "\\").."\"")
end
f,e = io.open( sFileName, "a+" )
if f then
f:write("" )
f:close() --// file and path did not exist.. now they do.
else
sFileName = "_stabtable.dat"--//this is only if the path provided is invalid to winblows. defaults to a file in the scripts dir.
end
end

-------------------------
sTable={["Settings"]={["Status"]=1,["StatsInMain"]=StatsInMain, ["FldScnds"] = FloodTime},["gTotal"]=0,["tUse"]={},["uUse"]={}}
cmdS={[Cmd1]=1,[Cmd2]=1,[Cmd3]=1,[Cmd4]=1, [Cmd5]=1,[Cmd6]=1,[Cmd7]=1,[Cmd8]=1,[Cmd9]=1}
oUsers = {}
require(sFileName)
require("_StabAnswers.txt")
-------------------------
function NewUserConnected(user)--//used for the randmNames function, and flood control.
oUsers[user.sName] = 1
end
function UserDisconnected(user)
oUsers[user.sName] = nil
end
OpDisconnected = UserDisconnected
OpConnected = NewUserConnected
-------------------------
function ChatArrival(user, data)
if string.sub(data, 1, 1) == "<" then
local _,_,cmd=string.find(data, "%b<>%s+(%S+).+") 
if not PreFixs[string.sub( cmd, 1, 1)] then return end --//(trying to speed things up.. dunno if it helps)
cmd = string.sub(cmd,2)
if not cmdS[cmd] then return end --//(trying to speed things up.. dunno if it helps)
local userN = user.sName
local _,_,junk=string.find(data, "%b<>%s+%S+%s+(.+)|")
local requestString = ""
if cmd == Cmd1 then --// list for the cmd to invoke the stab.
if sTable["Settings"]["Status"] == 0 then return end--//bot on?
if not oUsers[userN] then oUsers[userN] = 1 end--//case we missed their math.log-in.
if os.clock() - oUsers[userN] <= sTable["Settings"]["FldScnds"] then return 1 end--//flood protection.
local answer,victim, rand = answer1[math.random(table.getn(answer1))], junk or randmName(), randmName()
if string.find(victim, "%%") then victim = randmName() end--//the '%' sign fucks stuff up....
answer = string.gsub( answer, "(%[stbr%])", userN )--swap the vars in the answer..
answer = string.gsub( answer, "(%[stbd%])", victim )
answer = string.gsub( answer, "(%[rnduser%])", rand )
SendToAll( answer.."|" )
sTable["gTotal"] = sTable["gTotal"] +1
if sTable["tUse"][userN] then
sTable["tUse"][userN] = sTable["tUse"][userN] + 1
else
sTable["tUse"][userN] = 1
end
if sTable["uUse"][userN] then
if sTable["uUse"][userN][victim] then
sTable["uUse"][userN][victim] = sTable["uUse"][userN][victim] + 1
else
sTable["uUse"][userN][victim] = 1
end
else
sTable["uUse"][userN] = {}
sTable["uUse"][userN][victim] = 1
end
saveData() --//Save all data
oUsers[userN] = os.clock()
return 1
-------------------------
elseif cmd == Cmd2 then --//listen for the cmd to invoke the total count.
if sTable["Settings"]["Status"] == 0 then return end--//bot on?
if sTable["Settings"]["StatsInMain"] == 1 then
SendToAll(" *** The death count is: "..sTable["gTotal"]..". ***|" )
else
user:SendData(" *** The death count is: "..sTable["gTotal"]..". ***|" )
return 1
end
-------------------------
elseif cmd == Cmd3 then --//listen for the cmd to invoke the total usage.
if sTable["Settings"]["Status"] == 0 then return end--//bot on?
counting = 0
for key,value in sTable["tUse"] do
counting = counting +1
if counting < 5 then
requestString = requestString..key.." = "..value.." "
else
requestString = requestString..key.." = "..value.."\r\n"
counting = 0
end
end
if sTable["Settings"]["StatsInMain"] == 1 then
SendToAll(" \r\n*** Stab Usage for the hub... (how many times each person used the command)***"..
"\r\n_________________________________________________________________________\r\n"..requestString..
"\r\n_________________________________________________________________________|" ) --//send pm to yhub bot via raw message dispay the stab count
else
user:SendData(" \r\n*** Stab Usage for the hub... (how many times each person used the command)***"..
"\r\n_________________________________________________________________________\r\n"..requestString..
"\r\n_________________________________________________________________________|" )
return 1
end
-------------------------
elseif cmd == Cmd4  then --//listen for the cmd to invoke personal stats.
if sTable["Settings"]["Status"] == 0 then return end--//bot on?
local who = junk or userN
if sTable["uUse"][who] then
counting = 0
for key,value in sTable["uUse"][who] do
counting = counting +1
if counting < 5 then
requestString = requestString..key.." = "..value.." "
else
requestString = requestString..key.." = "..value.."\r\n"
counting = 0
end
end
if sTable["Settings"]["StatsInMain"] == 1 then
SendToAll(" \r\n***Personal Stab Usage for "..who.."... (how many times you stabbed that person)***"..
"\r\n_________________________________________________________________________\r\n"..requestString..
"\r\n_________________________________________________________________________|" )
else
user:SendData(" \r\n***Personal Stab Usage for "..who.."... (how many times you stabbed that person)***"..
"\r\n_________________________________________________________________________\r\n"..requestString..
"\r\n_________________________________________________________________________|" )
return 1
end
else
if sTable["Settings"]["StatsInMain"] == 1 then
SendToAll("No data for "..who..".|")
else
user:SendData("No data for "..who..".|")
return 1
end
end
-------------------------
elseif cmd == Cmd5 then--//Listen for Bot On/Off cmd
if user.iProfile >=1 then return end--//ops only
if sTable["Settings"]["Status"] == 1 then
sTable["Settings"]["Status"] = 0
user:SendData("Bot Turned OFF|")
else
sTable["Settings"]["Status"] = 1
user:SendData("Bot Turned ON|")
end
saveData() --//Save all data
return 1
-------------------------
elseif cmd == Cmd6 then--//listen for the main chat stats on or off.
if user.iProfile >=1 then return end--//ops only
if sTable["Settings"]["StatsInMain"] == 1 then
user:SendData("Stats In Main Turned OFF|")
sTable["Settings"]["StatsInMain"] = 0
else
user:SendData("Stats In Main Turned ON|")
sTable["Settings"]["StatsInMain"] = 1
end
saveData() --//Save all data
return 1
-------------------------
elseif cmd == Cmd7 then--//listen for help cmd
local prfxs =""
for k,v in PreFixs do prfxs = prfxs..k.."  " end
user:SendData("\r\nHelp for StabBot:\r\n\t"..
"Availible prefixes for commands:  "..prfxs.."\r\n\t"..
"User Commands:\r\n\t\t"..
Cmd1.." [nick]\tStabs nick or random user if not provided.\r\n\t\t"..
Cmd2.."\t\tShows the total count of how many times "..Cmd1.." has been used.\r\n\t\t"..
Cmd3.."\tShows how many times each user has used "..Cmd1..".\r\n\t\t"..
Cmd4.."\tShows who you have used "..Cmd1.." on, and how many times.\r\n\t\t"..
Cmd8.."\t\tClears your personal usage data.\r\n|")
if user.iProfile <= 1 then
user:SendData("\r\nAdmin Help for StabBot:\r\n\t"..
"Op Commands:\r\n\t\t"..
Cmd5.."\t\tTurns StabBot ON or OFF\r\n\t\t"..
Cmd6.."\tTurns Spaming of "..Cmd3.." and "..Cmd4.." in the main chat on or off.\r\n\t\t"..
Cmd9.." <#>\tSets the flood time. # = seconds. Limits users to 1 stab every # seconds. 0 = off.\r\n\t\t"..
Cmd8.." <nick>\tClears the personal usage data for user.\r\n|")
end
-------------------------
elseif cmd == Cmd8 then --//listen for clear stats cmd
local who = junk or userN
if user.iProfile >=2 then who = user.sName end
if not sTable["uUse"][who] then
user:SendData("There is no data for "..who..".|")
else
sTable["uUse"][who] = nil
user:SendData("Personal data for "..who.." has been cleared.|")
saveData() --//Save all data
end
return 1
elseif cmd == Cmd9 then --// listen for flood time cmd
if user.iProfile >=1 then return end--//ops only
_,_,junk=string.find(data, "%b<>%s+%S+%s+(%d+)|")
if junk == nil then
user:SendData("Error. Syntax: !"..Cmd8.." <#> # = seconds. Limits users to 1 stab every # seconds. 0 = off|")
else
sTable["Settings"]["FldScnds"] = tonumber(junk)
user:SendData("Flood time set to "..junk.." seconds.|")
saveData() --//Save all data
end
return 1
end
end
end
-------------------------
function randmName()
local n = 0
for k,v in oUsers do n=n+1 end
n = math.random( n )
for k,v in oUsers do
if n == 1 then
return k
end
n = n - 1
end
end
function saveData()
local data = Serialize(sTable, "sTable", "")
local f,e = io.open( sFileName, "w+" )
if f then
f.write(f, data )
io.close(f)
end
end
function Serialize(tTable, sTableName, sTab)
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.."={"
local tStart = 0
for key, value in tTable do
if tStart == 1 then
sTmp = sTmp..",\r\n"
else
sTmp = sTmp.."\r\n"
tStart = 1
end
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
end
sTmp = sTmp.."\r\n"..sTab.."}"
return sTmp
end
-------------------------
--//StabBot by ?ottledHat?. Tested in ptokax td4.
« Last Edit: 05 April, 2008, 22:18:37 by Manon »

PtokaX forum

StabBot 1.1 lua5
« on: 15 March, 2008, 19:58:01 »

Offline XTC

  • Junior Member
  • **
  • Posts: 15
  • Karma: +1/-0
Re: StabBot 1.1 lua5
« Reply #1 on: 09 August, 2008, 00:00:58 »
Where do I put this file ???

Offline Madman

  • Scripter
  • Emperor
  • ******
  • Posts: 1 316
  • Karma: +75/-1
Re: StabBot 1.1 lua5
« Reply #2 on: 18 August, 2008, 20:42:14 »
Done. Can befound on my site under API 2 > Singel Scripts

XTC, unrar it. Put the lua and txt file directly in the scripts dir.

How ever the version Manon linked to is for older PX, to use it with 0.4.1.1 go to my site.
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

PtokaX forum

Re: StabBot 1.1 lua5
« Reply #2 on: 18 August, 2008, 20:42:14 »