#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

/* Credits to Weed @ got.Juked for an easy way to fix the buttons */

#define PLUGIN "some1s_jailbreak mapfix"
#define VERSION "1.2"
#define AUTHOR "Jon"

new Trie:gTrieWallModels, gRegisterIndex

public plugin_precache()
{
	new Map[ 32 ]
	get_mapname( Map, 31 )

	if( !equali( Map, "some1s_jailbreak" ) )
		return

	new const WallModels[ ][ ] =
	{
		"*106", "*156",
		"*157", "*158", 
		"*159", "*160", 
		"*161", "*162",
		"*163", "*164", 
		"*165", "*166", 
		"*167"
	}
	
	gTrieWallModels = TrieCreate( )
	
	for( new i; i < sizeof WallModels; i++ )
		TrieSetCell( gTrieWallModels, WallModels[ i ], i )	
	
	gRegisterIndex = register_forward( FM_Spawn, "Spawn" )
	
	RegisterHam( Ham_Spawn, "func_button", "ButtonSpawn" )
}

public plugin_init()
{
	register_plugin( PLUGIN, VERSION, AUTHOR )
	register_cvar( PLUGIN, VERSION, FCVAR_SPONLY | FCVAR_SERVER )
	
	unregister_forward( FM_Spawn, gRegisterIndex )
	
	TrieDestroy( gTrieWallModels )
}

public Spawn( Ent )
{
	if( !pev_valid( Ent ) )
		return FMRES_IGNORED
	
	new Model[ 5 ]
	pev( Ent, pev_model, Model, 4 )
		
	if( TrieKeyExists( gTrieWallModels, Model ) )
	{
		engfunc( EngFunc_RemoveEntity, Ent )
			
		return FMRES_SUPERCEDE
	}
	
	return FMRES_IGNORED
}

public ButtonSpawn( Ent )
{
	new Target[ 32 ]
	pev( Ent, pev_targetname, Target, 31 )
	
	if( equal( Target, "cellcontrol" ) )
		set_pev( Ent, pev_target, "cells" )
	
	else if( equal( Target, "armory1" ) || equal( Target, "armory2" ) )
		set_pev( Ent, pev_target, "arm" )
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1044\\ f0\\ fs16 \n\\ par }
*/
