Author Topic: Help! want a smoother way!  (Read 2733 times)

0 Members and 1 Guest are viewing this topic.

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
Help! want a smoother way!
« on: 14 March, 2004, 21:36:59 »
Hey guys, have tried many things know, but are back to this shit again if elseif etc. instead of for a,b in table do or i = 1,getn(table) etc.

plz help me shorten this elseif etc. to maybe a smoother way, plz.

Code: [Select]
function NewUserConnected(curUser)
local tmp1 = NK[curUser.sName]
local tmp2 = IP[curUser.sIP]
if tmp2 then
if tmp2[1] and not tmp2[2] then IP[curUser.sIP]={tmp2[1],curUser.sName}
elseif tmp2[2] and not tmp2[3] then IP[curUser.sIP]={tmp2[1],tmp2[2],curUser.sName}
elseif tmp2[3] and not tmp2[4] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],curUser.sName}
elseif tmp2[4] and not tmp2[5] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],tmp2[4],curUser.sName}
elseif tmp2[5] and not tmp2[6] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],tmp2[4],tmp2[5],curUser.sName}
elseif tmp2[6] and not tmp2[7] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],tmp2[4],tmp2[5],tmp2[6],curUser.sName}
elseif tmp2[7] and not tmp2[8] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],tmp2[4],tmp2[5],tmp2[6],tmp2[7],curUser.sName}
elseif tmp2[8] and not tmp2[9] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],tmp2[4],tmp2[5],tmp2[6],tmp2[7],tmp2[8],curUser.sName}
elseif tmp2[9] and not tmp2[10] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],tmp2[4],tmp2[5],tmp2[6],tmp2[7],tmp2[8],tmp2[9],curUser.sName}
elseif tmp2[10] and not tmp2[11] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],tmp2[4],tmp2[5],tmp2[6],tmp2[7],tmp2[8],tmp2[9],tmp2[10],curUser.sName}
end
else
IP[curUser.sIP]={curUser.sName}
end
if tmp1 then
if tmp1[1] and not tmp1[2] then NK[curUser.sName]={tmp1[1],curUser.sIP}
elseif tmp1[2] and not tmp1[3] then NK[curUser.sName]={tmp1[1],tmp1[2],curUser.sIP}
elseif tmp1[3] and not tmp1[4] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],curUser.sIP}
elseif tmp1[4] and not tmp1[5] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],tmp1[4],curUser.sIP}
elseif tmp1[5] and not tmp1[6] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],tmp1[4],tmp1[5],curUser.sIP}
elseif tmp1[6] and not tmp1[7] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],tmp1[4],tmp1[5],tmp1[6],curUser.sIP}
elseif tmp1[7] and not tmp1[8] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],tmp1[4],tmp1[5],tmp1[6],tmp1[7],curUser.sIP}
elseif tmp1[8] and not tmp1[9] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],tmp1[4],tmp1[5],tmp1[6],tmp1[7],tmp1[8],curUser.sIP}
elseif tmp1[9] and not tmp1[10] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],tmp1[4],tmp1[5],tmp1[6],tmp1[7],tmp1[8],tmp1[9],curUser.sIP}
elseif tmp1[10] and not tmp1[11] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],tmp1[4],tmp1[5],tmp1[6],tmp1[7],tmp1[8],tmp1[9],tmp1[10],curUser.sIP}
end
else
NK[curUser.sName]={curUser.sIP}
end

SaveToFile(IP , "IP", F)
SaveToFile(NK , "NK", N)
end

it is a Database that stores info on how many ip per nick and nick per ip.

/NL
//NL

PtokaX forum

Help! want a smoother way!
« on: 14 March, 2004, 21:36:59 »

Offline tezlo

  • Triple Ace
  • **
  • Posts: 225
  • Karma: +1/-0
(No subject)
« Reply #1 on: 14 March, 2004, 22:45:51 »
NK[user.sName] = NK[user.sName] or {}
tinsert(NK[user.sName], user.sIP)
..

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #2 on: 14 March, 2004, 22:54:26 »
Quote
Originally posted by tezlo
NK[user.sName] = NK[user.sName] or {}
tinsert(NK[user.sName], user.sIP)
..

could you do an ex. if I not understand it right. gonna try.

/NL
//NL

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #3 on: 14 March, 2004, 22:59:18 »
back to the beginning it feels like with tables, suck...

help Tezlo:

Code: [Select]
function NewUserConnected(curUser)

IP[curUser.sIP] = IP[curUser.sIP] or {}
tinsert(IP[curUser.sIP], curUser.sName)

NK[curUser.sName] = NK[curUser.sName] or {}
tinsert(NK[curUser.sName], curUser.sIP)

SaveToFile(IP , "IP", F)
SaveToFile(NK , "NK", N)
end

just by this I get double's:
Code: [Select]
IP = {
["127.0.0.1"] = {
[1] = "[Local]Sabin",
[2] = "[Local]Sabin",
["n"] = 2,
},
}

NK = {
["[Local]Sabin"] = {
[1] = "127.0.0.1",
[2] = "127.0.0.1",
["n"] = 2,
},
}

plz help

/NL
//NL

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #4 on: 14 March, 2004, 23:17:37 »
plz some help... getting nuts...

/NL
//NL

[NL]Pur

  • Guest
(No subject)
« Reply #5 on: 14 March, 2004, 23:27:14 »
can't you write a check that looks if the ip already excist under a username. and then it shouldn't be added.

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #6 on: 14 March, 2004, 23:29:49 »
Quote
Originally posted by [NL]Pur
can't you write a check that looks if the ip already excist under a username. and then it shouldn't be added.

have tried and no luck in that, then it will not write anyting. but maybe have something.

else help help...
//NL

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #7 on: 14 March, 2004, 23:45:40 »
here is my solusion, tell me if it's totaly messed up.

Code: [Select]
IP[curUser.sIP] = IP[curUser.sIP] or {}
local check =""
for ip,table in IP do
for n,nick in table do
if curUser.sName==nick then
check="1"
end
end
end
if check=="" then
tinsert(IP[curUser.sIP], curUser.sName)
end
//NL

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
(No subject)
« Reply #8 on: 14 March, 2004, 23:51:14 »
here is the complete solusion for my problem above i hope, if not, then tell me Tezlo.

Code: [Select]
function NewUserConnected(curUser)
IP[curUser.sIP] = IP[curUser.sIP] or {}
local ch1,temp ="",IP[curUser.sIP]
if temp then
for n,nick in temp do
if curUser.sName==nick then
ch1="1"
end
end
end
if ch1=="" then tinsert(IP[curUser.sIP], curUser.sName) end
NK[curUser.sName] = NK[curUser.sName] or {}
local ch2,temp ="",NK[curUser.sName]
if temp then
for n,ip in temp do
if curUser.sIP==ip then
ch2="1"
end
end
end
if ch2=="" then tinsert(NK[curUser.sName], curUser.sIP) end
SaveToFile(IP , "IP", F)
SaveToFile(NK , "NK", N)
end

/NL
//NL

PtokaX forum

(No subject)
« Reply #8 on: 14 March, 2004, 23:51:14 »