[Help] Age
#1

How i can make to get age with Birth Date. On Player Register they put they Birth Age. And at /stats to show the age.
I was thinking to " Current Year - Birth Year" But i was born in 4th december 1994 an 2012-1994 = 18 years but in december i make 18.

Can anybody help me please ?
Reply
#2

new year;
getdate(year);

then take the current year minus the year they wrote they were born?
Reply
#3

Its not difficult, you only need a if statement

pawn Код:
// BirthAge is my imaginary variable which stores the, yeah Birth Age
// I save the date into the format year, 4 char, month, 2 char, day also 2 char
// BirthAge[playerid] = year * 10000 + month * 100 + day;
stock GetAge(playerid) { // forum.sa-mp.com/showpost.php?p=1939338&postcount=3
    new
        day,
        year,
        month
    ;
    getdate(year, month, day);
    month = month * 100 + day; // current month and day
    day = BirthAge[playerid] % 10000; // extracts month and day
    year = year - BirthAge[playerid] / 10000; // gets the difference in years
    return (day <= month) ? (year) : (year - 1); // if current date is higher or equal he already had birthday
}
Reply
#4

It's not working at BirthAge[playerid] I put 4121994 (4/12/1994 | DD/MM/YYYY).
Reply
#5

Quote:
Originally Posted by rAzvAn18
Посмотреть сообщение
It's not working at BirthAge[playerid] I put 4121994 (4/12/1994 | DD/MM/YYYY).
Thats mostly because I wrote in my post that you need to save it like that

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
pawn Код:
// BirthAge[playerid] = year * 10000 + month * 100 + day;
And that would result in BirthAge[playerid] = 19941204

Just to help you a bit
pawn Код:
// n3d - forum.sa-mp.com/showpost.php?p=1940997&postcount=5
stock SetPlayerBirthday(playerid, day, month, year) {
    return (BirthAge[playerid] = year * 10000 + month * 100 + day);
}
If you try to understand my code you will understand why you need to save it like that
Reply
#6

O sorry ) , I don't see that part

It's Working , Thanks a lot
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)