PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < engine >
#include < hamsandwich >
#pragma semicolon 1
#define PLUGIN ""
#define VERSION "0.0.1"
const Float:CELL_RADIUS = 200.0;
new Trie:g_CellManagers;
new g_Buttons[10];
public plugin_init()
{
register_plugin( PLUGIN, VERSION, "ConnorMcLeod" );
register_clcmd("say !open", "ClCmd_OpenCells", ADMIN_CFG);
setup_buttons();
}
public plugin_precache()
{
g_CellManagers = TrieCreate();
}
public pfn_keyvalue( ent )
{
static szClass[32], szKey[32], szValue[32];
copy_keyvalue(szClass, charsmax(szClass), szKey, charsmax(szKey), szValue, charsmax(szValue));
if( equal(szClass, "multi_manager") )
{
TrieSetCell(g_CellManagers, szKey, ent);
}
}
public ClCmd_OpenCells(id, lvl, cid)
{
if( cmd_access(id, lvl, cid, 1) )
{
for(new i; i < sizeof(g_Buttons); i++)
{
if(g_Buttons[i])
{
ExecuteHamB(Ham_Use, g_Buttons[i], 0, 0, 1, 1.0);
entity_set_float(g_Buttons[i], EV_FL_frame, 0.0);
}
}
}
return PLUGIN_HANDLED;
}
setup_buttons()
{
new ent[3];
new info[32];
new pos;
new doors[50];
new num;
while((pos <= sizeof(g_Buttons)) && (ent[0] = find_ent_by_class(ent[0], "info_player_deathmatch")))
{
num = find_sphere_class(ent[0], "func_door", CELL_RADIUS, doors, sizeof(doors));
for(--num; num>=0; num--)
{
ent[1] = doors[num];
entity_get_string(ent[1], EV_SZ_targetname, info, charsmax(info));
if(!info[0])
{
continue;
}
if(TrieKeyExists(g_CellManagers, info))
{
TrieGetCell(g_CellManagers, info, ent[2]);
}
else
{
ent[2] = find_ent_by_target(0, info);
}
if(is_valid_ent(ent[2]) && (in_array(ent[2], g_Buttons, sizeof(g_Buttons)) < 0))
{
g_Buttons[pos] = ent[2];
pos++;
break;
}
}
}
TrieDestroy(g_CellManagers);
}
in_array(needle, data[], size)
{
for(new i = 0; i < size; i++)
{
if(data[i] == needle)
return i;
}
return -1;
}