[Help] Age - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [Help] Age (
/showthread.php?tid=353228)
[Help] Age -
rAzvAn18 - 22.06.2012
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 ?
Re: [Help] Age -
[NWA]Hannes - 22.06.2012
new year;
getdate(year);
then take the current year minus the year they wrote they were born?
AW: [Help] Age -
Nero_3D - 22.06.2012
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
}
Re: [Help] Age -
rAzvAn18 - 23.06.2012
It's not working at BirthAge[playerid] I put 4121994 (4/12/1994 | DD/MM/YYYY).
AW: Re: [Help] Age -
Nero_3D - 23.06.2012
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
Re: [Help] Age -
rAzvAn18 - 23.06.2012
O sorry

) , I don't see that part
It's Working , Thanks a lot