PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: GaMeFaNaTiC on 25 October, 2003, 12:15:50

Title: need a bit of help on this script... plz help
Post by: GaMeFaNaTiC on 25 October, 2003, 12:15:50
--FreshStuff v.2.3
--You need a folder called "txt" in your Ptokax scripts folder, like this /scripts/txt/
--Only OPs can ADD and DEL added by shipis

--Name this bot to anything you like
bot = "[gG?]Network"

--Name the commands to what U like
--This command adds stuff, syntax : +adds THESTUFF
cmd1 = "+addsingle"

--This command shows the stuff, syntax : +shows THESTUFF
cmd2 = "+singles"

--This command deletes an entry, syntax : +dels THESTUFFNUMBER
cmd3 = "+delsingle"

--This command shows the Top Poster, syntax : +topp
cmd4 = "+topsingleposter"

--Set This to anything else than nil and the 5 newest items will be shown at userconnect
SendOnConnect = nil

--Set this number to the Maximum of shown items
Max1 = 100

--Set this number to the Maximum of shown items on connect
Max2 = 5

--Set this number to the Maximum of stored table entries
MaxT = 100

--Set this number to the Maximum of shown Posters
Max3 = 10
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------

File1 = "singles.txt"
File2 = "singlesPosters.txt"

newstuff={}
posters={}

curtime = date("[%d-%m-%Y]")

function Main()
ReadStuff1(File1, newstuff)
topItems1 = ReadTable(newstuff, Max1)
topItems2 = ReadTable(newstuff, Max2)
ReadPosters()
topposters = ShowPosters(posters, Max3)
end

function NewUserConnected(curUser)
if SendOnConnect then
OpenFile(curUser, File1)
end
end

function OpConnected(curUser)
if SendOnConnect then
OpenFile(curUser, File1)
end
end

function DataArrival(curUser,data)

if (strsub(data, 1, 1) == "<") then
data = strsub(data,1,strlen(data)-1)

if (strfind(strlower(data), strlower(cmd1))) and curUser.bOperator then
s,e,cmd,item = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
if ( item == nil or item == "" ) then
curUser:SendPM(bot, " If you want to add an item type "..cmd1.." YOURITEM in main chat :)")
return 1
elseif ( strlen(item) < 100 and strlen(item) > 5) then
item = gsub(item, "(%w+)", "%1 ");
for i,v in newstuff do
s,e,name,curitem = strfind( v, "-%s+%b[]%s+(%S+)%s+added%s+<::%s+(.*)" )
if curitem == nil then
else
curitem = strsub(curitem,1,strlen(curitem)-4)
if strlower(curitem) == strlower(item) then
curUser:SendPM(bot, " Sorry your item <:: "..curitem.." ::> has already been added.\r\n"..
" "..v)
return 1
end
end
end
ReadPosters()
if posters[curUser.sName]==nil then
posters[curUser.sName]=1
WritePosters()
topposters = ShowPosters(posters, Max3)
else
posters[curUser.sName]=posters[curUser.sName]+1
WritePosters()
topposters = ShowPosters(posters, Max3)
end
curstuff = " [gG?] " ..item.. " "
tinsert ( newstuff, 1, curstuff)
WriteStuff1(File1, newstuff)
newstuff = {}
ReadStuff1(File1, newstuff)
topItems1 = ReadTable(newstuff, Max1)
topItems2 = ReadTable(newstuff, Max2)
SendToAll(newstuff[1])
return 1

else
curUser:SendPM(bot, " If you want to add an item type "..cmd1.." YOURITEM (at least 5 characters) in main chat :)")
return 1
end
end

if (strfind(strlower(data), strlower(cmd2))) then
curUser:SendPM(bot, "\r\n".."Latest Singles \r\n"..
topItems1.."\r\n"..
"Latest Singles ")
return 1
end

if (strfind(strlower(data), strlower(cmd3))) and curUser.bOperator then
if curUser.bOperator then
s,e,cmd,num = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
num2=tonumber (num)
if ( num2 == nil ) then
curUser:SendPM(bot, " To delete an item type "..cmd3.." ITEMNUMBER in main chat :)")
return 1
else
if newstuff[num2]~=nil then
tremove (newstuff, num2)
WriteStuff1(File1, newstuff)
newstuff = {}
ReadStuff1(File1, newstuff)
topItems1 = ReadTable(newstuff, Max1)
topItems2 = ReadTable(newstuff, Max2)
curUser:SendPM(bot, " Item Nr. "..num2.." was deleted.")
return 1
else
curUser:SendPM(bot, " Item Nr. "..num2.." is not in list.")
return 1
end
end
end
end

if (strfind(strlower(data), strlower(cmd4))) then
curUser:SendPM(bot, "\r\n"..
" -= Top "..Max3.." Releasers =-\r\n"..
topposters)
return 1
end
end
end
----------------------------------------------------------------------
function ReadStuff1(File, table)
local handle = openfile("txt/"..File1, "r")
if (handle) then
local line = read(handle)
while line do
s,e,ind,val = strfind( line, "(%S+)%s+(.*)")
ind = tonumber (ind)
table[ind]=val
line = read(handle)
end
closefile(handle)
end
end
----------------------------------------------------------------------
function WriteStuff1(File, table)
local handle = openfile("txt/"..File1, "w")
for i = 1, MaxT do
if table[i] then
write(handle,i.." "..table[i].."\r\n")
end
end
closefile(handle)
end
----------------------------------------------------------------------
function ReadTable(table, Max)
var1 = 0
local msgfromtxt ="\r\n"
for index, value in table do
var1 = var1 + 1
msgfromtxt = msgfromtxt.." "..index.." "..value.."\r\n"
if var1 == Max then
break
end
end
return msgfromtxt
end
----------------------------------------------------------------------
function ShowPosters(table, Max)
var2 = 0
var3 = 0
local msgfromtxt ="\r\n"
while var2 < Max do
var2 = var2 +1
var4 = 0
for index, value in table do
value = tonumber (value)
if value >= var4 then
var4 = value
userm = index
end
end
table[userm]=0
var3 = var3 +1
msgfromtxt = msgfromtxt.." "..var3.." - "..userm.." posted "..var4.." Items.\r\n"
end
return msgfromtxt
end
----------------------------------------------------------------------
function ReadPosters()
local handle = openfile("txt/"..File2, "r")
if (handle) then
local line = read(handle)
while line do
s,e,ind,val = strfind( line, "(%S+)%s+(.*)")
posters[ind]=val
line = read(handle)
end
closefile(handle)
end
end
----------------------------------------------------------------------
function WritePosters()
local handle = openfile("txt/"..File2, "w")
for index, value in posters do
write(handle,index.." "..value.."\r\n")
end
closefile(handle)
end


ok the only problem with this is, when i add something say for example, +addsingle DMX - BLA BLA, it double spaces it to make DMX  -  BLA  BLA. i only want a single space :S. and the other thing is, when i add another thing to +singles i want it to go at the bottom but the new ones go at the top :S. can somebody help on how i can fix this?? thnks
Title:
Post by: raz on 25 October, 2003, 16:04:20
what do u mean it double spaces it. could u show us. :D
Title:
Post by: GaMeFaNaTiC on 25 October, 2003, 17:34:20
lol 2 spaces init between the words like "ME--ME" :]

- = space