Author Topic: Some help, plesae ( gsub(), strfind() )  (Read 2340 times)

0 Members and 1 Guest are viewing this topic.

Offline Xico

  • Junior Member
  • **
  • Posts: 18
  • Karma: +1/-0
Some help, plesae ( gsub(), strfind() )
« on: 15 August, 2004, 15:27:52 »
Hello ppl

Well I'm trying to develop some kind of client check and I'm stuck (my skils with Lua are still very poor)

Code: [Select]
sVersion = "0.3.3cvs20040611"
sTempVer = ""
gsub(sVersion, "([0-9.])", function(x) sTempVer = sTempVer ..x end)
After this sTempVer = 0.3.3

The question is: how can I get sTemVer = 0.33 ?

(And thanks to NightLitch, from who I got some good ideas, and some pieces of code)

PtokaX forum

Some help, plesae ( gsub(), strfind() )
« on: 15 August, 2004, 15:27:52 »

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #1 on: 15 August, 2004, 16:09:28 »
Quote
Originally posted by Xico
Hello ppl

Well I'm trying to develop some kind of client check and I'm stuck (my skils with Lua are still very poor)

Code: [Select]
sVersion = "0.3.3cvs20040611"
sTempVer = ""
gsub(sVersion, "([0-9.])", function(x) sTempVer = sTempVer ..x end)
After this sTempVer = 0.3.3

The question is: how can I get sTemVer = 0.33 ?

(And thanks to NightLitch, from who I got some good ideas, and some pieces of code)

try:

Code: [Select]
gsub(sVersion, "(%d+%.([%d+%.]))", function(x) sTempVer = sTempVer ..x end)

Not sure at all, but I think it should something like that.

/NL
//NL

Offline Xico

  • Junior Member
  • **
  • Posts: 18
  • Karma: +1/-0
(No subject)
« Reply #2 on: 15 August, 2004, 17:36:01 »
Well NightLitch you r my hero (don't take it wrong  :)  )but this time it doesn't work

From a sVersion= "0.3.3" I got a sTempVer = "0.3"
It laks the last digit

But tanks for the efort
(and sorry, but english is not my mother longuage)

Edited

and from sVersion= "0.3.020040508" I got sTempVer = "0.30.2".  
« Last Edit: 15 August, 2004, 17:45:18 by Xico »

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #3 on: 15 August, 2004, 17:55:24 »
Try this one then:

Code: [Select]
function Main()
sVersion = "0.3.3cvs20040611"
sTempVer = ""
sTempC = 0
msg = gsub(sVersion, "(%.)", function(x) if x and sTempC ~= 1 then sTempC = 1 return x else return "" end end)
SendToAll(msg)
end

Outcome:

Code: [Select]
0.33cvs20040611

dunno if this is how u want it...

Cheers / NL
//NL

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #4 on: 15 August, 2004, 17:59:00 »
Added a strfind to fix it like this:

Code: [Select]
sVersion = "0.3.3cvs20040611"
sTempVer = ""
sTempC = 0
_,_,sVersion = strfind(sVersion, "([%.%d]+)")
msg = gsub(sVersion, "(%.)", function(x) if x and sTempC ~= 1 then sTempC = 1 return x else return "" end end)
SendToAll(msg)

Outcome:
Code: [Select]
0.33

NL
//NL

Offline Xico

  • Junior Member
  • **
  • Posts: 18
  • Karma: +1/-0
(No subject)
« Reply #5 on: 15 August, 2004, 19:44:33 »
Thanks NightLitch

I'm beeing a lot daring and i'm posting your VersionCheck() with "your" mod (I'm using it on my hub, a litle 1 with 110/150 users)
Code: [Select]
function VersionCheck(curUser, sCliente, vTag)

local sDownload = tFazerDown[sCliente]
local nVersao
local nVersaoMin
local sTempVer
local msg

  sTempC = 0
  _,_,sTempVer = strfind(vTag["V"], "([%.%d]+)")
  msg = gsub(sTempVer, "(%.)", function(x) if x and sTempC ~= 1 then sTempC = 1 return x else return "" end end)
  nVersao = tonumber(msg)
  sTempC = 0
  _,_,sTempVer = strfind(tVersaoCliente[sCliente], "([%.%d]+)")
  msg = gsub(sTempVer, "(%.)", function(x) if x and sTempC ~= 1 then sTempC = 1 return x else return "" end end)
  nVersaoMin = tonumber(msg)
 
-- // debug Information
--local usr = GetItemByName("Xico")
--if usr then
--usr:SendPM("Debug", "Cliente: "..sCliente.."   Tag: "..vTag["V"].."   MinVersion: "..nVersaoMin.."   ActVersion: "..nVersao)
--end

if nVersao < nVersaoMin then
Counter["MinVer"] = Counter["MinVer"] + 1
curUser:SD(BotName,Arg(CC5, sCliente, "CLIENT", vTag["V"], "VERSION"))
curUser:SD(BotName,Arg(CC6, sCliente, "CLIENT", sVersao, "VERSION", sCliente, "CLI", sDownload, "DL"))
curUser:Disconnect()
end
end

Once more, many thanks for your help
« Last Edit: 15 August, 2004, 19:46:09 by Xico »

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #6 on: 15 August, 2004, 19:57:06 »
Your welcome m8
//NL

PtokaX forum

(No subject)
« Reply #6 on: 15 August, 2004, 19:57:06 »