PtokaX forum

Archive => Archived 5.0 boards => Request for scripts => Topic started by: ruler on 28 February, 2005, 21:42:25

Title: Request: how to convert this to LUA 5
Post by: ruler on 28 February, 2005, 21:42:25
Hi folks!
Sorry but i have had no time to read up on LUA 5 as yet and i was wondering how to convert this small function to LUA 5?
here is the code...

function checkReg(user)
   found,name,password,lev=nil,nil,nil,nil
   readfrom("../RegisteredUsers.dat","|")
      while 1 do
      local line = read()
      if (line == nil) then lev = nil break end
      s,e,name,password,lev=strfind(line,"(.-)\124(.-)\124(.+)")
      if (username == name) then found = 1 break end
      end
   readfrom()
end

This is part of a registration section of my main script.the variable 'found' just acts like a Flag and is nothing more.
I'd be very greatful for any help as i am sure others might benifet from it too, hopefully.
thanks again and btw, i love the new Ptokax HubSoft, its perfect. Just what i wanted :) thanks
Title:
Post by: blackwings on 28 February, 2005, 21:54:19
As far as I see, this is the only thing you need to change =

Change this line =
s,e,name,password,lev=strfind(line,"(.-)\124(.-)\124(.+)")

To this =
s,e,name,password,lev=string.find(line,"(.-)\124(.-)\124(.+)")
Title:
Post by: ruler on 28 February, 2005, 22:14:59
na, that didnt work sorry, it looks like it doesnt recognice the code

readfrom("../RegisteredUsers.dat","|")

and  

readfrom()

there must be another way of doing this?

thanks for the swift reply though.
Title:
Post by: the_pest on 28 February, 2005, 22:38:52
try to change "readfrom" to "io.input"  

or better not, bad advice
Title:
Post by: ruler on 28 February, 2005, 23:53:17
thanks for that but now i have discovered many other problems like the good old ...

function DataArrival(user,data) no longer exists and my scripts are totally usless :(
i love the hubsoft but LUA 5 realy sucks BIG TIME!
nothing works now, its all gone pear shaped ?(
dam where do i start  8o
i realy wanna use this new hubsoft but the new LUA 5 has complicated things a lot, dam dam dam

thanks for the help anyway
Title:
Post by: plop on 01 March, 2005, 00:59:36
QuoteOriginally posted by ruler
thanks for that but now i have discovered many other problems like the good old ...

function DataArrival(user,data) no longer exists and my scripts are totally usless :(
i love the hubsoft but LUA 5 realy sucks BIG TIME!
nothing works now, its all gone pear shaped ?(
dam where do i start  8o
i realy wanna use this new hubsoft but the new LUA 5 has complicated things a lot, dam dam dam

thanks for the help anyway
better check the new scripting.txt, all answers are in that.
beside's there are apearing howto's about how 2 change scripts 2 lua 5.
the changes made 2 ptokax are only for the best.
more things can be done, things are going faster, and more efficient.
and be happy, i had 2 convert about 11.000 lines on my a.i..
but this took about 5 seconds 2 convert about 90% of the code (made a script which does this, and it's posted on the board).

plop
Title:
Post by: ruler on 01 March, 2005, 14:15:04
thanks plop
what is the name of the converter script?
i managed to get one of my scripts converted eccept 1 line...

answer, x = gsub(value[random(1,getn(value))], "%b[]", curUser.sName)

i get the error...
 
Syntax ...en\Desktop\0.3.3.0.b16.04.nt.dgb\scripts\--bot--.lua:665: attempt to call global `getn' (a nil value)

as they say, there's always one ;)
thanks again
Title:
Post by: ruler on 01 March, 2005, 14:45:47
ok im back after serching for your LUA translator!
ive tried to convert this script from the old LUA to the new LUA 5, it still dont work  lol
there are no errors reported but it just dont work for some reason? can anyone see why this wont work please, here is the code...

botname = "-=Ada=-"

trigall=1

trigw = {
             
         lol={
     "hilarious!",
     "hehe",
   "lmao",
   "rofl",
   ":D",
     ":-)"  
                                 },

         fav={
     "Yeah [CURUSER], try this ----->  /fav  ",
     "Hmm, i think its like this dude! ----->  /fav  ",
     "try this ------->  /fav  ",
   "[CURUSER], this might work ----->  /fav  ",
     "I think /fav would work better [CURUSER] ;-)  "
                                 },
             
   }


function Main()
-- frmHub:RegBot(botname)
end

function ChatArrival(curUser, data)

status=string.sub(data,1,string.len(data)-1)
-- parse the command
s,e,cmd = string.find( status, "%b<>%s+(%S+)" )

if (cmd=="+quiet") then
trigall=0
SendToAll("(=R=D=)", " Hmf, Okidoki I will be quiet :(( ")
return 1
elseif (cmd=="+speak") then
trigall=1
SendToAll("(=R=D=)", " Okay, I will talk to you again :-)")
return 1
end

       
   if( string.sub(data, 1, 1) == "<" ) then
      -- get the msg only using regular expression
      s,e,msg = string.find(data, "%b<>([%a ]+)")                                        
      -- look in the table
                if trigall==1 then
      for key, value in trigw do
                for key2, value2 in value do
                     
   if( string.find( string.lower(msg), key) ) then
                 else break  
   end

        if( string.find( string.lower(msg), "!me") ) then
                  t="**"..curUser.sName
                  data=string.gsub (msg, "!me", t, 1 )
   end

      SendToAll( data ) -- send the original data
                   
            SetTimer(1800)
                  StartTimer()
      answer, x = string.gsub(value[math.random(1,table.getn(value))], "%b[]", curUser.sName)

   return 1; -- tell the hub we have processed the data
   end
   end  
   end
end

function OnTimer()
   SendToAll( "(=R=D=)", answer ) -- send bot's answer
   StopTimer()
end
end--------------------------------------------------------------------------------

i think you might already know what it is supposed to do :)
Title:
Post by: the_pest on 01 March, 2005, 14:46:38
This thread (http://board.univ-angers.fr/thread.php?threadid=2923&boardid=5&sid=990c17a9dc54f12de14fd39ebbc9099f) could help you
Title:
Post by: [UK]Madman on 01 March, 2005, 15:50:36
Only a guess, but because of the new ChatArrival .. this >> if( string.sub(data, 1, 1) == "<" ) then    isnt really needed as everything in ChatArrival has obviously come from main chat.  

Is the data comming through ChatArrival still formatted the same as before (e.g. still beginning with "<") ?

If not then this could be a problem....
Title:
Post by: ruler on 01 March, 2005, 15:54:26
dont forget that there isnt only main chat, there is PM too ;)

the "<" is needed to define that its comming from main chat and not in PM
Title:
Post by: [UK]Madman on 01 March, 2005, 16:36:42
function ToArrival(User,Data)   is used for PM data, unless im mistaken  :P
Title:
Post by: jiten on 01 March, 2005, 16:49:21
Yups. That's it Madman.
Title:
Post by: ruler on 01 March, 2005, 17:10:29
i have one last request  8o
how do i get this small function converted into LUA 5?
it just reads the registeredusers.dat...

function checkReg(user)
   found,nme,password,lev=nil,nil,nil,nil
   readfrom("../RegisteredUsers.dat","|")
      while 1 do
      local line = read()
      if (line == nil) then lev = nil break end
      s,e,nme,password,lev=strfind(line,"(.-)\124(.-)\124(.+)")
      if (username == nme) then found = 1 break end
      end
   readfrom()
end


ive tried several ways but it still wont work, this works in the normal LUA but not LUA 5
thanks
Title:
Post by: PPK on 01 March, 2005, 17:58:38
QuoteOriginally posted by [UK]Madman
Is the data comming through ChatArrival still formatted the same as before (e.g. still beginning with "<") ?
PtokaX always send to lua arrivals full DC command as is received from client -> yes command is same as before  :)
Title:
Post by: [_XStaTiC_] on 01 March, 2005, 23:44:34
I'm testing the new Ptokax and i want to know what's the best way to use the Arrival.


This one

function SearchArrival(curUser, data)
if curUser.iProfile == -1 and NoSearch == 1 then
curUser:SendData("*** You are not registered in this hub please register and you may Search.")
return 1
       end  
end

Or this one.

function SearchArrival(curUser, data)
  if (strsub(data, 1, 7) == "$Search") then
if curUser.iProfile == -1 and NoSearch == 1 then
curUser:SendData("*** You are not registered in this hub please register and you may Search.")
return 1
                end      
       end
end
Title:
Post by: PPK on 02 March, 2005, 00:08:35
QuoteOriginally posted by [_XStaTiC_]
function SearchArrival(curUser, data)
  if (strsub(data, 1, 7) == "$Search") then
You don't need to check if is $Search -> it is SearchArrival -> PtokaX always give to this arrival only $Search command  ;)
Title:
Post by: plop on 02 March, 2005, 00:11:46
QuoteOriginally posted by ruler
thanks plop
what is the name of the converter script?
i managed to get one of my scripts converted eccept 1 line...

answer, x = gsub(value[random(1,getn(value))], "%b[]", curUser.sName)

i get the error...
 
Syntax ...en\Desktop\0.3.3.0.b16.04.nt.dgb\scripts\--bot--.lua:665: attempt to call global `getn' (a nil value)

as they say, there's always one ;)
thanks again
answer, x = string.gsub(value[random(1,table.getn(value))], "%b[]", curUser.sName)

plop
Title:
Post by: Typhoon on 02 March, 2005, 23:19:39
QuoteOriginally posted by plop
QuoteOriginally posted by ruler
thanks plop
what is the name of the converter script?
i managed to get one of my scripts converted eccept 1 line...

answer, x = gsub(value[random(1,getn(value))], "%b[]", curUser.sName)

i get the error...
 
Syntax ...en\Desktop\0.3.3.0.b16.04.nt.dgb\scripts\--bot--.lua:665: attempt to call global `getn' (a nil value)

as they say, there's always one ;)
thanks again
answer, x = string.gsub(value[random(1,table.getn(value))], "%b[]", curUser.sName)

plop


Wuhu got you plop :p

answer, x = string.gsub(value[[COLOR=blue]math.random[/COLOR] (1,table.getn(value))], "%b[]", curUser.sName)
Title:
Post by: bastya_elvtars on 02 March, 2005, 23:31:18
Hehe, lucky ppl, you had the opportunity to test lua5 for a while...

But !me just got back to internet...