PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: raz on 21 October, 2003, 14:02:38

Title: could you help me with dis plz
Post by: raz on 21 October, 2003, 14:02:38
could you plz change +addalbums so only ops can do i have added "if curUser.bOperator then" and changed afew thingz around but it comes out to be dat +deletealbum doesn't work. this is the original script, plz can u change it so ops can do +addalbums. can u check it b4 u give it back to see if it wokrs. i know that there are updated scripts but all i need is dis. thanks.

--FreshStuff v.2.3
--You need a folder called "txt" in your Ptokax scripts folder, like this /scripts/txt/

--Name this bot to anything you like
bot = "-= Albums =-"

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

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

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

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

--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 = "albums.txt"
File2 = "albumPosters.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))) then
s,e,cmd,item = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
if ( item == nil or item == "" ) then
curUser:SendData(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:SendData(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 = "- "..curtime.." "..curUser.sName.." added <:: "..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:SendData(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:SendData(bot, "\r\n"..
" ??*?'?*????*?'?*?? The "..Max1.." Newest Items ??*?'?*????*?'?*?? \r\n"..
topItems1.."\r\n"..
" ??*?'?*????*?'?*?? The "..Max1.." Newest Items ??*?'?*????*?'?*?? ")
return 1
end

if (strfind(strlower(data), strlower(cmd3))) then
if curUser.bOperator then
s,e,cmd,num = strfind( data, "%b<>%s+(%S+)%s+(.*)" )
num2=tonumber (num)
if ( num2 == nil ) then
curUser:SendData(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:SendData(bot, " Item Nr. "..num2.." was deleted.")
return 1
else
curUser:SendData(bot, " Item Nr. "..num2.." is not in list.")
return 1
end
end
end
end

if (strfind(strlower(data), strlower(cmd4))) then
curUser:SendData(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 then
write(handle,i.." "..table.."\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
Title:
Post by: servaks on 21 October, 2003, 14:15:43
In original scr i got error:
Syntax Error: table index is nil

/shipis
Title:
Post by: servaks on 21 October, 2003, 17:44:55
Here you go...


--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 = "-= Albums =-"

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

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

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

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

--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 = "albums.txt"
File2 = "albumPosters.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:SendData(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:SendData(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 = "- "..curtime.." "..curUser.sName.." added <:: "..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:SendData(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:SendData(bot, "\r\n"..
" ??*?'?*????*?'?*?? The "..Max1.." Newest Items ??*?'?*????*?'?*?? \r\n"..
topItems1.."\r\n"..
" ??*?'?*????*?'?*?? The "..Max1.." Newest Items ??*?'?*????*?'?*?? ")
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:SendData(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:SendData(bot, " Item Nr. "..num2.." was deleted.")
return 1
else
curUser:SendData(bot, " Item Nr. "..num2.." is not in list.")
return 1
end
end
end
end

if (strfind(strlower(data), strlower(cmd4))) then
curUser:SendData(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


/shipis
Title:
Post by: servaks on 21 October, 2003, 17:55:05
This one works fine (just tested)...

/shipis
Title:
Post by: Alexei on 21 October, 2003, 18:00:30
how da hell do you post this as a code??? like a pic or smth.... you know what i mean... ?(
Title:
Post by: raz on 21 October, 2003, 18:03:27
thanks servak really need that.
Title:
Post by: servaks on 21 October, 2003, 18:08:19
alexei: Press the "#" button...

raz: Its my job here, to help people...

/shipis
Title:
Post by: raz on 21 October, 2003, 18:42:49
sorry but i forgot 2 mention can u change it so it goes in pm instead of main. thanks
Title:
Post by: servaks on 21 October, 2003, 18:51:22
wow
im too lame to do it..
i liek mainchat..
thats why i dont know how to do it..

/shipis
Title:
Post by: raz on 21 October, 2003, 19:01:26
can u get some1 else 2 do it. thanks
Title:
Post by: raz on 22 October, 2003, 21:58:53
so can u make the script, when some1 does +albums it comes in pm not in main.
Title:
Post by: raz on 22 October, 2003, 22:40:12
so is there any1 out there who could change it so it goes in pm not on main.safe. :D
Title:
Post by: NightLitch on 22 October, 2003, 22:57:37
Well you could learn it your self -raz-

just change:

curUser:SendData

to

curUser:SendPM

and add

frmHub:RegBot(bot)

under

function Main()

/NightLitch
Title:
Post by: raz on 23 October, 2003, 18:25:08
thanks nightlitch i have been waiting for  a bit for some1 2 tell me how 2 do it. i knew about send pm but i didn't know u have 2 register the bot 2 make it works.thanks again. :D
Title:
Post by: raz on 23 October, 2003, 18:26:53
i am learning just joined a little while ago, so i don't know much and i didn't hardly come on the old forum. 8)