Raised This Month: $ Target: $400
 0% 

Nvault Ammo bank!!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EXaNoVA
New Member
Join Date: Jul 2011
Old 07-09-2011 , 13:37   Nvault Ammo bank!!
Reply With Quote #1

Hey Guys!!

I'm beginner!
This is my first public plugin!!
This plugin save your ammo automaticaly, if you are logged in.

Commands:
say /login
say /password
say /send

I 'm using this plugin on our zombie server, and there is working fine.
If somebody find bug, pm me.

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

new g_saveg_ammo[33], g_logged_in[33], g_pw[33][64], cvar_max

public plugin_init()
{
    
register_plugin("[ZP] Nvault Bank with Password""1.1""EXaNoVA")

    
register_event("DeathMsg","event_deathmsg","a")
    
register_forward(FM_PlayerPreThink"fw_PlayerPreThink")
    
    
cvar_max register_cvar("nvault_max_ammo_save""2000")
    
    
register_clcmd("say ""say_hook")
    
register_dictionary("nvault_bank.txt")

    
g_save nvault_open("bank_save")
}
public 
plugin_end()
{    
    static 
maxplayers

    
if(!maxplayers)
        
maxplayers get_maxplayers()
    
    for(new 
i=1maxplayersi++)
    {
        if(
is_user_connected(i))
        {
            
filter(i)
        }
    }
}
public 
zp_user_infected_post(idinfector)
{
    
filter(infector)
    
filter(id)
}
public 
zp_extra_item_selected(iditemid)
{
    
filter(id)
}
public 
event_deathmsg()
{
    new 
killer read_data(1)
    new 
victim read_data(2)

    if (!
killer && !victim)
        return 
PLUGIN_CONTINUE
        
    filter
(killer)
    
filter(victim)

    return 
PLUGIN_CONTINUE
}
public 
say_hook(id)
{
    new 
text[100], command[64], password[32], num[30], name[50], vaultkey[64]
    
read_args(text99)
    
remove_quotes(text)
    
    
command[0] = '^0'
    
password[0] = '^0'
    
parse(textcommand63,  password31num29)
    
    
get_user_name(idname49)
    
    
format(vaultkey63"%s-/"name)
    
    if(
equal(command"/login"6))
    {
        new 
vaultdata[256], ammo[32], pw[64]
            
        
nvault_get(g_savevaultkeyvaultdata255)
        
replace_all(vaultdata255"#""")
    
        
parse(vaultdataammo31pw63)
        if(
g_logged_in[id] == 0)
        {
            if(!
pw[0] && !pw[1] && !pw[2])
            {
                
client_print(idprint_chat"%L"LANG_PLAYER"NO_PW1")
                
client_print(idprint_chat"%L"LANG_PLAYER"NO_PW2")
                return 
PLUGIN_HANDLED
            
}
            else if(
equal(passwordpw))
            {
                
g_ammo[id] = str_to_num(ammo)+zp_get_user_ammo_packs(id)
                
g_pw[id] = pw
                g_logged_in
[id] = 1
    
                zp_set_user_ammo_packs
(idg_ammo[id])
                
client_print(idprint_chat"%L",LANG_PLAYER"YOUR_AMMO",  g_ammo[id])
                
client_print(idprint_chat"%L"LANG_PLAYER"LOGIN_SUCCES")
            }
            else
            {
                
client_print(idprint_chat"%L"LANG_PLAYER"WRONG_PW")
            }
        }
        else
        {
            
client_print(idprint_chat"%L"LANG_PLAYER"ALREADY")
        }
        return 
PLUGIN_HANDLED
    
}
    else if(
equal(command"/password"9))
    {
        new 
vaultdata[256], ammo[32], pw[64]    
        
        
nvault_get(g_savevaultkeyvaultdata255)
        
replace_all(vaultdata255"#""")
        
        
parse(vaultdataammo31pw63)
        
g_pw[id] = password
        
if(!pw[0] && !pw[1] && !pw[2])
        {
            
format(vaultdata255"%i# %s#"g_ammo[id], g_pw[id])
            
nvault_set(g_savevaultkeyvaultdata)
            
client_print(idprint_chat"%L",LANG_PLAYER"PW_CREATED1"password)
            
client_print(idprint_chat"%L",LANG_PLAYER"PW_CREATED2"password)
        }
        else if(
g_logged_in[id] == 1)
        {
            if(!
password[0] && !password[1] && !password[2])
            {
                
client_print(idprint_chat"%L"LANG_PLAYER"PW_ERROR")
            }
            else
            {
                
format(vaultdata255"%i# %s#"g_ammo[id], password)
                
nvault_set(g_savevaultkeyvaultdata)
                
client_print(idprint_chat"%L"LANG_PLAYER"PW_CHANGED"password)
            }
        }
        else
        {
            
client_print(idprint_chat"%L"LANG_PLAYER"NOT_LOGGED")
        }
        return 
PLUGIN_HANDLED
    
}
    else if(
equal(command"/send"))
    {
        new 
ammo str_to_num(num)
        new 
receiver cmd_target(idpassword7);
        if(!
receiver)
        {
            
client_print(idprint_chat"%L"LANG_PLAYER"NO_PLAYER")
        }
        else if(
zp_get_user_ammo_packs(id) < ammo)
        {
            
client_print(idprint_chat"%L"LANG_PLAYER"NO_ENOUGH")
        }
        else
        {
            new 
rec[32]
            
get_user_name(receiverrec31)
            
zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) - ammo)
            
zp_set_user_ammo_packs(receiverzp_get_user_ammo_packs(receiver) + ammo)
            
client_print(idprint_chat"%L"LANG_PLAYER"GAVE_AMMO"rec)
            
client_print(receiverprint_chat"%L"LANG_PLAYER"BECAME_AMMO"name)
        }
    }
    return 
PLUGIN_HANDLED
}
public 
fw_PlayerPreThink(id)
{
    
g_ammo[id] = zp_get_user_ammo_packs(id)

    return 
FMRES_IGNORED
}
public 
client_disconnect(id)
{
    
filter(id)
    
g_logged_in[id] = 0
    g_ammo
[id] = 0
}
public 
client_connect(id)
{
    
g_logged_in[id] = 0
}
public 
filter(id)
{
    if(
g_logged_in[id])
    {
        
save_ammo(id)
    }
    else
        return
}
public 
save_ammo(id)
{
    new 
vaultkey[64], vaultdata[256], name[33]
    
get_user_name(id,name,32)
            
    
format(vaultkey63"%s-/"name)
    if(
g_ammo[id] >= get_pcvar_num(cvar_max))
    {
        
format(vaultdata255"%d# %s#"get_pcvar_num(cvar_max), g_pw[id])
        
client_print(idprint_chat"%L"LANG_PLAYER"REACHED"get_pcvar_num(cvar_max))
    }
    else
    {
        
format(vaultdata255"%i# %s#"g_ammo[id], g_pw[id])
    }
    
nvault_set(g_savevaultkeyvaultdata)
    return 
PLUGIN_CONTINUE

Sorry for my bad english. I used translator.
Attached Files
File Type: sma Get Plugin or Get Source (zp_nvault_bank.sma - 827 views - 4.9 KB)
File Type: txt nvault_bank.txt (1.4 KB, 320 views)

Last edited by EXaNoVA; 07-19-2011 at 08:23.
EXaNoVA is offline
sound010
Senior Member
Join Date: Mar 2011
Old 07-09-2011 , 13:40   Re: Nvault Ammo bank!!
Reply With Quote #2

Hey!!

This is very nice Work, and good job

By No Sound^^
__________________
sound010 is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-09-2011 , 13:45   Re: Nvault Ammo bank!!
Reply With Quote #3

After a quick glimpse i found these things:
1-
Code:
public plugin_end() {     for(new i=0; i < get_maxplayers(); i++)     {         if(is_user_connected(i))         {             filter(i)         }     } }
->
Code:
public plugin_end() {     static maxplayers     new i     if ( !maxplayers ) maxplayers = get_maxplayers()     for(i=1; i < maxplayers; i++)     {         if(is_user_connected(i))         {             filter(i)         }     } }
Since you there is no need to call it for 32 players when you only need it once.

2-
Instead of using PlayerPrethink you should use a set_task (with flag "b") which is called every 5 seconds and then update the ammo packs since prethink is called upto 60 times per second and there is no need to check every so often.
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 07-19-2011 , 08:59   Re: Nvault Ammo bank!!
Reply With Quote #4

abdul-rehman!

Plugin end is only called once in the whole plugin, why cache maxplayers into a static variable?
Will the 2. parameter of the for loop be executed every time to check if the conditions are met?

If so, I would suggest this:
Code:
public plugin_end(){
    new i, maxplayers = get_maxplayers();
    for(i=1; i < maxplayers; i++){
        if(is_user_connected(i)){
             filter(i)
        }
    }
}
Lulu the hero is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-19-2011 , 11:09   Re: Nvault Ammo bank!!
Reply With Quote #5

Quote:
Originally Posted by Lulu the hero View Post
abdul-rehman!

Plugin end is only called once in the whole plugin, why cache maxplayers into a static variable?
Will the 2. parameter of the for loop be executed every time to check if the conditions are met?

If so, I would suggest this:
Code:
public plugin_end(){
    new i, maxplayers = get_maxplayers();
    for(i=1; i < maxplayers; i++){
        if(is_user_connected(i)){
             filter(i)
        }
    }
}
Oh yeah, Thnx for correcting me
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
olari9
Senior Member
Join Date: May 2009
Old 07-19-2011 , 18:09   Re: Nvault Ammo bank!!
Reply With Quote #6

Nice plugin! It is saving on name right?
__________________
olari9 is offline
JIoJI
Junior Member
Join Date: Dec 2010
Old 07-20-2011 , 09:34   Re: Nvault Ammo bank!!
Reply With Quote #7

This bank blocked all my "/..." commands, for example "/knife"
P.S. sorry for my bad eng
JIoJI is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 07-20-2011 , 11:48   Re: Nvault Ammo bank!!
Reply With Quote #8

Version 1.11 - Updated the player_prethink stuff and updated the say_hook part.
Attached Files
File Type: sma Get Plugin or Get Source (zp_nvault_bank.sma - 634 views - 5.9 KB)
Lulu the hero is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 07-20-2011 , 12:15   Re: Nvault Ammo bank!!
Reply With Quote #9

Version 1.12 without get_maxplayers, though I think this is slower slightly. Using get_players instead of going through all players at plugin end. Also this solves a hidden bug:
PHP Code:
public plugin_end()
{
    new 
players[32], playernum;
    
get_players(playersplayernum);
    
    for(new 
i=0playernumi++)
    {
        
filter(players[i]);
    }

Previous code returned in the middle of the loop if there was no connected player in a slot.
Also corrected the set_task mistypeing in previous version.
Attached Files
File Type: sma Get Plugin or Get Source (zp_nvault_bank.sma - 652 views - 5.8 KB)

Last edited by Lulu the hero; 07-20-2011 at 12:17.
Lulu the hero is offline
JIoJI
Junior Member
Join Date: Dec 2010
Old 07-20-2011 , 12:45   Re: Nvault Ammo bank!!
Reply With Quote #10

//AMXXPC compile.exe
// by the AMX Mod X Dev Team


//// zp_nvault_bank.sma
// D:\scripting\zp_nvault_bank.sma(33) : error 035: argument type mismatch (argu
ment 1)
// D:\scripting\zp_nvault_bank.sma(196) : error 017: undefined symbol "id"
// D:\scripting\zp_nvault_bank.sma(196) : warning 215: expression has no effect
// D:\scripting\zp_nvault_bank.sma(197) : error 017: undefined symbol "id"
// D:\scripting\zp_nvault_bank.sma(197) : error 017: undefined symbol "id"
// D:\scripting\zp_nvault_bank.sma(197) : error 088: number of arguments does no
t match definition
// D:\scripting\zp_nvault_bank.sma(197) : fatal error 107: too many error messag
es on one line
//
// Compilation aborted.
// 6 Errors.
// Could not locate output file D:\scripting\compiled\zp_nvault_bank.amx (compil
e failed).
//
// Compilation Time: 0,19 sec
// ----------------------------------------

Press enter to exit ...
JIoJI 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 12:55.


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