Welcome Soldier.



[APORTE] Mercader + Configuración.

Sky^^ Sin conexión
User
#1
FUNCIÓN: Al tipear en say '/mercader' se abrirá un menú donde puedes crear una entidad a la cual le puse de nombre 'Mercader'.
La entidad se creará a donde apuntes, la entidad no se mueve ni nada, al presionar la E cerca de ella manda un print( esto se puede editar ).
La entidad se guarda automáticamente en un archivo .ini.

CÓDIGO:
Código PHP:
<?php 
/* ============================================== */

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <engine>
#include <fakemeta>

new const szPlugin[ ][ ] = { "Mercader + Configuration", "1.0", "Sky^^" };
new const
szMessages[ ][ ] = { "^3MERCADER:^1", "^3ERROR:^1" };
new const
szPrefixMenu[ ] = "\yMERCADER:\w";

/* ============================================== */

#define MERCHANT_CLASSNAME "MERCHANT_NPC"
#define MERCHANT_MODEL "models/Merchant/gman.mdl"

new const g_szSoundOpen[ ][ ] = { "MERCADER/M_OPENM.wav" };
new const
g_szSoundError[ ][ ] = { "MERCADER/M_ERROR.wav" };
new const
g_szSoundNext[ ][ ] = { "MERCADER/M_NEXT.wav" };

new
g_szFile[ 128 ];

/* ============================================== */

public plugin_init( )
{
register_plugin( szPlugin[ 0 ], szPlugin[ 1 ], szPlugin[ 2 ] );

register_clcmd( "say /mercader", "menu_Mercader" );

RegisterHam( Ham_Use, "func_button", "fw_UseButton" );

register_think( MERCHANT_CLASSNAME, "fw_Merchant_Think" );
}
public
plugin_precache( )
{
new
i;

engfunc( EngFunc_PrecacheModel, MERCHANT_MODEL );
engfunc( EngFunc_PrecacheGeneric, "models/gmanT.mdl" );

for(
i = 0; i < sizeof g_szSoundOpen; i++ ) engfunc( EngFunc_PrecacheSound, g_szSoundOpen[ i ] );
for(
i = 0; i < sizeof g_szSoundError; i++ ) engfunc( EngFunc_PrecacheSound, g_szSoundError[ i ] );
for(
i = 0; i < sizeof g_szSoundNext; i++ ) engfunc( EngFunc_PrecacheSound, g_szSoundNext[ i ] );
}

public
plugin_cfg( )
{
new
szDir[ 64 ], szMapName[ 32 ];
get_localinfo( "amxx_configsdir", szDir, charsmax( szDir ) );

get_mapname( szMapName, charsmax( szMapName ) );
strtolower( szMapName );

formatex( g_szFile, charsmax( g_szFile ), "%s/mercader/%s.ini", szDir, szMapName );

if (!
file_exists( g_szFile ) )
{
server_print( "No hay Mercader's guardados en este mapa" );

add( szDir, charsmax( szDir ), "/mercader" );

if( !
dir_exists( szDir ) )
mkdir( szDir );
}
else
ReadFile( );
}

ReadFile( )
{
new
szData[ 64 ], szX[ 13 ], szY[ 13 ], szZ[ 13 ], Float:Origin[ 3 ];

new
File = fopen( g_szFile, "rt" );

while( !
feof( File ) )
{
fgets( File, szData, charsmax( szData ) );

if( !
szData[ 0 ] || szData[ 0 ] == ';' || szData[ 0 ] == ' ' || ( szData[ 0 ] == '/' && szData[ 1 ] == '/') )
continue;

parse( szData, szX, charsmax( szX ), szY, charsmax( szY ), szZ, charsmax( szZ ) );
 
Origin
[ 0 ] = str_to_float( szX );
Origin[ 1 ] = str_to_float( szY );
Origin[ 2 ] = str_to_float( szZ );

createMercader( Origin );
}

fclose( File );
}

/* ============================================== */

public menu_Mercader( id )
{
if( !
is_user_alive( id ) )
{
emit_sound( id, CHAN_ITEM, g_szSoundError[ random_num( 0, sizeof g_szSoundError - 1 ) ], VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
cc( id, "%s Debes estar vivo para abrir el menu.", szMessages[ 1 ] );
return
PLUGIN_HANDLED;
}
if( !
is_user_admin( id ) )
{
emit_sound( id, CHAN_ITEM, g_szSoundError[ random_num( 0, sizeof g_szSoundError - 1 ) ], VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
cc( id, "%s Debes ser administrador para abrir el menu.", szMessages[ 1 ] );
return
PLUGIN_HANDLED;
}

static
iFormatex[ 90 ];

formatex( iFormatex, charsmax( iFormatex ), "%s CONFIGURACION DEL MERCADER", szPrefixMenu );
new
iMenu = menu_create( iFormatex, "hand_MenuMercader" );

menu_additem( iMenu, "\wCREAR\y MERCADER", "1" );

menu_additem( iMenu, "\wBORRAR\y MERCADER", "2" );

menu_additem( iMenu, "\wGUARDAR\y MERCADER's", "3" );

menu_setprop( iMenu, MPROP_EXITNAME, "SALIR" );
menu_display( id, iMenu, 0 );

return
PLUGIN_HANDLED;
}
public
hand_MenuMercader( id, menu, item )
{
if(
item == MENU_EXIT )
{
menu_destroy( menu )
return
PLUGIN_HANDLED;
}

switch(
item )
{
case
0:
{
new
i_Origin[ 3 ], Float:f_Origin[ 3 ];
get_user_origin( id, i_Origin, 3 );
IVecFVec( i_Origin, f_Origin );

f_Origin[ 2 ] += 20.0;

if(
createMercader( f_Origin ) )
{
emit_sound( id, CHAN_ITEM, g_szSoundNext[ random_num( 0, sizeof g_szSoundNext - 1 ) ], VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
cc( id, "%s Mercader creado correctamente.", szMessages[ 0 ] );
menu_Mercader( id );
}
else
{
emit_sound( id, CHAN_ITEM, g_szSoundError[ random_num( 0, sizeof g_szSoundError - 1 ) ], VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
cc( id, "%s No se pudo crear el Mercader.", szMessages[ 1 ] );
menu_Mercader( id );
}
}
case
1:
{
new
ent, body;
get_user_aiming( id, ent, body, 9999 );

if(
is_valid_ent( ent ) )
{
new
szClass[ 32 ];
entity_get_string( ent, EV_SZ_classname, szClass, charsmax( szClass ) );

if(
equal( szClass, MERCHANT_CLASSNAME ) )
{
remove_entity( ent );
emit_sound( id, CHAN_ITEM, g_szSoundNext[ random_num( 0, sizeof g_szSoundNext - 1 ) ], VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
cc( id, "%s Mercader removido correctamente.", szMessages[ 0 ] );
menu_Mercader( id );
}
else
{
emit_sound( id, CHAN_ITEM, g_szSoundError[ random_num( 0, sizeof g_szSoundError - 1 ) ], VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
cc( id, "%s Debes apuntar al Mercader para borrarlo.", szMessages[ 1 ] );
menu_Mercader( id );
}
}
else
{
emit_sound( id, CHAN_ITEM, g_szSoundError[ random_num( 0, sizeof g_szSoundError - 1 ) ], VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
cc( id, "%s Debes apuntar al Mercader para borrarlo.", szMessages[ 1 ] );
menu_Mercader( id );
}
}
case
2:
{
new
szData[ 64 ], ent = -1,  Float:Origin[ 3 ];

if(
file_exists( g_szFile ) )
delete_file( g_szFile );

new
File = fopen( g_szFile, "at" );

write_file( g_szFile, "// Posiciones de los Mercader's." );
write_file( g_szFile, "// NO MODIFICAR NADA." );
write_file( g_szFile, "// Plugin by Skylar.^n" );

while( (
ent = find_ent_by_class(ent, MERCHANT_CLASSNAME ) ) )
{
entity_get_vector( ent, EV_VEC_origin, Origin );

formatex( szData, charsmax( szData ), "%f %f %f^n", Origin[ 0 ], Origin[ 1 ], Origin[ 2 ] );

fputs( File, szData );
}

fclose( File );

emit_sound( id, CHAN_ITEM, g_szSoundNext[ random_num( 0, sizeof g_szSoundNext - 1 ) ], VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
cc( id, "%s Mercader's guardados correctamente.", szMessages[ 0 ] );
}
}

menu_destroy( menu );
return
PLUGIN_HANDLED;
}

public
createMercader( Float:Origin[ 3 ] )
{
new
i_Ent = create_entity( "func_button" );

if( !
is_valid_ent( i_Ent ) )
return
PLUGIN_CONTINUE
 
entity_set_string
( i_Ent, EV_SZ_classname, MERCHANT_CLASSNAME );
entity_set_string( i_Ent, EV_SZ_target, "merchant" );
entity_set_int( i_Ent, EV_INT_solid, SOLID_BBOX );
entity_set_model( i_Ent, MERCHANT_MODEL );
 
#define MERCHANT_MINS { -16.0, -16.0, 0.0 }
#define MERCHANT_MAXS { 16.0, 16.0, 72.0 }
entity_set_size( i_Ent, Float:MERCHANT_MINS, Float:MERCHANT_MAXS );

entity_set_origin( i_Ent, Origin );
 
entity_set_float
( i_Ent, EV_FL_nextthink, halflife_time( ) + 3.0 );
 
drop_to_floor
( i_Ent );

return
PLUGIN_HANDLED;
}

/* ============================================== */

public fw_Merchant_Think( ent )
{
entity_set_float( ent, EV_FL_animtime, get_gametime( ) );
entity_set_float( ent, EV_FL_framerate, 1.0 );
entity_set_int( ent, EV_INT_sequence, random_num( 0, 4 ) );

entity_set_float( ent, EV_FL_nextthink, halflife_time( ) + 3.0 );
}

public
fw_UseButton( ent, id )
{
if( !
ent || id > 32 ) return HAM_IGNORED;
if( !
is_user_alive( id ) ) return HAM_IGNORED;

static
szTarget[ 32 ]; entity_get_string( ent, EV_SZ_target, szTarget, charsmax( szTarget ) )

if(
equal( szTarget, "merchant" ) )
{
emit_sound( id, CHAN_ITEM, g_szSoundOpen[ random_num( 0, sizeof g_szSoundOpen - 1 ) ], VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
cc( id, "%s Se abrio el Shop.", szMessages[ 0 ] );
}

return
HAM_IGNORED;
}

/* ============================================== */

stock cc( id, const input[], any:... )
{
static
szMsg[ 191 ], msgSayText;

if( !
msgSayText ) msgSayText = get_user_msgid( "SayText" );

vformat( szMsg, 190, input, 3) ;

replace_all( szMsg, 190, "!g", "^4" );
replace_all( szMsg, 190, "!y", "^1" );
replace_all( szMsg, 190, "!team", "^3" );

message_begin( id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, msgSayText, .player = id );
write_byte( id ? id : 33 );
write_string( szMsg );
message_end( );
}

ACÁ PUEDEN EDITAR LA FUNCIÓN QUE CUMPLIRÁ AL PRESIONAR LA TECLA 'E':

Código PHP:
<?php 
public fw_UseButton( ent, id )
{
if( !
ent || id > 32 ) return HAM_IGNORED;
if( !
is_user_alive( id ) ) return HAM_IGNORED;

static
szTarget[ 32 ]; entity_get_string( ent, EV_SZ_target, szTarget, charsmax( szTarget ) )

if(
equal( szTarget, "merchant" ) )
{
emit_sound( id, CHAN_ITEM, g_szSoundOpen[ random_num( 0, sizeof g_szSoundOpen - 1 ) ], VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
cc( id, "%s Se abrio el Shop.", szMessages[ 0 ] );
}

return
HAM_IGNORED;
}

RECURSOS: http://www.mediafire.com/file/by13p454a5...cursos.rar

Si tienen alguna duda me la comentan!
[Imagen: 76561198095047868.png]

Perfil de amxmodx-es: Skylar
[+] 1 user says Thank You to Sky^^ for this post
Responder





Usuarios navegando en este tema:
1 invitado(s)



Sobre M X E M E X I C O

Comunidad MxE © 2020 - La mejorar comunidad de Counter Strike 1.6 .