Raised This Month: $51 Target: $400
 12% 

[Snippet] User Age


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 08-24-2013 , 14:41   [Snippet] User Age
Reply With Quote #1

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

PHP Code:
#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(idlevelcid)
{
    if(!
cmd_access(idlevelcid4))
        return

    new 
age_day[3], age_month[3], age_year[5]
    
read_argv(1age_day2)
    
read_argv(2age_month2)
    
read_argv(3age_year4)
    
    
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(idyear[id], month[id], day[id])
}

public 
SaveAge(id)
{
    new 
AuthID[35]
    
get_user_authid(idAuthID34)
    
    new 
vaultkey[64], vaultdata[256]
    
format(vaultkey63"%s-ages"AuthID)
    
format(vaultdata255"%i %i %i "year[id], month[id], day[id])
    
nvault_set(g_vaultvaultkeyvaultdata)
}

public 
LoadAge(id)
{
    new 
AuthID[35]
    
get_user_authid(idAuthID34)
    
    new 
vaultkey[64], vaultdata[256]
    
format(vaultkey63"%s-ages"AuthID)
    
format(vaultdata255"%i %i %i "year[id], month[id], day[id])
    
nvault_get(g_vaultvaultkeyvaultdata255)
    
    new 
age_year[5], age_month[3], age_day[3]
    
    
parse(vaultdataage_year4age_month2age_day2)
    
    
year[id] = str_to_num(age_year)
    
month[id] = str_to_num(age_month)
    
day[id] = str_to_num(age_day)
    
    
check_user_age(idyear[id], month[id], day[id])
}

stock check_user_age(idage_yearage_monthage_day)
{
    new 
y[5], m[3], d[3], today_yeartoday_monthtoday_day
    get_time
("%Y"y4)
    
get_time("%m"m2)
    
get_time("%d"d2)
    
    
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

Credits Nvault: http://forums.alliedmods.net/showthr...ghlight=nvault
Thanks to YamiKaitou and .Dare Devil.

EDIT:
You shouldnt change value of MIN_AGE because steam only allows older then 13. Anyway you can set it higher
__________________

Last edited by Jhob94; 08-28-2013 at 13:20.
Jhob94 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-24-2013 , 15:03   Re: [Snippet] User Age
Reply With Quote #2

Why guys keep using # to separate values in vault when spaces is just ok ?
Why guys keep adding a string to steamid when steamid is just ok to use as key ?
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 08-24-2013 at 15:04.
ConnorMcLeod is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 08-24-2013 , 15:34   Re: [Snippet] User Age
Reply With Quote #3

Well i just used from the xp tutorial, didnt changed much. Anyway does that affects the running of plugin?
__________________
Jhob94 is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 08-25-2013 , 10:35   Re: [Snippet] User Age
Reply With Quote #4

Quote:
Originally Posted by Jhob94 View Post
Well i just used from the xp tutorial, didnt changed much. Anyway does that affects the running of plugin?
Not adding a string to the key means that you don't have to call format
Using a space means that you don't have to call replace_all
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).

Last edited by YamiKaitou; 08-25-2013 at 10:35.
YamiKaitou is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 08-25-2013 , 18:57   Re: [Snippet] User Age
Reply With Quote #5

Ok
__________________
Jhob94 is offline
BLacking98
Veteran Member
Join Date: Oct 2012
Location: California
Old 09-08-2013 , 19:57   Re: [Snippet] User Age
Reply With Quote #6

I'm sorry for the question but how do you calculate players ages ?
__________________
BLacking98 is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 09-10-2013 , 07:23   Re: [Snippet] User Age
Reply With Quote #7

look the stock. The actual year - born year. If player hadnt his birthday this year yet, it removes one year from age. Math isnt that complicated that you think
__________________
Jhob94 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-10-2013 , 10:57   Re: [Snippet] User Age
Reply With Quote #8

Please use date() instead of strings.
__________________
Black Rose is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:11.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode