#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>
// CUSTOMIZING AREA START
#define MAX_DELAY 180.0
#define MIN_DELAY 1.0
#define EDITED_ENT 293759
// CUSTOMIZING AREA END
#define VERSION "1.3"
#define m_flWait 44
#define m_ls.sUnlockedSound 78
new g_iSprite;
new g_iMsg_Saytext;
new g_iSound[ 33 ];
new g_iEntity[ 33 ];
new g_szConfigFile[ 96 ];
new Trie:g_tSounds;
new const g_szButtons[ ][ ] = {
"func_button",
"func_rot_button",
"button_target"
};
new const g_szSoundsNames[ ][ ] = {
"Nincs",
"Nagy eltrafalas & Bemelegites",
"Hozzaferest adott",
"Gyors Combolock",
"Ero halal bolt 1",
"Ero halal bolt 2",
"Buvar",
"Kicsi eltrafalas",
"Nyito kartya hang",
"Zugas",
"Zugas kikapcsolas",
"", // 11
"", // 12
"Kilincs nyitas",
"Fenyek boszorkany"
};
new const g_szSounds[ ][ ] = {
"common/null.wav",
"buttons/button1.wav",
"buttons/button2.wav",
"buttons/button3.wav",
"buttons/button4.wav",
"buttons/button5.wav",
"buttons/button6.wav",
"buttons/button7.wav",
"buttons/button8.wav",
"buttons/button9.wav",
"buttons/button10.wav",
"",
"",
"buttons/latchunlocked1.wav",
"buttons/lightswitch2.wav"
};
public plugin_init( ) {
register_plugin( "Buttons Delay Editor", VERSION, "xPaw" );
register_cvar( "butt_delay_edit", VERSION, FCVAR_SERVER | FCVAR_SPONLY );
register_clcmd( "amx_delayedit", "CmdOpenMenu", ADMIN_CFG );
register_menucmd( register_menuid( "ButtonsDelayEdit" ), ( MENU_KEY_1 | MENU_KEY_2 | MENU_KEY_3 | MENU_KEY_4 | MENU_KEY_5 | MENU_KEY_9 | MENU_KEY_0 ), "handleMenu" );
g_iMsg_Saytext = get_user_msgid( "SayText" );
IntButtons( );
}
public plugin_precache( ) {
g_iSprite = precache_model( "sprites/flare1.spr" );
g_tSounds = TrieCreate( );
new szI[ 6 ];
for( new i = 0; i < sizeof g_szSounds; i++ ) {
if( !g_szSounds[ i ][ 0 ] )
continue;
precache_sound( g_szSounds[ i ] ); // Some of them could be not precached by map.
num_to_str( i, szI, 5 );
TrieSetString( g_tSounds, g_szSounds[ i ], szI );
}
}
public client_putinserver( id ) {
g_iSound[ id ] = 0;
g_iEntity[ id ] = 0;
}
public plugin_end( ) {
TrieDestroy( g_tSounds );
delete_file( g_szConfigFile );
new bool:bFound, iFile = fopen( g_szConfigFile, "a" );
if( iFile ) {
new szModel[ 5 ], Float:flWait, szSound[ 32 ], iSpawnFlags, iEntity = FM_NULLENT;
fprintf( iFile, "; A gombok kesedelem szerkeszto v%s by xPaw^n; <classname> <model> <delay> <sound> <dontmove> <toggable>^n^n", VERSION );
for( new i; i < sizeof g_szButtons; i++ ) {
iEntity = FM_NULLENT;
while( ( iEntity = find_ent_by_class( iEntity, g_szButtons[ i ] ) ) ) {
if( pev( iEntity, pev_iuser2 ) == EDITED_ENT ) {
iSpawnFlags = pev( iEntity, pev_spawnflags );
flWait = get_pdata_float( iEntity, m_flWait, 4 );
pev( iEntity, pev_model, szModel, 4 );
eng_get_string( get_pdata_int( iEntity, m_ls.sUnlockedSound, 5 ), szSound, 31 );
fprintf( iFile, "^"%s^" ^"%s^" ^"%f^" ^"%s^" ^"%i^" ^"%i^"^n", g_szButtons[ i ], szModel, flWait, szSound,
( iSpawnFlags & SF_BUTTON_DONTMOVE ) ? 1 : 0, ( iSpawnFlags & SF_BUTTON_TOGGLE ) ? 1 : 0 );
if( !bFound ) bFound = true;
}
}
}
fclose( iFile );
if( !bFound )
delete_file( g_szConfigFile );
}
}
public IntButtons( ) {
get_localinfo( "amxx_datadir", g_szConfigFile, charsmax( g_szConfigFile ) );
formatex( g_szConfigFile, charsmax( g_szConfigFile ), "%s/ButtonDelayEdit", g_szConfigFile );
if( !dir_exists( g_szConfigFile ) )
mkdir( g_szConfigFile );
new szMapName[ 32 ];
get_mapname( szMapName, charsmax( szMapName ) );
strtolower( szMapName );
formatex( g_szConfigFile, charsmax( g_szConfigFile ), "%s/%s.txt", g_szConfigFile, szMapName );
new iFile = fopen( g_szConfigFile, "r" );
if( iFile ) {
new iEntity, iSpawnFlags, szI[ 6 ], szDatas[ 256 ], szClassname[ 32 ], szModel[ 5 ];
new iFlags[ 2 ], szDelay[ 16 ], szMovable[ 6 ], szToggable[ 6 ], szSound[ 32 ];
while( !feof( iFile ) ) {
fgets( iFile, szDatas, charsmax( szDatas ) );
trim( szDatas );
if( !szDatas[ 0 ] || szDatas[ 0 ] == ';' || ( szDatas[ 0 ] == '/' && szDatas[ 1 ] == '/' ) )
continue;
parse( szDatas, szClassname, 31, szModel, 4, szDelay, 15, szSound, 31, szMovable, 5, szToggable, 5 );
iEntity = find_ent_by_model( -1, szClassname, szModel );
if( iEntity > 0 ) {
set_pdata_float( iEntity, m_flWait, str_to_float( szDelay ), 4 );
if( !szSound[ 0 ] )
formatex( szSound, 31, "%s", g_szSounds[ 0 ] ); // Some maps have empty sounds O.o
if( TrieGetString( g_tSounds, szSound, szI, 5 ) || equali( szSound, g_szSounds[ 0 ] ) ) {
set_pdata_int( iEntity, m_ls.sUnlockedSound, engfunc( EngFunc_AllocString, szSound ), 5 );
DispatchKeyValue( iEntity, "unlocked_sound", szI );
}
iSpawnFlags = pev( iEntity, pev_spawnflags );
if( szMovable[ 0 ] ) {
iFlags[ 0 ] = str_to_num( szMovable );
if( ( iSpawnFlags & SF_BUTTON_DONTMOVE ) ) {
if( iFlags[ 0 ] == 0 )
set_pev( iEntity, pev_spawnflags, iSpawnFlags & ~SF_BUTTON_DONTMOVE );
} else {
if( iFlags[ 0 ] == 1 )
set_pev( iEntity, pev_spawnflags, iSpawnFlags | SF_BUTTON_DONTMOVE );
}
}
if( szToggable[ 0 ] ) {
iFlags[ 1 ] = str_to_num( szToggable );
if( ( iSpawnFlags & SF_BUTTON_TOGGLE ) ) {
if( iFlags[ 1 ] == 0 )
set_pev( iEntity, pev_spawnflags, iSpawnFlags & ~SF_BUTTON_TOGGLE );
} else {
if( iFlags[ 1 ] == 1 )
set_pev( iEntity, pev_spawnflags, iSpawnFlags | SF_BUTTON_TOGGLE );
}
}
DispatchSpawn( iEntity );
set_pev( iEntity, pev_iuser2, EDITED_ENT );
}
}
fclose( iFile );
}
}
public CmdOpenMenu( id, level, cid ) {
if( !cmd_access( id, level, cid, 1 ) )
return PLUGIN_HANDLED;
ShowMenu( id );
return PLUGIN_HANDLED;
}
public ShowMenu( id ) {
new szMenu[ 364 ], iKeys;
add( szMenu, charsmax( szMenu ), "\rA gombok kesedelem szerkeszto by xPaw^n^n" );
if( g_iEntity[ id ] > 0 ) {
new szI[ 6 ], szSound[ 32 ], szRandom[ 64 ], iWait;
iWait = floatround( get_pdata_float( g_iEntity[ id ], m_flWait, 4 ) );
formatex( szRandom, charsmax( szRandom ), "\yAktualis gomb: \w#%i^n\yAktualis kesedelem: \w%i masodperc%s^n^n", g_iEntity[ id ], iWait, iWait == 1 ? "" : "s" );
add( szMenu, charsmax( szMenu ), szRandom );
eng_get_string( get_pdata_int( g_iEntity[ id ], m_ls.sUnlockedSound, 5 ), szSound, 31 );
if( !szSound[ 0 ] )
formatex( szSound, 31, "%s", g_szSounds[ 0 ] ); // Some maps have empty sounds O.o
if( TrieGetString( g_tSounds, szSound, szI, 5 ) ) {
g_iSound[ id ] = str_to_num( szI );
formatex( szRandom, charsmax( szRandom ), "\r3. \wAktiv hang: \y%s^n", g_szSoundsNames[ g_iSound[ id ] ] );
} else {
g_iSound[ id ] = 0;
formatex( szRandom, charsmax( szRandom ), "\r3. \wAktiv hang: \yismeretlen\r (Jelentes xPaw)^n" );
// Log report
new szMapName[ 32 ];
get_mapname( szMapName, charsmax( szMapName ) );
log_amx( "----------" );
log_amx( "Beszamolas az ismeretlen hangnak" );
log_amx( "Hang: %s", szSound );
log_amx( "Palya: %s", szMapName );
log_amx( "Lenyeg: %i - Max jatekosok: %i", g_iEntity[ id ], get_maxplayers( ) );
log_amx( "----------" );
}
add( szMenu, charsmax( szMenu ), "\r1. \wKesedelem fent^n\r2. \wKesedelem lent^n^n" );
add( szMenu, charsmax( szMenu ), szRandom );
new iSpawnFlags = pev( g_iEntity[ id ], pev_spawnflags );
formatex( szRandom, charsmax( szRandom ), "\r4. \wNem mozog: \y%s^n\r5. \wToggable: \y%s^n^n",
( iSpawnFlags & SF_BUTTON_DONTMOVE ) ? "Igen" : "Nem", ( iSpawnFlags & SF_BUTTON_TOGGLE ) ? "Yes" : "No" );
add( szMenu, charsmax( szMenu ), szRandom );
iKeys = MENU_KEY_1 | MENU_KEY_2 | MENU_KEY_3 | MENU_KEY_4 | MENU_KEY_5 | MENU_KEY_9 | MENU_KEY_0;
} else {
add( szMenu, charsmax( szMenu ), "\yAktualis gomb: \wN/A^n^n" );
iKeys = MENU_KEY_9 | MENU_KEY_0;
}
add( szMenu, charsmax( szMenu ), "\r9. \wFelszedes uj gomb^n\r0. \wKilepes" );
show_menu( id, iKeys, szMenu, -1, "A gombok kesedelem szerkesztes" );
}
public handleMenu( id, iNum ) {
switch( iNum ) {
case 0: {
if( pev_valid( g_iEntity[ id ] ) ) {
new Float:flWait;
flWait = get_pdata_float( g_iEntity[ id ], m_flWait, 4 );
if( flWait + 1.0 > MAX_DELAY ) {
GreenPrint( id, "^4[AMXX]^3 Te maximum kesedelmet ertel el^4 %i^3!", floatround( MAX_DELAY ) );
} else {
set_pdata_float( g_iEntity[ id ], m_flWait, flWait + 1.0, 4 );
set_pev( g_iEntity[ id ], pev_iuser2, EDITED_ENT );
}
} else
g_iEntity[ id ] = 0;
}
case 1: {
if( pev_valid( g_iEntity[ id ] ) ) {
new Float:flWait;
flWait = get_pdata_float( g_iEntity[ id ], m_flWait, 4 );
if( flWait - 1.0 < MIN_DELAY ) {
GreenPrint( id, "^4[AMXX]^3 Te minimum kesedelemre terjedtel^4 %i^3!", floatround( MIN_DELAY ) );
} else {
set_pdata_float( g_iEntity[ id ], m_flWait, flWait - 1.0, 4 );
set_pev( g_iEntity[ id ], pev_iuser2, EDITED_ENT );
}
} else
g_iEntity[ id ] = 0;
}
case 2: {
if( pev_valid( g_iEntity[ id ] ) ) {
new iSound, szI[ 6 ];
if( g_iSound[ id ] == sizeof( g_szSoundsNames ) - 1 ) {
iSound = engfunc( EngFunc_AllocString, g_szSounds[ 0 ] );
num_to_str( 0, szI, 5 );
} else {
new i = g_iSound[ id ] + 1;
// We need to ignore 11 & 12....
if( 11 <= i <= 12 )
i = 13;
iSound = engfunc( EngFunc_AllocString, g_szSounds[ i ] );
num_to_str( i, szI, 5 );
}
set_pdata_int( g_iEntity[ id ], m_ls.sUnlockedSound, iSound, 5 );
DispatchKeyValue( g_iEntity[ id ], "unlocked_sound", szI );
} else
g_iEntity[ id ] = 0;
}
case 3: {
if( pev_valid( g_iEntity[ id ] ) ) {
new iSpawnFlags = pev( g_iEntity[ id ], pev_spawnflags );
if( iSpawnFlags & SF_BUTTON_DONTMOVE )
set_pev( g_iEntity[ id ], pev_spawnflags, iSpawnFlags & ~SF_BUTTON_DONTMOVE );
else
set_pev( g_iEntity[ id ], pev_spawnflags, iSpawnFlags | SF_BUTTON_DONTMOVE );
DispatchSpawn( g_iEntity[ id ] );
} else
g_iEntity[ id ] = 0;
}
case 4: {
if( pev_valid( g_iEntity[ id ] ) ) {
new iSpawnFlags = pev( g_iEntity[ id ], pev_spawnflags );
if( iSpawnFlags & SF_BUTTON_TOGGLE )
set_pev( g_iEntity[ id ], pev_spawnflags, iSpawnFlags & ~SF_BUTTON_TOGGLE );
else
set_pev( g_iEntity[ id ], pev_spawnflags, iSpawnFlags | SF_BUTTON_TOGGLE );
DispatchSpawn( g_iEntity[ id ] );
} else
g_iEntity[ id ] = 0;
}
case 8: {
g_iSound[ id ] = 0;
g_iEntity[ id ] = 0;
new iEntity, iBody;
get_user_aiming( id, iEntity, iBody, 400 );
if( pev_valid( iEntity ) ) {
if( IsButton( iEntity ) ) {
g_iEntity[ id ] = iEntity;
// Draw a beam from player to button
new iOrigin[ 3 ], iOrigin2[ 3 ], Float:flMins[ 3 ], Float:flMaxs[ 3 ];
get_user_origin( id, iOrigin );
pev( iEntity, pev_mins, flMins );
pev( iEntity, pev_maxs, flMaxs );
iOrigin2[ 0 ] = floatround( ( flMins[ 0 ] + flMaxs[ 0 ] ) * 0.5 );
iOrigin2[ 1 ] = floatround( ( flMins[ 1 ] + flMaxs[ 1 ] ) * 0.5 );
iOrigin2[ 2 ] = floatround( ( flMins[ 2 ] + flMaxs[ 2 ] ) * 0.5 );
DrawBeam( iOrigin, iOrigin2 );
} else
GreenPrint( id, "^4[AMXX]^1 Kerlek celozz meg egy gombot!" );
} else
GreenPrint( id, "^4[AMXX]^1 Kerlek celozz meg egy gombot!" );
}
case 9: {
g_iSound[ id ] = 0;
g_iEntity[ id ] = 0;
return;
}
}
if( iNum != 9 )
ShowMenu( id );
}
bool:IsButton( iEntity ) {
new szClassname[ 32 ];
pev( iEntity, pev_classname, szClassname, 31 );
for( new i; i < sizeof g_szButtons; i++ )
if( equal( szClassname, g_szButtons[ i ] ) )
return true;
return false;
}
stock DrawBeam( iOrigin[ 3 ], iOrigin2[ 3 ] ) {
message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
write_byte( TE_BEAMPOINTS );
write_coord( iOrigin[ 0 ] );
write_coord( iOrigin[ 1 ] );
write_coord( iOrigin[ 2 ] );
write_coord( iOrigin2[ 0 ] );
write_coord( iOrigin2[ 1 ] );
write_coord( iOrigin2[ 2 ] );
write_short( g_iSprite ); // model
write_byte( 0 ); // start frame
write_byte( 10 ); // framerate
write_byte( 20 ); // life
write_byte( 10 ); // width
write_byte( 2 ); // noise
write_byte( 0 ); // red
write_byte( 100 ); // green
write_byte( 255 ); // blue
write_byte( 100 ); // brightness
write_byte( 30 ); // speed
message_end( );
}
stock GreenPrint( id, const szMsg[ ], any:... ) {
new szMessage[ 192 ];
vformat( szMessage, 191, szMsg, 3 );
message_begin( MSG_ONE_UNRELIABLE, g_iMsg_Saytext, _, id );
write_byte( id );
write_string( szMessage );
message_end( );
return 1;
}