Code:
#include <amxmodx>
#include <nvault>
#include <fun>
new ghnVault;
new ghpcvarFrequency;
public plugin_init() {
register_plugin("Give M4A1 by command", "1.0", "[ --{-@ ]");
ghnVault = nvault_open("GiveM4A1");
if ( ghnVault == INVALID_HANDLE )
set_fail_state("Couldn't open vault");
register_clcmd("say /gun", "user_clcmd");
ghpcvarFrequency = register_cvar("give_m4a1_frequency", "86400");
}
public plugin_end()
nvault_close(ghnVault);
public user_clcmd(id) {
new AuthID[32];
get_user_authid(id, AuthID, 31);
new curTime = get_systime();
new lastUsed = nvault_get(ghnVault, AuthID);
new giveFreq = get_pcvar_num(ghpcvarFrequency);
new outString[32];
if ( lastUsed + giveFreq > curTime ) {
TimerFormat(1000 * ( giveFreq - ( curTime - lastUsed ) ), outString, charsmax(outString), 2);
client_print(id, print_chat, "You have to wait %s to use this command again!", outString);
return;
}
give_item(id, "weapon_m4a1");
num_to_str(curTime, outString, charsmax(outString));
nvault_set(ghnVault, AuthID, outString);
}
#define TimerDays(%0) ( %0 / 86400000 )
#define TimerHours(%0) ( %0 % 86400000 / 3600000 )
#define TimerMinutes(%0) ( %0 % 3600000 / 60000 )
#define TimerSeconds(%0) ( %0 % 60000 / 1000 )
#define TimerMilliseconds(%0) ( %0 % 1000 )
stock TimerFormat(hTimer, output[], maxlen, mode = 1, bool:full = false) {
new len;
if ( full || TimerDays(hTimer) )
len = formatex(output, maxlen, mode == 1 ? "%02d:" : "%dd ", TimerDays(hTimer));
if ( full || ( len && mode == 1 ) || TimerHours(hTimer) )
len += formatex(output[len], maxlen - len, mode == 1 ? "%02d:" : "%dh ", TimerHours(hTimer));
if ( full || ( len && mode == 1 ) || TimerMinutes(hTimer) )
len += formatex(output[len], maxlen - len, mode == 1 ? "%02d:" : "%dm ", TimerMinutes(hTimer));
if ( full || ( len && mode == 1 ) || TimerSeconds(hTimer) )
len += formatex(output[len], maxlen - len, mode == 1 ? "%02d." : "%ds ", TimerSeconds(hTimer));
if ( full || ! len || mode == 1 || TimerMilliseconds(hTimer) )
len += formatex(output[len], maxlen - len, mode == 1 ? "%03d" : "%dms", TimerMilliseconds(hTimer));
}