PtokaX forum

Development Section => HOW-TO's => Topic started by: NightLitch on 24 February, 2004, 21:49:36

Title: How to: Make straight fine lines in a view...
Post by: NightLitch on 24 February, 2004, 21:49:36
I want to know how to line up my List's propertly and straight...

this is mine now:

         Msg = Msg .. "\r\n ( "..Nick.." )\t( "..byOP.." )\t( "..Count.." )\t( "..Reason.." )"


outcome like this:
NXS-3 Ban Info

 ( [Local]KR ) ( [SU+]NightLitch ) ( 2 ) ( for no reason )
 ( [Local]KalleAnkasattp ) ( [SU+]NightLitch ) ( 1 ) ( for no reason )


help plz...

want it to be in straight lines no matter the nicks lenghts.

Hope for good answers.

/NL
Title:
Post by: Skrollster on 24 February, 2004, 23:03:01
*hint* strlen() *hint*
Title:
Post by: Skrollster on 24 February, 2004, 23:07:22
One way of solving it is:

Msg = Msg .. "\r\n ( "..Nick.." )"..strrep(" ", 30 - strlen(Nick)).."( "..byOP.." )"..strrep(" ", 30 - strlen(byOP)).."( "..Count.." )"..strrep(" ", 30 - strlen(Count)).."( "..Reason.." )"
Title:
Post by: NightLitch on 25 February, 2004, 00:39:51
Thx Alot Skrollster. Was thinking in that direction but didn't know how to do it.

Thx / NL
Title:
Post by: NightLitch on 25 February, 2004, 00:45:34
Your fine ex. you sent. Is that supposed to work or just a hint for me do get it working in some way?`

cause with yours I get:
( [Local]KR )                     ( [SU+]NightLitch )               ( 2 )                             ( for no reason )
 ( [Local]KalleAnkasattp )         ( [SU+]NightLitch )               ( 1 )                             ( for no reason )
plz some help.


*EDITED*

HUH!!! how is that possible here and not in my client ???
Title:
Post by: NightLitch on 25 February, 2004, 00:51:37
Noticed that it wasn't compatible with MS Sans Serif

But that is the standard font for the clients...
Title:
Post by: NightLitch on 25 February, 2004, 01:09:12
Why is it that that ( Courier New ) is the only Font I have that lines up the line right.... why Skrollster ???

I would want it to work with MS Sans Serif...
Title:
Post by: tezlo on 25 February, 2004, 01:50:00
it will only show up right with fixed fonts (all characters have the same width).. ie. terminal would work as well
Title:
Post by: Skrollster on 25 February, 2004, 12:34:43
as tezlo says it only works with fixed fonts...

but you can get almost perfect by using a formula like(i know this isn't right but you might get it):

Msg = Msg .. "\r\n ( "..Nick.." )"..strrep("\t", 30/(1+strlen(Nick))).."( "..byOP.." )"..strrep("\t", 30/(1+strlen(byOP))).."( "..Count.." )"..strrep("\t", 30/(1+strlen(Count))).."( "..Reason.." )"
i'm using (1+strlen(Count)) to not devide by zero

hope you can get my thought so you can get it to work...
Title:
Post by: Skrollster on 25 February, 2004, 12:36:29
i'm in school right now so i don't know how strrep() will reakt to a real instead of an int, you might have to format it so it becomes an int instead...
Title:
Post by: NightLitch on 25 February, 2004, 16:47:39
Thx Skrollster gonna see what I can come by.
Title:
Post by: tezlo on 25 February, 2004, 16:59:38
had the same problem the other day so i made these two functions..
function pad(str, len)
local diff = len - strlen(str)
if diff <= 0 then return strsub(str, 1, len-2)..".."
else return str..strrep(" ", diff) end
end

function columnize(...)
local str = ""
for i = 1, getn(arg), 2 do str = str..pad(arg[i], arg[i+1]) end
return str
end

columnize(victim, 25, kicker, 25, count, 5, reason, 25)
maybe it helps..
Title:
Post by: Skrollster on 25 February, 2004, 17:04:10
I had to try this out then i came home this was the result i had:

function StraightLines(Nick, byOP, Count, Reason)
Msg = " ( "..Nick.." )"..strrep("\t", 40/(8+strlen(Nick))).."( "..byOP.." )"..strrep("\t", 40/(8+strlen(byOP))).."( "..Count.." )"..strrep("\t", 40/(8+strlen(Count))).."( "..Reason.." )"
return Msg
end
Title:
Post by: NightLitch on 25 February, 2004, 17:17:13
Nice, Nice NICE!!!!

Thx Alot!!!

Wasn't that big of a different from the first.

But I had never got that out.

/NL
Title:
Post by: Skrollster on 25 February, 2004, 17:26:22
Tezlo i get an error the i try to use your functions:

Syntax error: bad argument #1 to `strlen' (string expected, got nil)
stack traceback:
   1:  function `strlen' [C]
   2:  function `pad' at line 16 [file `C:\DC-Hub\Op-m?te\scripts\Test.lua']
   3:  function `columnize' at line 23 [file `C:\DC-Hub\Op-m?te\scripts\Test.lua']
   4:  function `OnTimer' at line 12 [file `C:\DC-Hub\Op-m?te\scripts\Test.lua']

function Main()
SetTimer(500)
StartTimer()
end

function OnTimer()
StopTimer()
Skrollster = GetItemByName("Skrollster")
Skrollster.Send = function(self, text) return Skrollster:SendData(Bot, text) end
test = "Test"
Bot = 'PtokaX'
Skrollster:SendPM(Bot,columnize(victim, 25, kicker, 25, count, 5, reason, 25))
end

function pad(str, len)
local diff = len - strlen(str)
if diff <= 0 then return strsub(str, 1, len-2)..".."
else return str..strrep(" ", diff) end
end

function columnize(...)
local str = ""
for i = 1, getn(arg), 2 do str = str..pad(arg[i], arg[i+1]) end
return str
end
Title:
Post by: tezlo on 25 February, 2004, 18:10:32
try to feed it strings
Title:
Post by: Skrollster on 25 February, 2004, 19:22:22
Sorry, i guess i'm just a bit tired ;)
Title:
Post by: Stravides on 26 February, 2004, 10:32:50
Seems to work :) cheers m8y

victim =
{
"jasdfjasdflh",
"kjasdkja",
"kjashdflkjashdflkjasdfl",
}

kicker =
{
"kjasdkja",
"kjashdflkjashdflkjasdfl",
"jasdfjasdflh",
}

count =
{
"134",
"1234",
"2",
}

reason =
{
"kjasdkja",
"kjashdflkjashdflkjasdfl",
"jasdfjasdflh",
}

function Main()
SetTimer(500)
StartTimer()
end

function OnTimer()
StopTimer()
Stravides = GetItemByName("Stravides")
Stravides.Send = function(self, text) return Stravides:SendData(Bot, text) end
test = "Test"
Bot = 'PtokaX'
for i=1,3 do
Stravides:SendPM(Bot,columnize(victim[i], 30, kicker[i], 30, count[i], 10, reason[i], 25))
end
end

function pad(str, len)
local diff = len - strlen(str)
if diff <= 0 then return strsub(str, 1, len-2)..".."
else return str..strrep(" ", diff) end
end

function columnize(...)
local str = ""
for i = 1, getn(arg), 2 do str = str..pad(arg[i], arg[i+1]) end
return str
end