hi, i'm Massimo, :D
i'd like to know how can i compare 2 strings and find a substring in a string.
when i used the verion 15.09 of ptokax i used this commands
(strsub(strlower(data),1,3)==strlower("$SR"))
and
_,_,fileString = strfind(data,"$SR%s+%S+%s+(.+).*")
but don't work in this ptokax's version. ;(
How can i do it? ?(
tnx 4 attention answer me if u can bye :D
ptokax report this error..
[14:32] Syntax ...o procazzo\scripts\Segnala i file proibiti_v1.1z.lua:224: attempt to call global `strsub' (a nil value)
QuoteOriginally posted by boomalek
hi, i'm Massimo, :D
i'd like to know how can i compare 2 strings and find a substring in a string.
when i used the verion 15.09 of ptokax i used this commands
(strsub(strlower(data),1,3)==strlower("$SR"))
and
_,_,fileString = strfind(data,"$SR%s+%S+%s+(.+).*")
but don't work in this ptokax's version. ;(
How can i do it? ?(
tnx 4 attention answer me if u can bye :D
Try replacing every "str" to "string.". Something like:
strsub -> string.sub;
strlower -> string.lower;
strfind -> string.find
Btw, put all that on a new function called SRArrival as the Lua 4 DataArrival has been splitted (check the file "Scripting-Interface.txt" shipped with the new PtokaX).
Cheers
Thanks very much Jiten.....
now it work correctly...
very truly yours ;)
Hi i have another questionn...
i know to read from a file txt with dofile("filename"),
but how can i write someting modify in them?
So i have a file txt that remember maxuser and maxshare i did this with the older version of ptokax
function saveNumber(file, number)
writeto(file)
write(number)
writeto()
end
can someone help me?
tnx bye
u really should take a look at the lua 5 howto section :
but i guess it would be something like this :
function SaveNumber(file,number)
io.output(file)
io.write(number)
io.close()
io.output()
end
or maybe like this :
function SaveNumber(file,number)
io.read(file,"a+")
io.write(number)
io.close()
end
Good Luck !
Hi.. I know the question isn't new.. And of course yes.. I will read the Lua 5 tutorial. But the next few weeks I do not have enough time..
Do I have to change nearly all in the scripts in LUA 4 to use them in the new ptokax.. or do I have to change only some vars. and prefixes?
No script is working in the new version.. because of LUA 5.. but the strange thing is, that also the scripts without syntax errors do not work..
It seams that they are not started.. but they are regged in the hub.. but no cmd start the e.g. Massmessanger..
or is it possible to use a script or a bot to enable LUA 4 in teh new version of ptokax??
Thx in advance..
bye Jacky
It really does depend on the complexity of the script, some scripts might work without any changes, while others might require quite a lot of work .
Indead...
Some of them are starting and are listed in the userlist.. As I said... They don't have any syntax errors.. but they do nothing.. for exampel....
-- SlotsBot for PtokaX DC Hub 0.3.2.6 Test Drive 4
-- On command +slots, sends a search and checks the results for free slots & total number of slots
-- Sends the results in PM from Hub bot
-- Adaptation by OpiumVolage (01 July 2003) based on
-- retrobot? v0.99?
-- slots module
-- by tezlo
-- 2003
-- Twiddled a bit to have results sent in PM - by bolamix 1 July 2003
-- unused sTarget left for future syntax parsing.
botName = "your_hub_bot"
-- library
function getid(table, name)
return foreachi(table, function(id, item) if item.sName == %name then return id end end)
end
function putitem(table, item)
if not item then return end
local id = getid(table, item.sName)
if id then table[id] = item
else tinsert(table, item) id = table.n
end return id
end
-- events
function OnTimer()
local i = 1 while tabSlots[i] do
local table = tabSlots[i]
if clock() >= table.iClock + tmrSlots then
if table.tItems.n == 0 then SendPmToNick(table.sName, botName, "No users with free slots found|") end
SendPmToNick(table.sName, botName, "Done|")
tremove(tabSlots, i)
if tabSlots.n == 0 then frmHub:EnableSearchData(0) end
else i = i + 1 end
end
end
function slotsOnHub(user, args)
local s, e, free, all = strfind(args, " (%d+)/(%d+)"..strchar(5))
foreachi(tabSlots, function(id, item)
if not getid(item.tItems, %user.sName) then
putitem(item.tItems, { sName = %user.sName, sValue = %free.."/"..%all })
-- if item.sTarget and (%user.sName == item.sTarget) then
-- SendToNick(item.sName, " user
"..%user.sName.." "..%free.."/"..%all.."|")
-- item.iClock = item.iClock - tmrSlots
-- elseif not item.sTarget and
if (tonumber(%free) >= item.iNR) then
SendPmToNick(item.sName, botName, " user "..%user.sName.." "..%free.."/"..%all.."|")
end
end end)
end
function doSlots(user, nr, nick)
user:SendPM(botName, "Checking..|")
frmHub:EnableSearchData(1)
SendToAll("$Search Hub:"..Command.." T?F?0?1?.|")
putitem(tabSlots, { sName = user.sName, iClock = clock(), iNR = nr, tItems = {n=0} })
-- putitem(tabSlots, { sName = user.sName, sTarget = nick, iClock = clock(), iNR = nr, tItems = {n=0} })
end
-- init
tmrSlots = 5 -- Number of seconds waiting for replys
tabSlots = {n=0}
Command = "+slots"
function DataArrival(user, data)
if strfind(data, "%b<>%s+("..Command..").*|") then
s, e, nr = strfind(data, "%b<>%s+"..Command.."%s+([0-9]+)")
if s then nr = tonumber(nr) else nr = 1 end
doSlots(user, nr) return 1
end
if strfind(data, "^%$SR") then slotsOnHub(user, data) end
end
function Main()
SetTimer(tmrSlots*1000)
StartTimer()
end
or this nice tool
--OnHub Time Logger V.1.5
--Create a "txt" Folder in the PtokaX scripts Folder, like this /scripts/txt/
-- Name this bot to what you want
bot="Master"
--Name the commands to what you like
cmd1 = "+mytime"
cmd2 = "+alltime"
--This number stands for the maximum of displayed users, set it to what U like
Max = 50
---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------
UserHubTime={}
File1 = "UserHubTime.txt"
sec = 1000
min = 60 * sec
function Main()
SetTimer( 1 * min)
StartTimer()
ReadHubUsers()
tophubbers = GetUserMaxTime()
end
function OnTimer()
ReadHubUsers()
for index, value in UserHubTime do
if GetItemByName(index) then
value=value+1
UserHubTime[index]=value
end
end
SaveHubUsers()
tophubbers = GetUserMaxTime()
end
function NewUserConnected(curUser)
if UserHubTime[curUser.sName]==nil then
UserHubTime[curUser.sName]=0
end
end
function OpConnected(curUser)
if UserHubTime[curUser.sName]==nil then
UserHubTime[curUser.sName]=0
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
local tmp = UserHubTime[curUser.sName]
local months, days, hours, minutes = floor(tmp/43200), floor(mod(tmp/1440, 30)), floor(mod(tmp/60, 24)), floor(mod(tmp/1, 60))
curUser:SendData(bot, "You have been online : "..months.." months, "..days.." days, "..hours.." hours, "..minutes.." minutes ( "..UserHubTime[curUser.sName].." min ).")
return 1
end
if (strfind(strlower(data), strlower(cmd2))) then
curUser:SendData(bot, " -= The Top "..Max.." Campers =-\r\n"..
tophubbers.."\r\n")
return 1
end
end
end
----------------------------------------------------------------------------------------------------------
function ReadHubUsers()
local handle = openfile("txt/"..File1, "r")
if (handle) then
local line = read(handle)
while line do
s,e,ind,val = strfind( line, "(%S+)%s+(.*)")
UserHubTime[ind]=val
line = read(handle)
end
closefile(handle)
end
end
----------------------------------------------------------------------------------------------------------
function SaveHubUsers()
local handle = openfile("txt/"..File1, "w")
for index, value in UserHubTime do
if UserHubTime[index]~=0 then
write(handle,index.." "..value.."\r\n")
end
end
closefile(handle)
end
----------------------------------------------------------------------------------------------------------
function GetUserMaxTime()
TCopy={}
for i,v in UserHubTime do
TCopy[i]=v
end
local msgfromtxt ="\r\n"
for i = 1,Max do
var1 = 0
for index, value in TCopy do
value = tonumber (value)
if value > var1 then
var1 = value
userm = index
end
end
local tmp = TCopy[userm]
local months, days, hours, minutes = floor(tmp/43200), floor(mod(tmp/1440, 30)), floor(mod(tmp/60, 24)), floor(mod(tmp/1, 60))
TCopy[userm]=0
msgfromtxt = msgfromtxt.." "..i.." - "..userm.." :: "..months.." Months, "..days.." Days, "..hours.." Hours, "..minutes.." Min ( "..tmp.." min ).\r\n"
end
return msgfromtxt
end
-------------------------------------------------------------------------------------------------------------------------------------------------------
-- ? by chiller and you. Thx to the forum and to tezlo for the nice calculation from minutes to months, days, etc. --
-------------------------------------------------------------------------------------------------------------------------------------------------------