PHP Code:
/* Copyright © 2008, ConnorMcLeod
Kz Buttons is free software;
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Kz Buttons; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#define PLUGIN "Kz Buttons"
#define AUTHOR "ConnorMcLeod"
#define VERSION "0.0.1"
#define MAX_PLAYERS 32
#define START 0
#define STOP 1
#define BUTTONS 2
#define MIN_DELAY 0.5
new g_iButtons[BUTTONS]
new Float:g_flLastUse[MAX_PLAYERS+1][BUTTONS]
new g_iMaxPlayers
new g_iButtonForwardId
new g_iReturn
find_buttons()
{
new iTemp,
iEnt = engfunc(EngFunc_FindEntityByString, 0, "classname", "func_button"),
szTarget[32],
i
new counter_start[][] = {"counter_start", "clockstartbutton", "firsttimerelay", "multi_start", "counter_start_button"}
new counter_stop[][] = {"counter_off", "clockstop", "clockstopbutton", "multi_stop", "stop_counter"}
while( iEnt && (!g_iButtons[START] || !g_iButtons[STOP]))
{
iTemp = engfunc(EngFunc_FindEntityByString, iEnt, "classname", "func_button")
pev(iEnt, pev_target, szTarget, 31)
if(!g_iButtons[START])
{
for( i=0 ; i<sizeof(counter_start) ; i++ )
{
if( !g_iButtons[START] && equal(szTarget, counter_start[i] ) )
{
g_iButtons[START] = iEnt
}
}
}
if(!g_iButtons[STOP])
{
for( i=0 ; i<sizeof(counter_stop) ; i++ )
{
if( !g_iButtons[STOP] && equal(szTarget, counter_stop[i] ) )
{
g_iButtons[STOP] = iEnt
}
}
}
iEnt = iTemp
}
if( g_iButtons[START] && g_iButtons[STOP] )
{
return 1
}
iEnt = engfunc(EngFunc_FindEntityByString, 0, "classname", "func_button")
while( iEnt && (!g_iButtons[START] || !g_iButtons[STOP]))
{
iTemp = engfunc(EngFunc_FindEntityByString, iEnt, "classname", "func_button")
pev(iEnt, pev_targetname, szTarget, 31)
if(!g_iButtons[START])
{
for( i=0 ; i<sizeof(counter_start) ; i++ )
{
if( !g_iButtons[START] && equal(szTarget, counter_start[i] ) )
{
g_iButtons[START] = iEnt
}
}
}
if(!g_iButtons[STOP])
{
for( i=0 ; i<sizeof(counter_stop) ; i++ )
{
if( !g_iButtons[STOP] && equal(szTarget, counter_stop[i] ) )
{
g_iButtons[STOP] = iEnt
}
}
}
iEnt = iTemp
}
if( g_iButtons[START] && g_iButtons[STOP] )
{
return 2
}
return 0
}
public plugin_init()
{
switch( find_buttons() )
{
case 1:
{
register_plugin( PLUGIN, VERSION, AUTHOR )
RegisterHam(Ham_Use, "func_button", "Ham_Use_button")
}
case 2:
{
register_plugin( PLUGIN, VERSION, AUTHOR )
RegisterHam(Ham_Touch, "func_button", "Ham_Touch_button")
}
default:
{
register_plugin( PLUGIN, "No Buttons Founded", AUTHOR )
pause("ad")
return
}
}
g_iButtonForwardId = CreateMultiForward("client_use_button", ET_IGNORE, FP_CELL, FP_CELL)
g_iMaxPlayers = get_maxplayers()
}
public plugin_natives()
{
register_library("kz_buttons")
}
public client_putinserver(id)
{
g_flLastUse[id][START] = 0.0
g_flLastUse[id][STOP] = 0.0
}
public Ham_Use_button(iEnt, id, idactivator, use_type, Float:flValue)
{
if( !(1 <= id <= g_iMaxPlayers) ||
use_type != 2 ||
flValue != 1.0 )
{
return HAM_IGNORED
}
static iButton
if( iEnt == g_iButtons[START] )
{
iButton = START
}
else if( iEnt == g_iButtons[STOP] )
{
iButton = STOP
}
else
{
return HAM_IGNORED
}
static Float:flTime
global_get(glb_time, flTime)
if( g_flLastUse[id][iButton] + MIN_DELAY > flTime )
{
return HAM_IGNORED
}
g_flLastUse[id][iButton] = flTime
ExecuteForward(g_iButtonForwardId, g_iReturn, id, iButton)
return HAM_IGNORED
}
public Ham_Touch_button(iEnt, id)
{
if(!(1 <= id <= g_iMaxPlayers))
return HAM_IGNORED
static iButton
if( iEnt == g_iButtons[START] )
{
iButton = START
}
else if( iEnt == g_iButtons[STOP] )
{
iButton = STOP
}
else
{
return HAM_IGNORED
}
static Float:flTime
global_get(glb_time, flTime)
if( g_flLastUse[id][iButton] + MIN_DELAY > flTime )
{
return HAM_IGNORED
}
g_flLastUse[id][iButton] = flTime
ExecuteForward(g_iButtonForwardId, g_iReturn, id, iButton)
return HAM_IGNORED
}