PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Devastator on 01 February, 2004, 21:44:15

Title: Help With This Script
Post by: Devastator on 01 February, 2004, 21:44:15
Plz sum1 help me with this i want it so u can delete entries theres a .dat file with it........but can u do this so u can delete entries i knw theres Fresh Stuff around but i am already using that for something else and i wanna use this! but all i need is a +del 2 delete entries without having 2 go in 2 the .dat file and changin it which is hard if u r not hosting!



botname = "BotName"

function Main()
frmHub:RegBot(botname)
end


function DataArrival(user, data)

-- PM cmds:

if(strsub(data, 1, 4) == "$To:") then
data=strsub(data,1,strlen(data)-1)
s,e,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == botname) then
s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")
if user.bOperator then
if (cmd=="addhiphop") then

-- arg from PM
arg= GetArgsPM(data)

-- Check if arg from PM is not 'nil' (empty)

if arg ~= nil then
local handle=openfile("hiphop.dat","a")
write(handle,""..date("<%d.%m.%Y> ")..arg.."     <"..user.sName..">?")
user:SendPM(botname,"Saved ....")
user:SendData(botname, "New entry in Hip Hop!")
closefile(handle)
else
user:SendData(botname, "Wrong synthax: addhiphop ")
end
end
end

if (cmd=="+hiphop") then
handle2=openfile("hiphop.dat","r")
if (handle2==nil) then
else
line = read(handle2,"*a")
line=strsub(line,1,strlen(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(botname,linearray[i])
end
closefile(handle2)
end
end
end
end

-- Main Chat cmds:

if (strsub(data, 1, 1) == "<") then
data = strsub(data,1,strlen(data)-1)
s,e,cmd,dataa = strfind( data, "%b<>%s+(%S+)%s+(%S+)" )

if user.bOperator then
if (strfind(strlower(data), strlower("addhiphop"))) then

-- arg from main
arg= GetArgsML(data)

-- Check if arg from main is not 'nil' (empty)

if arg ~= nil then
local handle=openfile("hiphop.dat","a")
write(handle,""..date("<%d.%m.%Y> ")..arg.."     <"..user.sName..">?")
user:SendPM(botname,"Saved ....")
user:SendData(botname, "New entry in Hip Hop!")
closefile(handle)
else
user:SendData(botname, "Wrong synthax: addhiphop ")
end
end
end

if (strfind(strlower(data), strlower("+hiphop"))) then
handle2=openfile("hiphop.dat","r")
if (handle2==nil) then
else
line = read(handle2,"*a")
line=strsub(line,1,strlen(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(botname,linearray[i])
end
closefile(handle2)
end
end
end
end

function tokenize (inString,token)
_WORDS = {}
local matcher = "([^?"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end

-- Get Args from PM:
function GetArgsPM(data)
s,e,whoTo,from,cmd,arg = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(.*)")
return arg
end

-- Get Args from the Main Chat:
function GetArgsML(data)
s,e,cmd,arg = strfind(data, "%b<>%s+(%S+)%s+(.*)")
return arg
end



Plz Help Me!!!

Thanx A LoT ppl

Devastator
Title:
Post by: plop on 02 February, 2004, 01:24:54
you can run 2 instances of freshstuff if you rename the commands in 1 of them.

plop