[STOCK] CalculateAge

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1367
Gender:
United States of America

[STOCK] CalculateAge

Post by Archive-Poster »

Return age!

Usage: CalculateAge(year, month, day), example: CalculateAge( 1990, 05, 08 )

Code: Select all

stock CalculateAge(year, month, day)
{
    new currentyear, currentmonth, currentday, age;
    date(currentyear, currentmonth, currentday);
    age = currentyear - year;
    if(currentmonth < month || currentmonth == month && currentday < day) age--;
    return (age >= 0 && day != 0 && month != 0 && day < 32 && month < 13 && year < currentyear+1) ? age : -1;
}
Example Plugin:

Code: Select all

#include <amxmodx>
#include <calculateage>

public plugin_init()
{
    register_plugin("Age Stock Test", "0.1", "kiki33")
    register_clcmd("get_age", "get_your_age", ADMIN_ALL, "<birthyear> <birthmonth> <birthday>")
}

public get_your_age(id)
{
        static Arg[5], Arg2[3], Arg3[3];
        read_argv(1, Arg, 4);
        read_argv(2, Arg2, 2);
        read_argv(3, Arg3, 2);
        
        if(!Arg[1] || !Arg2[1]  || !Arg3[1] ) return 1;
        
        new age = CalculateAge(str_to_num(Arg), str_to_num(Arg2), str_to_num(Arg3));
        
        client_print(id, print_chat, "Your Age: %d", age);
        
        return 1;
} 
Attachments
calculateage.inc.zip
(378 Bytes) Downloaded 8 times

Who is online

Users browsing this forum: No registered users and 1 guest