[Snippet] User Age

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

[Snippet] User Age

Post by Archive-Poster »

Hi
I was going to do some chat plugin for display Age of player.
Well i decided to stop working on it, i have 2 servers to finish and no time to continue it.
You can do whatever you want with it, chat, change nick, whatever. Top15 or a list
At moment user set age with console command: amx_setage "day" "month" "year", but i thought in make menu but willnt do at moment so if someone wants it would be better then command probably

IMPORTANT: The values in check_user_age has to be num so if you getting value from str you have to convert to num. This also includes if user is in Birthday so make sure when user sets him age to put the bool false or he can continue with the bool true

Code: Select all

#include <amxmodx>
#include <amxmisc>
#include <nvault>

#define MIN_AGE 13
#define MAX_AGE 75

new age[33], day[33], month[33], year[33]
new bool:in_birthday[33]
new g_vault

public plugin_init() {
    register_plugin("Age", "0.0.1", "Jhob94")
    
    register_concmd("amx_setage", "set_age", ADMIN_ALL, "^"day^" ^"month^" ^"year^"")
    
    g_vault = nvault_open("ages_vault")
}

public client_putinserver(id)
{
    age[id] = 0
    day[id] = 0
    month[id] = 0
    year[id] = 0
    in_birthday[id] = false
    LoadAge(id)
}

public set_age(id, level, cid)
{
    if(!cmd_access(id, level, cid, 4))
        return

    new age_day[3], age_month[3], age_year[5]
    read_argv(1, age_day, 2)
    read_argv(2, age_month, 2)
    read_argv(3, age_year, 4)
    
    year[id] = str_to_num(age_year)
    month[id] = str_to_num(age_month)
    day[id] = str_to_num(age_day)
    
    if(month[id] > 12 || day[id] > 31)
        return
    
    in_birthday[id] = false
    
    SaveAge(id)
    
    check_user_age(id, year[id], month[id], day[id])
}

public SaveAge(id)
{
    new AuthID[35]
    get_user_authid(id, AuthID, 34)
    
    new vaultkey[64], vaultdata[256]
    format(vaultkey, 63, "%s-ages", AuthID)
    format(vaultdata, 255, "%i %i %i ", year[id], month[id], day[id])
    nvault_set(g_vault, vaultkey, vaultdata)
}

public LoadAge(id)
{
    new AuthID[35]
    get_user_authid(id, AuthID, 34)
    
    new vaultkey[64], vaultdata[256]
    format(vaultkey, 63, "%s-ages", AuthID)
    format(vaultdata, 255, "%i %i %i ", year[id], month[id], day[id])
    nvault_get(g_vault, vaultkey, vaultdata, 255)
    
    new age_year[5], age_month[3], age_day[3]
    
    parse(vaultdata, age_year, 4, age_month, 2, age_day, 2)
    
    year[id] = str_to_num(age_year)
    month[id] = str_to_num(age_month)
    day[id] = str_to_num(age_day)
    
    check_user_age(id, year[id], month[id], day[id])
}

stock check_user_age(id, age_year, age_month, age_day)
{
    new y[5], m[3], d[3], today_year, today_month, today_day
    get_time("%Y", y, 4)
    get_time("%m", m, 2)
    get_time("%d", d, 2)
    
    today_year = str_to_num(y)
    today_month = str_to_num(m)
    today_day = str_to_num(d)
    
    if(today_year < age_year)
        return
    
    age[id] = today_year - age_year
    
    if(today_month <= age_month)
    {
        if(today_month == age_month && today_day < age_day || today_month < age_month)
            age[id] -= 1
    }
    
    if(age[id] < MIN_AGE || age[id] > MAX_AGE)
        age[id] = 0
    
    if(today_month == age_month && today_day == age_day)
        in_birthday[id] = true
} 
EDIT:
You shouldnt change value of MIN_AGE because steam only allows older then 13. Anyway you can set it higher

Who is online

Users browsing this forum: No registered users and 1 guest