PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: Syphrone-NL on 10 September, 2005, 11:40:43

Title: need help with Birthday script 3.5
Post by: Syphrone-NL on 10 September, 2005, 11:40:43
I got birthday script 3.5 and its working great but i want something in the birthday list that the birthdays are sorted on date. So that the one in January first is in the list and the one in December the last in the list can somebody make this for me.

Here i got the birthday list from the script:

function ListBirths(user, how)
local str = "The Birthday List of the users of this Hub"
local msg = "\r\n    ..-*'~ "..str.." ~'*-..\r\n"..string.rep("^", string.len(str)+2).."\r\n\t"
local c = 0
local status = ""
for i, v in tBirthdays do
if GetItemByName(i) then status = "online" else status = "offline" end
c = c + 1
tip = ". - "..tBirthdays[i][1].."/"..tBirthdays[i][2].."/"..tBirthdays[i][3].."\t- \t"..i.."\t"..Zodiac(tBirthdays[i]).."\t ( "..status.." )"
if tBirthdays[i][1].."/"..tBirthdays[i][2] == os.date("%d/%m") then
tip = tip.."-+-"
end
msg = msg..c..tip.."\r\n\t"
end
if loadcelebs ~= 0 then
for i, v in tCelebs do
status = ":Celebrity:"
c = c + 1
tip = ". - \t"..tCelebs[i][1].."/"..tCelebs[i][2].."/"..tCelebs[i][3].."\t- \t"..i.."\t"..Zodiac(tCelebs[i]).."\t ( "..status.." )"
if tCelebs[i][1].."/"..tCelebs[i][2] == os.date("%d/%m") then
tip = tip.."-+-"
end
msg = msg..c..tip.."\r\n\t"
end
end
SendBack(msg, user, how)
end
Title:
Post by: mateci on 10 September, 2005, 23:49:57

-- SerializeDates function by Mateci as requested by Syphrone-NL
-- This function is serializing dates (smaller to bigger) . If you want bigger to smaller then change "<" with ">" .
-- tBirthdays[][3]=name, tBirthdays[][2]=month, tBirthdays[][1]=day
-- If tBirthdays[][2] or tBirthdays[][1] is a string then use tonumber after if and elseif lines( like  tonumber( tBirthdays[j][2] ) < tonumber( tBirthdays[i][2] ) )
-- Good uses

function SerializeDates(tBirthdays)
for i in ipairs(tBirthdays) do
for j in ipairs(tBirthdays) do
if j>i then
if tBirthdays[j][2] < tBirthdays[i][2] then
tBirthdays[i][1],tBirthdays[j][1] = tBirthdays[j][1],tBirthdays[i][1]
tBirthdays[i][2],tBirthdays[j][2] = tBirthdays[j][2],tBirthdays[i][2]
tBirthdays[i][3],tBirthdays[j][3] = tBirthdays[j][3],tBirthdays[i][3]
elseif tBirthdays[j][2] == tBirthdays[i][2] then
if tBirthdays[j][1] < tBirthdays[i][1] then
tBirthdays[i][1],tBirthdays[j][1] = tBirthdays[j][1],tBirthdays[i][1]
tBirthdays[i][2],tBirthdays[j][2] = tBirthdays[j][2],tBirthdays[i][2]
tBirthdays[i][3],tBirthdays[j][3] = tBirthdays[j][3],tBirthdays[i][3]
end
end
end
end
end
end

Title:
Post by: bastya_elvtars on 11 September, 2005, 00:21:48
Wouldn't a JulianDate be better? Just asking...
Title:
Post by: Syphrone-NL on 11 September, 2005, 10:43:26
Mateci can i putt that in the birthday 3.5 script because i wanted that in the script not a stand alone script and can you say then how to putt it in the script



Bastya_elvtars whats a JulianDate???
Title:
Post by: mateci on 11 September, 2005, 14:37:01
QuoteOriginally posted by Syphrone-NL

whats a JulianDate???


JulianDate is a function which converts date to decimal.

Yes it can be better but there are only month and day so i dont need convert date to decimal. (i use only 3 if)

It s not a script it is only a function, Syphrone-NL. so you can put that anywhere u want in script, only use "SerializeDates(tBirthdays)" before "for i, v in tBirthdays do"
Title:
Post by: bastya_elvtars on 11 September, 2005, 16:10:15
But if use the current year, you will get decimel values that are easy to sort, no need for double loop.
Title:
Post by: Syphrone-NL on 11 September, 2005, 20:07:44
i tryed putting it in the script but it doesnt work  

can somebody post the script with that function in it in here please
Title:
Post by: mateci on 11 September, 2005, 20:38:34
Syphrone-NL,Can you send the tBirthdays and tCelebs tables (or an example of tables), so i can modify it for your script?

bastya_elvtars, can u send juliandate function? ( i think we are talking different functions because julian date function which i saw has lots of mathematical operators. But i use only three if. so i use that. )
Title:
Post by: Syphrone-NL on 11 September, 2005, 21:21:39
Take some glasses look at the top i already post it in the beginning but for you here you go:

function ListBirths(user, how)
local str = "The Birthday List of the users of this Hub"
local msg = "\r\n    ..-*'~ "..str.." ~'*-..\r\n"..string.rep("^", string.len(str)+2).."\r\n\t"
local c = 0
local status = ""
for i, v in tBirthdays do
if GetItemByName(i) then status = "online" else status = "offline" end
c = c + 1
tip = ". - "..tBirthdays[i][1].."/"..tBirthdays[i][2].."/"..tBirthdays[i][3].."\t- \t"..i.."\t"..Zodiac(tBirthdays[i]).."\t ( "..status.." )"
if tBirthdays[i][1].."/"..tBirthdays[i][2] == os.date("%d/%m") then
tip = tip.."-+-"
end
msg = msg..c..tip.."\r\n\t"
end
if loadcelebs ~= 0 then
for i, v in tCelebs do
status = ":Celebrity:"
c = c + 1
tip = ". - \t"..tCelebs[i][1].."/"..tCelebs[i][2].."/"..tCelebs[i][3].."\t- \t"..i.."\t"..Zodiac(tCelebs[i]).."\t ( "..status.." )"
if tCelebs[i][1].."/"..tCelebs[i][2] == os.date("%d/%m") then
tip = tip.."-+-"
end
msg = msg..c..tip.."\r\n\t"
end
end
SendBack(msg, user, how)
end

Thats the little thing out of birthdayman 3.5   lua5
Title:
Post by: Syphrone-NL on 11 September, 2005, 21:28:10
If you need something else

look at this

5th post that one from jiten (http://board.univ-angers.fr/thread.php?threadid=4134&boardid=28&sid=ddf6e584243d73717346608d45d052af)
Title:
Post by: mateci on 11 September, 2005, 22:23:08
QuoteOriginally posted by mateci

Syphrone-NL,Can you send the tBirthdays and tCelebs ***---tables---*** (or an example of tables), so i can modify it for your script?


QuoteOriginally posted by Syphrone-NL

Take some glasses look at the top i already post it in the beginning but for you here you go:

i didnt want the list function, i want the tables so i can understand what the meaning of i in tBirthdays[1] or meaning of tBirthdays[3]. it will be number or name or year or sth else. pls read my post carefully and answer then..

please more carefull about what u are writing.

thx
Title:
Post by: Syphrone-NL on 12 September, 2005, 07:52:36
Im really sorry

I searched the scripted and found something here you go:

--- // --- Table Serialization --- Thanks NL
function Serialize(tTable, sTableName, sTab)

        assert(tTable, "tTable equals nil");
        assert(sTableName, "sTableName equals nil");

        assert(type(tTable) == "table", "tTable must be a table!");
        assert(type(sTableName) == "string", "sTableName must be a string!");

        sTab = sTab or "";
        sTmp = ""

        sTmp = sTmp..sTab..sTableName.." = {\n"

        for key, value in tTable do
                local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);

                if(type(value) == "table") then
                        sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
                else
                        local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
                        sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
                end

                sTmp = sTmp..",\n"
        end

        sTmp = sTmp..sTab.."}"
        return sTmp
end

or

--- // --- Script-Starts
tBirthdays = {}
tCelebs = {}
tCalendar = {
[1] = { 31, "January", },
[2] = { 28, "February", },
[3] = { 31, "March", },
[4] = { 30, "April", },
[5] = { 31, "May", },
[6] = { 30, "June", },
[7] = { 31, "July", },
[8] = { 31, "August", },
[9] = { 30, "September", },
[10] = { 31, "October", },
[11] = { 30, "November", },
[12] = { 31, "December", },
}

if this is not what youre looking for please see the script here:

5th post that one from jiten (http://board.univ-angers.fr/thread.php?threadid=4134&boardid=28&sid=ddf6e584243d73717346608d45d052af)
Title:
Post by: mateci on 12 September, 2005, 14:59:50
Ok then, i also add a function for converting tables in a form for serializedates function. also some changes in list function.

--Convert and SerializeDates functions by Mateci

function Convert(tBirthdays)
local tBirthdaysCur,iCount = {},0
for i in pairs(tBirthdays) do
iCount = iCount+1
tBirthdaysCur[iCount] = {}
tBirthdaysCur[iCount][1] = tBirthdays[i][1]
tBirthdaysCur[iCount][2] = tBirthdays[i][2]
tBirthdaysCur[iCount][3] = tBirthdays[i][3]
tBirthdaysCur[iCount][4] = i
end
return tBirthdaysCur,iCount
end

function SerializeDates(tBirthdays,iCount)
for i=1,iCount do
for j=(i+1),iCount do
if tBirthdays[j][2] < tBirthdays[i][2] then
tBirthdays[i][1],tBirthdays[j][1] = tBirthdays[j][1],tBirthdays[i][1]
tBirthdays[i][2],tBirthdays[j][2] = tBirthdays[j][2],tBirthdays[i][2]
tBirthdays[i][3],tBirthdays[j][3] = tBirthdays[j][3],tBirthdays[i][3]
tBirthdays[i][4],tBirthdays[j][4] = tBirthdays[j][4],tBirthdays[i][4]
elseif tBirthdays[j][2] == tBirthdays[i][2] then
if tBirthdays[j][1] < tBirthdays[i][1] then
tBirthdays[i][1],tBirthdays[j][1] = tBirthdays[j][1],tBirthdays[i][1]
tBirthdays[i][2],tBirthdays[j][2] = tBirthdays[j][2],tBirthdays[i][2]
tBirthdays[i][3],tBirthdays[j][3] = tBirthdays[j][3],tBirthdays[i][3]
tBirthdays[i][4],tBirthdays[j][4] = tBirthdays[j][4],tBirthdays[i][4]
end
end
end
end
return tBirthdays
end
-- The finish of Mateci's functions
---------------------------------------------------------------------
function ListBirths(user, how)
local str = "The Birthday List of the users of this Hub"
local msg = "\r\n    ..-*'~ "..str.." ~'*-..\r\n"..string.rep("^", string.len(str)+2).."\r\n\t"
local c = 0
local status = ""
local tBirthdaysCur = SerializeDates(Convert(tBirthdays))
for i in ipairs(tBirthdaysCur) do
local sUser =  tBirthdaysCur[i][4]
if GetItemByName(sUser) then status = "online" else status = "offline" end
c = c + 1
tip = ". - "..tBirthdaysCur[i][1].."/"..tBirthdaysCur[i][2].."/"..tBirthdaysCur[i][3].."\t- \t"..tBirthdaysCur[i][4].."\t"..Zodiac(tBirthdaysCur[i]).."\t ( "..status.." )"
if tBirthdaysCur[i][1].."/"..tBirthdaysCur[i][2] == os.date("%d/%m") then
tip = tip.."-+-"
end
msg = msg..c..tip.."\r\n\t"
end
if loadcelebs ~= 0 then
local tCelebsCur = SerializeDates(Convert(tCelebs))
for i in ipairs(tCelebsCur) do
status = ":Celebrity:"
c = c + 1
tip = ". - \t"..tCelebsCur[i][1].."/"..tCelebsCur[i][2].."/"..tCelebsCur[i][3].."\t- \t"..tCelebsCur[i][4].."\t"..Zodiac(tCelebsCur[i]).."\t ( "..status.." )"
if tCelebsCur[i][1].."/"..tCelebsCur[i][2] == os.date("%d/%m") then
tip = tip.."-+-"
end
msg = msg..c..tip.."\r\n\t"
end
end
SendBack(msg, user, how)
end



Please send errors so i can fix them.  (i check my functions by lua console but not all script)

Good Uses
Title:
Post by: Syphrone-NL on 12 September, 2005, 16:27:08
Thank you very much i works great got no errors
Title:
Post by: Syphrone-NL on 12 September, 2005, 16:33:08
It worked great but then somebody wanted to add his birthday and then i got this error

[16:29] Syntax ...ivate Hub\0.3.3.0.b17.09.nt.dbg\scripts\birthday.lua:587: attempt to call global `Serialize' (a nil value)

And now he cleaned my whole birthday list
Title:
Post by: Syphrone-NL on 12 September, 2005, 16:38:44
Damn that was my fould its already solved deleted to much of the script  8o  :rolleyes:  

So no errors again  :D

THX THX THX  :D  8)
Title:
Post by: bastya_elvtars on 12 September, 2005, 18:30:44
QuoteOriginally posted by mateci
bastya_elvtars, can u send juliandate function? ( i think we are talking different functions because julian date function which i saw has lots of mathematical operators. But i use only three if. so i use that. )

In lawmaker.lua you can find it.
Title:
Post by: mateci on 13 September, 2005, 15:49:02
as i said before the juliandate function has lots of mathematical operators.


function JulianDate(DAY, MONTH, YEAR, HOUR, MINUTE, SECOND) -- Written by RabidWombat.
-- HOUR is 24hr format.
  local jy, ja, jm;
  assert(YEAR ~= 0);
  assert(YEAR ~= 1582 or MONTH ~= 10 or DAY < 4 or DAY > 15);
  --The dates 5 through 14 October, 1582, do not exist in the Gregorian system!
  if(YEAR < 0 ) then
    YEAR = YEAR + 1;
  end
  if( MONTH > 2) then
    jy = YEAR;
    jm = MONTH + 1;
  else
    jy = YEAR - 1;
    jm = MONTH + 13;
  end
  local intgr = math.floor( math.floor(365.25*jy) + math.floor(30.6001*jm) + DAY + 1720995 );
  --check for switch to Gregorian calendar
  local gregcal = 15 + 31*( 10 + 12*1582 );
  if(DAY + 31*(MONTH + 12*YEAR) >= gregcal ) then
    ja = math.floor(0.01*jy);
    intgr = intgr + 2 - ja + math.floor(0.25*ja);
  end
  --correct for half-day offset
  local dayfrac = HOUR / 24 - 0.5;
  if( dayfrac < 0.0 ) then
    dayfrac = dayfrac + 1.0;
    intgr = intgr - 1;
  end
  --now set the fraction of a day
  local frac = dayfrac + (MINUTE + SECOND/60.0)/60.0/24.0;
  --round to nearest second
  local jd0 = (intgr + frac)*100000;
  local  jd  = math.floor(jd0);
  if( jd0 - jd > 0.5 ) then jd = jd + 1 end
  return jd/100000;
end


three if is more faster and less source consumer than lots of math functions and ifs, is it?