I had that in my mind too, but it is easier to create a new buyzone for only the time it is needed I think.
This is where I got so far, I'm sure there are some mistakes but it works yet
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
public plugin_init()
{
register_plugin( "Shared Buy Zones", "0.2", "RaZ_HU" );
}
public plugin_natives()
{
register_native("create_fake_buyzone", "native_create_fake_buyzone");
}
public plugin_cfg()
{
// Set every buyzone usable for both teams
new iBuyZone = -1;
if( fm_find_ent_by_class( iBuyZone, "func_buyzone" ) )
{
while( ( iBuyZone = fm_find_ent_by_class( iBuyZone, "func_buyzone" ) ) )
{
set_pev( iBuyZone, pev_team, 0 );
}
}
}
/*
* Creates a fake buyzone around the player.
* If timer is defined then remove buyzone after that in seconds.
* native create_fake_buyzone(iEnt, iTeam = 0, Float:fTimeleft = 0.0);
*/
public native_create_fake_buyzone(plugin_id, params)
{
new iEnt = get_param(1);
// Stop if entity doesn't exist
if( !pev_valid( iEnt ) )
return PLUGIN_HANDLED;
new iTeam = get_param(2);
new Float:fTimeleft = get_param_f(3);
new Float:iOrigin[3];
// Get the origin of the entity (player) where we want to create a buyzone
fm_get_brush_entity_origin( iEnt, iOrigin );
new iZone = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "func_buyzone" ) );
if ( iZone )
{
dllfunc( DLLFunc_Spawn, iZone );
set_pev( iZone, pev_team, iTeam );
engfunc( EngFunc_SetSize, iZone, Float:{-96.0, -96.0, -48.0}, Float:{96.0, 96.0, 48.0} );
engfunc( EngFunc_SetOrigin, iZone, iOrigin );
// To make sure it triggers
dllfunc( DLLFunc_Touch, iEnt, iZone );
}
// Timer option, if not supplied then it will remain until mapchange
if( params == 3 )
{
set_task( fTimeleft, "cancelBuy", iZone );
}
return PLUGIN_CONTINUE;
}
public cancelBuy( iEnt )
{
engfunc( EngFunc_RemoveEntity, iEnt );
}
The usage is this simple (in the RTD plugin in my example where players spawn at next round):
PHP Code:
create_fake_buyzone(id, 0, get_cvar_float("mp_buytime") );
Map filtering (aim, fy, scout etc.) is done in the RTD plugin too, but I wouldn't put that in this plugin for no reason.