Raised This Month: $32 Target: $400
 8% 

[HELP] Work


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 06-03-2018 , 11:37   [HELP] Work
Reply With Quote #1

I cant under stand how this plugin work and what is the use of nvault. any one plz explain me

PHP Code:
#include <amxmodx>
#include <zombieplague>
#include <nvault>

#define NV_NAME "FREE_AMMO"

#define TAG "[ZP]"

enum player_struct 
{

    
mtime,bool:ftime,key[64]
}

new 
g_playerMAX_PLAYERS ][player_struct];

new 
cvar_save_type,cvar_time
new cvar_ap 500

public plugin_init() {

    
register_plugin("Free Ammo Packs""1.0""|RrebEliii|");
    
    
cvar_save_type register_cvar("free_ammo_save_type","1"); // how to save data 1 by authid, 2 by ip or 3 by name
    
cvar_time register_cvar("free_ammo_minutes","720"); // Time In Minute, 2800minutes=48hours it will be auto calculated
    
    
register_clcmd("say /free""cmd_ap");
    
    
register_clcmd("say_team /free""cmd_ap");
}
        
public 
cmd_ap(id) {

    new 
nv nvault_open(NV_NAME);
    
    if(
nv == INVALID_HANDLE) {
        
        
client_print(id,print_chat,"%s For the moment getting ammo packs system is inactive..",TAG);
        
        return;
    }
    
    new 
txt_min[32],txt_ap[10];
    
    new 
ap get_pcvar_num(cvar_ap),pminutes get_pcvar_num(cvar_time);
    
    
copy(txt_ap,charsmax(txt_ap),(ap==1)?"pack":"packs");
    
    
build_time(pminutes,txt_min,charsmax(txt_min));
    
    if(
g_player[id][ftime]) {
        
        
client_print(id,print_chat,"%s You have just received %d ammo %s, get another in %s !",TAG,ap,txt_ap,txt_min);
        
        
zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) + ap);
        
        
g_player[id][ftime]=false;
        
        
nvault_touch(nv,g_player[id][key],g_player[id][mtime]=get_systime());
        
        return;
    }
    
    new 
user_time=get_systime()-g_player[id][mtime];
    
    new 
diff_min=(user_time<(pminutes*60))?pminutes-(user_time/60):pminutes;
    
    
build_time(diff_min,txt_min,charsmax(txt_min));
    
    if(
user_time>=(pminutes*60)) {
        
        
client_print(id,print_chat,"%s You have just received %d ammo %s since %s passed !",TAG,ap,txt_ap,txt_min);
        
        
zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) + ap);
        
        
nvault_touch(nv,g_player[id][key],g_player[id][mtime]=get_systime());
    }
    
    else
        
        
client_print(id,print_chat,"%s Retry again in %s for getting %d more ammo %s !",TAG,txt_min,ap,txt_ap);
        
    
nvault_close(nv);
}

public 
client_putinserver(id) {
        
    new 
nv,data[32];
    
    
get_auth(id,g_player[id][key],charsmax(g_player[][key]));
    
    
g_player[id][mtime]=get_systime();
    
    
g_player[id][ftime]=false;
    
    
formatex(data,charsmax(data),"%d",g_player[id][mtime]);
    
    if((
nv=nvault_open(NV_NAME))==INVALID_HANDLE)
        return;
    
    if(!
nvault_lookup(nv,g_player[id][key],data,charsmax(data),g_player[id][mtime])) {
        
        
nvault_set(nv,g_player[id][key],data);
        
        
g_player[id][ftime]=true;
    }
    
    
nvault_close(nv);
}    

public 
client_disconnected(id) {
    
    
g_player[id][mtime]=0;
    
    
g_player[id][ftime]=false;
}

stock get_auth(id,data[],len)

    switch(
get_pcvar_num(cvar_save_type)) {
        
        
        case 
1get_user_authid(id,data,len);
        
        case 
2get_user_ip(id,data,len,1);
        
        case 
3get_user_name(id,data,len);
    }

stock build_time(pminutes,data[],len)

    if(
pminutes==1)
        
        
copy(data,len,"1 minute");
        
    else if(
pminutes!=1&&pminutes<60)
        
        
formatex(data,len,"%d minutes",pminutes);
        
    else if(
pminutes==60)
        
        
copy(data,len,"1 hour");
        
    else {
        
        new 
ptime=pminutes/60;
        
        if(
ptime*60==pminutes)
            
            
formatex(data,len,"%d %s",ptime,(ptime==1)?"hour":"hours");
            
        else {
            
            new 
diff=pminutes-ptime*60;
            
            
formatex(data,len,"%d %s and %d %s",ptime,(ptime==1)?"hour":"hours",diff,(diff==1)?"minute":"minutes");
        }
    } 
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 06-03-2018 , 12:11   Re: [HELP] Work
Reply With Quote #2

This uses get_gametime() and experiments with it making a clcmd to execute after X time has passed. Saves player data on a nvault, so client doesn't reconnect to call this clcmd again & transposes of seconds and turns them to hours(if), minutes(if) and what's left on seconds. I've once requested this type'a thingy and Black Rose built a cool stock.
__________________
Relaxing is offline
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 06-03-2018 , 13:06   Re: [HELP] Work
Reply With Quote #3

Can u share that stock..
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 06-03-2018 , 13:07   Re: [HELP] Work
Reply With Quote #4

Can u share that stock
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 06-03-2018 , 16:15   Re: [HELP] Work
Reply With Quote #5

My mistake, Black Rose did something about get_user_time().
ops a daisy
__________________
Relaxing 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 21:08.


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