Request: how to convert this to LUA 5
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Request: how to convert this to LUA 5

Started by ruler, 28 February, 2005, 21:42:25

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ruler

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

The Direct Connect Global Banlist get protected.

blackwings

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(.+)")


ruler

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.

The Direct Connect Global Banlist get protected.

the_pest

#3
try to change "readfrom" to "io.input"  

or better not, bad advice
use

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

The Direct Connect Global Banlist get protected.

plop

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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

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

The Direct Connect Global Banlist get protected.

ruler

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 :)

The Direct Connect Global Banlist get protected.

the_pest

use

[UK]Madman

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....

ruler

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

The Direct Connect Global Banlist get protected.

[UK]Madman

function ToArrival(User,Data)   is used for PM data, unless im mistaken  :P

jiten

Yups. That's it Madman.

ruler

#13
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

The Direct Connect Global Banlist get protected.

PPK

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  :)
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

[_XStaTiC_]

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

PPK

#16
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  ;)
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Typhoon

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)



bastya_elvtars

Hehe, lucky ppl, you had the opportunity to test lua5 for a while...

But !me just got back to internet...
Everything could have been anything else and it would have just as much meaning.

SMF spam blocked by CleanTalk