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

[ZP] AP Limit


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
strangeguy
Senior Member
Join Date: Mar 2019
Old 07-27-2021 , 12:11   [ZP] AP Limit
Reply With Quote #1

Hello!
Someone can change me that, the limit will work only when it's new map? Now it's work like, when you will reach 300 AP (normal player), 500 AP (VIP), you cannot reach more.

Code:
#include <amxmodx>
#include <zombieplague>
#include <fvault>

#define PLUGIN "[ZP] Save Ammo New v2"
#define VERSION "1.3"
#define AUTHOR "Shaxu"

#define AUTOSAVE_INTERVAL 30.0
#define ACCESS_FLAG ADMIN_LEVEL_H
#define MAX_SAVE_ALL 300
#define MAX_SAVE_VIP 500

#define flag_get(%1,%2) (%1 & (1 << (%2 & 31)))
#define flag_get_boolean(%1,%2) (flag_get(%1,%2) ? true : false)
#define flag_set(%1,%2) %1 |= (1 << (%2 & 31))
#define flag_unset(%1,%2) %1 &= ~(1 << (%2 & 31))

new const g_vault_name[] = "ammobank"
new g_LoadSuccess, g_IsConnected, g_MaxPlayers
new g_name[33][33]
new g_ammo[33]
new cvar_block_start_ammo, cvar_load_ammo_packs
new SayText

#define is_user_valid(%1) (1 <= %1 <= g_MaxPlayers)

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_logevent("logevent_round_end", 2, "1=Round_End")
	cvar_block_start_ammo = register_cvar("zp_bank_block_start", "1")
	cvar_load_ammo_packs = register_cvar("zp_bank_auto_save", "1")
	g_MaxPlayers = get_maxplayers()
	SayText = get_user_msgid("SayText")
}

public plugin_cfg()
{
	set_task(AUTOSAVE_INTERVAL, "TaskAutoSave",_,_,_,"b")
}

public client_putinserver(id)
{
	if( is_user_connected ( id ) )
	set_task( 6.0, "ShowMessage", id )
	
	if(is_user_hltv(id) || is_user_bot(id)) return;
	
	if(get_pcvar_num(cvar_block_start_ammo))
	{
		zp_set_user_ammo_packs(id, 0)
	}

	if(get_pcvar_num(cvar_load_ammo_packs))
	{
		AutoLoad(id)
	}
}

public client_disconnect(id)
{
	if(flag_get(g_LoadSuccess,id))
	{
		SaveAmmo(id)
		flag_unset(g_LoadSuccess,id)
	}
	
	flag_unset(g_IsConnected,id)
}

public logevent_round_end() TaskAutoSave();

public TaskAutoSave()
{
	for(new id = 1; id <= g_MaxPlayers; id++)
	{
		if(is_user_valid(id) && flag_get(g_IsConnected,id) && flag_get(g_LoadSuccess,id)) SaveAmmo(id);
	}
}

LoadAmmo(id)
{
	new data[16]
	if(fvault_get_data(g_vault_name, g_name[id], data, 15))
	{
		g_ammo[id] = str_to_num(data)
		zp_set_user_ammo_packs(id, g_ammo[id])
	}
	
	flag_set(g_LoadSuccess,id)
}

SaveAmmo(id)
{
	if(!flag_get(g_LoadSuccess,id))
	{
		server_print("[AutoSaveAmmoPack] User [%i] failed to save AP because it not loaded yet!", id)
		return
	}
	
	g_ammo[id] = zp_get_user_ammo_packs(id)
	if(get_user_flags(id) & ACCESS_FLAG)
	{
		if(g_ammo[id] >= MAX_SAVE_VIP)
		{
			g_ammo[id] = MAX_SAVE_VIP
		}
	}
	else 
	if(g_ammo[id] >= MAX_SAVE_ALL)
	{
		g_ammo[id] = MAX_SAVE_ALL
	}
	
	new data[16]
	num_to_str(g_ammo[id], data, 15)
	fvault_set_data(g_vault_name, g_name[id], data)
}

public AutoLoad(id)
{
	if(is_user_hltv(id) || is_user_bot(id)) return;
	
	flag_set(g_IsConnected,id)
	get_user_name(id, g_name[id], 32)
	LoadAmmo(id)
}

public ShowMessage(id) 
{
	g_ammo[id] = zp_get_user_ammo_packs(id)
	ChatColor(id, "!g[ZP]!y Twoje AP - !g%d !y| Limit Zwykly - !g300 AP !y| Limit VIP - !g500 AP", g_ammo[id])
}

stock ChatColor(const id, const input[], any:...)
{
    new count = 1, players[32]
    static msg[191]
    vformat(msg, 190, input, 3)

    replace_all(msg, 190, "!g", "^4") // Green Color
    replace_all(msg, 190, "!y", "^1") // Default Color
    replace_all(msg, 190, "!t", "^3") // Team Color
    replace_all(msg, 190, "!t2", "^0") // Team2 Color

    if (id) players[0] = id; else get_players(players, count, "ch")
    {
        for (new i = 0; i < count; i++)
        {
            if (is_user_connected(players[i]))
            {
                message_begin(MSG_ONE_UNRELIABLE, SayText, _, players[i])
                write_byte(players[i]);
                write_string(msg);
                message_end();
            }
        }
    }
}
strangeguy is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 07-30-2021 , 00:25   Re: [ZP] AP Limit
Reply With Quote #2

I feel the code is missing since I only see you use zp_set_user_ammo_packs on LoadAP() which only happened when player join the server.
MAX_SAVE_ALL and MAX_SAVE_VIP only save AP to fvault, not set AP to player so it can't prevent player from getting over those cap.

=> Either you set ammo pack in other plugins or this is the missing code
__________________
My plugin:

Last edited by Celena Luna; 07-30-2021 at 00:29.
Celena Luna 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:43.


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