Raised This Month: $ Target: $400
 0% 

Add limit item ZP 5.0.8 | problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zollymaN
Junior Member
Join Date: Aug 2021
Location: Romania
Old 03-01-2022 , 12:08   Add limit item ZP 5.0.8 | problem
Reply With Quote #1

Hi, I have a problem I tried to limit this extra item so you can only buy it twice a round... the number of purchases of the item is not reset .. even if I buy this round 2 gas masks, I restart the round and it shows me that I have already bought 2/2 gas masks .. what did I do wrong?

Code:
#include < amxmodx >
#include < hamsandwich >
#include < engine >
#include < zp50_core >
#include < zp50_items >
	
#define _MarkPlayerHasMask(%0)   _bitPlayerHasMask |= (1 << (%0 & 31))
#define _ClearPlayerWithMask(%0)  _bitPlayerHasMask &= ~(1 << (%0 & 31))
#define _PlayerHasMask(%0)       _bitPlayerHasMask & (1 << (%0 & 31))
	
#define _PLUGIN   "[ZP50] Extra item: Gas Mask"
#define _VERSION             "3.0"
#define _AUTHOR           "H.RED.ZONE"

#define EV_INT_nadetype     EV_INT_flTimeStepSound
#define NADETYPE_INFECTION  1111 

new _ItemID

new g_Limit[33]

new cvar_Mask_limit

new _bitPlayerHasMask

new _gMaxPlayers, _gIcon, _gMsgSayText

public plugin_init() {
	register_plugin( _PLUGIN, _VERSION, _AUTHOR )
	
	RegisterHam( Ham_Spawn, "player", "_FW_PlayerSpawn", 1 )
	RegisterHam( Ham_Killed, "player", "_FW_PlayerKilled" )

	cvar_Mask_limit = register_cvar("zp_Mask_limit", "2")
		
	_ItemID = zp_items_register( "\r|Item| \wGasMask", 30 )
	
	_gMaxPlayers = get_maxplayers( )
	_gIcon = get_user_msgid( "StatusIcon" ) 
	_gMsgSayText = get_user_msgid( "SayText" )
}

public plugin_precache() {
	RegisterHam( Ham_Think, "grenade", "_FW_ThinkGrenade", 1 ) 
}

public zp_fw_items_select_post( plr, itemid, ignorecost ) {
        
	if( itemid == _ItemID ) 
	{
		_MarkPlayerHasMask( plr )
		Icon_On( plr )
		ProtoChat(plr, "You now have Gas Mask.");
		g_Limit[plr]++
	}
}

public zp_fw_items_select_pre( plr, itemid ) 
{
	
	if( itemid == _ItemID ) 
	{
		
		if( zp_core_is_zombie(plr))
			return ZP_ITEM_DONT_SHOW;

		static text[32]
		formatex (text, charsmax(text), "[%d/%d]", g_Limit[plr], get_pcvar_num(cvar_Mask_limit))
		zp_items_menu_text_add(text)

		if (g_Limit[plr] >= get_pcvar_num(cvar_Mask_limit))
			return ZP_ITEM_NOT_AVAILABLE;
		
		return ZP_ITEM_AVAILABLE;
	}
	return ZP_ITEM_AVAILABLE;
}

public zp_round_ended(winteam) 
{   
    _bitPlayerHasMask = 0 
}

public NewRound() 
{   
    for (new plr; plr <= _gMaxPlayers; plr++) 
    {                     
        g_Limit[plr] = 0
    }
}

public _FW_ThinkGrenade( iEnt ) {
	
	if( is_valid_ent(iEnt) ) {
		
		if( entity_get_int(iEnt, EV_INT_nadetype) == NADETYPE_INFECTION ) {
			
			for( new plr = 1; plr <= _gMaxPlayers; plr++ ) {
				
				if( is_user_alive(plr) 
				
				&& _PlayerHasMask(plr) ) {
					
					if( get_entity_distance(iEnt, plr) <= 240 ) {
						
						_ClearPlayerWithMask( plr )
						remove_entity( iEnt )
						Icon_Off( plr )
						
						ProtoChat( plr, "Infect nade is removed, you don't have mask anymore." )
					}
				}
			}
		}
	}
}

public zp_fw_core_infect( plr ) {
	_ClearPlayerWithMask( plr ) 
	Icon_Off( plr )
}

public _FW_PlayerSpawn( plr ) {
	_ClearPlayerWithMask( plr ) 
	Icon_Off( plr )
}

public _FW_PlayerKilled( plr ) {
	_ClearPlayerWithMask( plr ) 
	Icon_Off( plr )
}

public client_disconnect( plr ) {
	Icon_Off( plr )
}

public Icon_On( plr ) {
	message_begin( MSG_ONE_UNRELIABLE, _gIcon, { 0, 0, 0 }, plr );
	write_byte( 1 )
	write_string( "dmg_gas" )
	write_byte( 0 )
	write_byte( 255 )
	write_byte( 0 )
	message_end( )
}

public Icon_Off( plr ) {
	message_begin( MSG_ONE_UNRELIABLE, _gIcon, { 0, 0, 0 }, plr )
	write_byte( 0 )
	write_string( "dmg_gas" )
	write_byte( 0 )
	write_byte( 255 )
	write_byte( 0 )
	message_end( )
}

ProtoChat( plr, const sFormat[], any:... ) {
	
	static i; i = plr ? plr : get_player( )
	
	if ( !i ) {
		return PLUGIN_HANDLED;
	}
	
	new sMessage[ 256 ]
	new len = formatex( sMessage, 255, "^x01[^x04ZP^x01] ")
	
	vformat( sMessage[len], 255-len, sFormat, 3 )
	sMessage[ 192 ] = '^0' 
	
	Make_SayText( plr, i, sMessage )
	
	return PLUGIN_CONTINUE
}

get_player( ) {
	for ( new plr; plr <= _gMaxPlayers; plr++ ) {
		if ( is_user_connected(plr) ) {
			return plr
		}
	}
	return PLUGIN_HANDLED
}

Make_SayText( Receiver, Sender, sMessage[] ) {
	if ( !Sender ) {
		return PLUGIN_HANDLED;
	}
	
	message_begin( Receiver ? MSG_ONE_UNRELIABLE : MSG_ALL, _gMsgSayText, {0,0,0}, Receiver )
	write_byte( Sender )
	write_string( sMessage )
	message_end( )
	
	return PLUGIN_CONTINUE;
}
zollymaN is offline
Software15
Junior Member
Join Date: Feb 2022
Old 03-01-2022 , 12:13   Re: Add limit item ZP 5.0.8 | problem
Reply With Quote #2

Quote:
Originally Posted by zollymaN View Post
Hi, I have a problem I tried to limit this extra item so you can only buy it twice a round... the number of purchases of the item is not reset .. even if I buy this round 2 gas masks, I restart the round and it shows me that I have already bought 2/2 gas masks .. what did I do wrong?

Code:
#include < amxmodx >
#include < hamsandwich >
#include < engine >
#include < zp50_core >
#include < zp50_items >
	
#define _MarkPlayerHasMask(%0)   _bitPlayerHasMask |= (1 << (%0 & 31))
#define _ClearPlayerWithMask(%0)  _bitPlayerHasMask &= ~(1 << (%0 & 31))
#define _PlayerHasMask(%0)       _bitPlayerHasMask & (1 << (%0 & 31))
	
#define _PLUGIN   "[ZP50] Extra item: Gas Mask"
#define _VERSION             "3.0"
#define _AUTHOR           "H.RED.ZONE"

#define EV_INT_nadetype     EV_INT_flTimeStepSound
#define NADETYPE_INFECTION  1111 

new _ItemID

new g_Limit[33]

new cvar_Mask_limit

new _bitPlayerHasMask

new _gMaxPlayers, _gIcon, _gMsgSayText

public plugin_init() {
	register_plugin( _PLUGIN, _VERSION, _AUTHOR )
	
	RegisterHam( Ham_Spawn, "player", "_FW_PlayerSpawn", 1 )
	RegisterHam( Ham_Killed, "player", "_FW_PlayerKilled" )

	cvar_Mask_limit = register_cvar("zp_Mask_limit", "2")
		
	_ItemID = zp_items_register( "\r|Item| \wGasMask", 30 )
	
	_gMaxPlayers = get_maxplayers( )
	_gIcon = get_user_msgid( "StatusIcon" ) 
	_gMsgSayText = get_user_msgid( "SayText" )
}

public plugin_precache() {
	RegisterHam( Ham_Think, "grenade", "_FW_ThinkGrenade", 1 ) 
}

public zp_fw_items_select_post( plr, itemid, ignorecost ) {
        
	if( itemid == _ItemID ) 
	{
		_MarkPlayerHasMask( plr )
		Icon_On( plr )
		ProtoChat(plr, "You now have Gas Mask.");
		g_Limit[plr]++
	}
}

public zp_fw_items_select_pre( plr, itemid ) 
{
	
	if( itemid == _ItemID ) 
	{
		
		if( zp_core_is_zombie(plr))
			return ZP_ITEM_DONT_SHOW;

		static text[32]
		formatex (text, charsmax(text), "[%d/%d]", g_Limit[plr], get_pcvar_num(cvar_Mask_limit))
		zp_items_menu_text_add(text)

		if (g_Limit[plr] >= get_pcvar_num(cvar_Mask_limit))
			return ZP_ITEM_NOT_AVAILABLE;
		
		return ZP_ITEM_AVAILABLE;
	}
	return ZP_ITEM_AVAILABLE;
}

public zp_round_ended(winteam) 
{   
    _bitPlayerHasMask = 0 
}

public NewRound() 
{   
    for (new plr; plr <= _gMaxPlayers; plr++) 
    {                     
        g_Limit[plr] = 0
    }
}

public _FW_ThinkGrenade( iEnt ) {
	
	if( is_valid_ent(iEnt) ) {
		
		if( entity_get_int(iEnt, EV_INT_nadetype) == NADETYPE_INFECTION ) {
			
			for( new plr = 1; plr <= _gMaxPlayers; plr++ ) {
				
				if( is_user_alive(plr) 
				
				&& _PlayerHasMask(plr) ) {
					
					if( get_entity_distance(iEnt, plr) <= 240 ) {
						
						_ClearPlayerWithMask( plr )
						remove_entity( iEnt )
						Icon_Off( plr )
						
						ProtoChat( plr, "Infect nade is removed, you don't have mask anymore." )
					}
				}
			}
		}
	}
}

public zp_fw_core_infect( plr ) {
	_ClearPlayerWithMask( plr ) 
	Icon_Off( plr )
}

public _FW_PlayerSpawn( plr ) {
	_ClearPlayerWithMask( plr ) 
	Icon_Off( plr )
}

public _FW_PlayerKilled( plr ) {
	_ClearPlayerWithMask( plr ) 
	Icon_Off( plr )
}

public client_disconnect( plr ) {
	Icon_Off( plr )
}

public Icon_On( plr ) {
	message_begin( MSG_ONE_UNRELIABLE, _gIcon, { 0, 0, 0 }, plr );
	write_byte( 1 )
	write_string( "dmg_gas" )
	write_byte( 0 )
	write_byte( 255 )
	write_byte( 0 )
	message_end( )
}

public Icon_Off( plr ) {
	message_begin( MSG_ONE_UNRELIABLE, _gIcon, { 0, 0, 0 }, plr )
	write_byte( 0 )
	write_string( "dmg_gas" )
	write_byte( 0 )
	write_byte( 255 )
	write_byte( 0 )
	message_end( )
}

ProtoChat( plr, const sFormat[], any:... ) {
	
	static i; i = plr ? plr : get_player( )
	
	if ( !i ) {
		return PLUGIN_HANDLED;
	}
	
	new sMessage[ 256 ]
	new len = formatex( sMessage, 255, "^x01[^x04ZP^x01] ")
	
	vformat( sMessage[len], 255-len, sFormat, 3 )
	sMessage[ 192 ] = '^0' 
	
	Make_SayText( plr, i, sMessage )
	
	return PLUGIN_CONTINUE
}

get_player( ) {
	for ( new plr; plr <= _gMaxPlayers; plr++ ) {
		if ( is_user_connected(plr) ) {
			return plr
		}
	}
	return PLUGIN_HANDLED
}

Make_SayText( Receiver, Sender, sMessage[] ) {
	if ( !Sender ) {
		return PLUGIN_HANDLED;
	}
	
	message_begin( Receiver ? MSG_ONE_UNRELIABLE : MSG_ALL, _gMsgSayText, {0,0,0}, Receiver )
	write_byte( Sender )
	write_string( sMessage )
	message_end( )
	
	return PLUGIN_CONTINUE;
}
You had forgot to register new round in plugin init
Software15 is offline
zollymaN
Junior Member
Join Date: Aug 2021
Location: Romania
Old 03-01-2022 , 12:19   Re: Add limit item ZP 5.0.8 | problem
Reply With Quote #3

*Facepalm*
Code:
register_event("HLTV", "NewRound", "a", "1=0", "2=0")
done TY
zollymaN 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 19:06.


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