16/03/2018, 08:03 PM
Hola todos, bueno alguien podría cambiar esta torreta de treki a extra item de zombie plague por favor? ... gracias antemano
Código PHP:
#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <hamsandwich>
#include <ttt>
#include <xs>
/* ===============================================================================
* [ Plugin initiation & Global stuff ]
* =============================================================================== */
#define SetPlayerBit(%1,%2) ( %1 |= ( 1 << ( %2 & 31 ) ) )
#define ClearPlayerBit(%1,%2) ( %1 &= ~( 1 << ( %2 & 31 ) ) )
#define GetPlayerBit(%1,%2) ( %1 & ( 1 << ( %2 & 31 ) ) )
#define IsValidPlayer(%0) ( 1 <= %0 <= 32 )
enum _:Sentry_Sequences
{
Sequence_Idle = 0,
Sequence_Shooting = 1,
Sequence_Deploy = 4,
Sequence_Die = 5
}
const OFFSET_PAINSHOCK = 108;
const Sentry_Owner = EV_INT_iuser1;
const Sentry_Target = EV_INT_iuser2;
new const g_szCache_ExplosionEntity[ ] = "env_explosion";
new const g_szSentryEntity[ ] = "func_breakable";
new const g_szSentryClassname[ ] = "SentryGun";
new const g_szSentryModel[ ] = "models/ttt/us_turret.mdl";
new const g_szSentrySpotSound[ ] = "ttt/spot.wav";
new const g_szSentryStopSound[ ] = "ttt/stop.wav";
new const g_szSentryBuiltSound[ ] = "ttt/built.wav";
new const g_szSentryShootSound[ ] = "ttt/shoot.wav";
new g_iItemID, g_iMaxPlayers, g_iBought;
public plugin_precache( )
{
precache_sound( "debris/bustglass1.wav" );
precache_sound( "debris/bustglass2.wav" );
precache_model( "models/ttt/us_turrett.mdl" );
precache_model( g_szSentryModel );
precache_sound( g_szSentrySpotSound );
precache_sound( g_szSentryStopSound );
precache_sound( g_szSentryBuiltSound );
precache_sound( g_szSentryShootSound );
}
public plugin_init( )
{
register_plugin( "[TTT] Item: Sentry Gun", "1.0", "Manu" );
register_think( g_szSentryClassname, "think_Sentry" );
register_clcmd( "say /torreta", "CreateSentry" );
g_iMaxPlayers = get_maxplayers( );
}
/* ===============================================================================
* [ Trouble in terrorist town's forwards ]
* =============================================================================== */
public ttt_gamemode( iGamemode )
{
if( iGamemode == GAME_ENDED || iGamemode == GAME_RESTARTING )
{
static iNum, iPlayers[ 32 ]; get_players( iPlayers, iNum );
for( --iNum; iNum >= 0; iNum-- )
ClearPlayerBit( g_iBought, iPlayers[ iNum ] );
new iEnt;
while( ( iEnt = find_ent_by_class( iEnt, g_szSentryClassname ) ) != 0 )
entity_set_int( iEnt, Sentry_Owner, 0 );
}
}
public ttt_item_selected( iId, iItem, szName[ ], iPrice )
{
if( g_iItemID == iItem )
{
SetPlayerBit( g_iBought, iId );
client_print_color( iId, print_team_default, "^4[TTT]^1 Compraste una torreta. Mira al piso y escribe ^4/torreta^1 para colocarla!" );
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public ttt_plugin_cfg( ) g_iItemID = ttt_buymenu_add( "Torreta", 2, PC_TRAITOR );
/* ===============================================================================
* [ Sentry's brain & events ]
* =============================================================================== */
public think_Sentry( iEnt )
{
static iOwner; iOwner = entity_get_int( iEnt, Sentry_Owner );
if( is_valid_ent( iEnt ) && is_user_alive( iOwner ) && entity_get_float( iEnt, EV_FL_health ) > 0.0 )
{
static iTarget; iTarget = entity_get_int( iEnt, Sentry_Target );
if( IsValidPlayer( iTarget ) )
{
if( IsPlayerShootable( iEnt, iTarget ) )
{
TraceBullet( iEnt, iTarget );
SetEntityAiming( iEnt, iTarget );
PlaySequence( iEnt, Sequence_Shooting );
ExecuteHamB( Ham_TakeDamage, iTarget, iOwner, iOwner, 10.0, DMG_BULLET );
emit_sound( iEnt, CHAN_WEAPON, g_szSentryShootSound, 0.2, ATTN_NORM, 0, PITCH_NORM );
entity_set_float( iEnt, EV_FL_nextthink, halflife_time( ) + 0.1 );
}
else
{
PlaySequence( iEnt, Sequence_Idle );
entity_set_int( iEnt, Sentry_Target, 0 );
entity_set_float( iEnt, EV_FL_nextthink, halflife_time( ) + 1.0 );
emit_sound( iEnt, CHAN_WEAPON, g_szSentryStopSound, 0.2, ATTN_NORM, 0, PITCH_NORM );
}
}
else
{
entity_set_float( iEnt, EV_FL_nextthink, halflife_time( ) + 0.5 );
for( iTarget = 1; iTarget <= g_iMaxPlayers; iTarget++ )
{
if( IsPlayerShootable( iEnt, iTarget ) )
{
PlaySequence( iEnt, Sequence_Deploy );
entity_set_int( iEnt, Sentry_Target, iTarget );
emit_sound( iEnt, CHAN_WEAPON, g_szSentrySpotSound, 0.3, ATTN_NORM, 0, PITCH_NORM );
break;
}
}
}
}
else
{
PlaySequence( iEnt, Sequence_Die );
entity_set_float( iEnt, EV_FL_health, 1.0 );
entity_set_float( iEnt, EV_FL_takedamage, DAMAGE_NO );
entity_set_int( iEnt, EV_INT_effects, entity_get_int( iEnt, EV_INT_effects ) & ~EF_NODRAW );
set_task( 1.0, "RemoveSentry", iEnt );
}
}
public RemoveSentry( const iSentry )
{
static iEnt, Float:flOrigin[ 3 ]; entity_get_vector( iSentry, EV_VEC_origin, flOrigin );
if( is_valid_ent( ( iEnt = create_entity( g_szCache_ExplosionEntity ) ) ) )
{
entity_set_origin( iEnt, flOrigin );
entity_set_int( iEnt, EV_INT_spawnflags, SF_ENVEXPLOSION_NODAMAGE );
DispatchKeyValue( iEnt, "iMagnitude", "50" );
DispatchSpawn( iEnt );
force_use( iEnt, iEnt );
remove_entity( iEnt );
remove_entity( iSentry );
return 1;
}
return 0;
}
/* ===============================================================================
* [ Client-related & Events ]
* =============================================================================== */
public CreateSentry( const iId )
{
static iEnt,Float:vOrigin[ 3 ],Float:vAngles[ 3 ];
if( GetPlayerBit( g_iBought, iId ) && is_valid_ent( ( iEnt = create_entity( g_szSentryEntity ) ) ) )
{
if( GetSentryOrigin( iId, vOrigin, vAngles ) )
{
entity_set_string( iEnt, EV_SZ_classname, g_szSentryClassname );
entity_set_model( iEnt, g_szSentryModel );
entity_set_size( iEnt, Float:{ -16.0,-16.0,0.0 }, Float:{ 16.0,16.0,36.0 } );
entity_set_origin( iEnt, vOrigin );
entity_set_vector( iEnt, EV_VEC_angles, vAngles );
entity_set_int( iEnt, EV_INT_solid, SOLID_BBOX );
entity_set_int( iEnt, EV_INT_movetype, MOVETYPE_TOSS );
entity_set_int( iEnt, Sentry_Owner, iId );
entity_set_float( iEnt, EV_FL_health, 300.0 );
entity_set_float( iEnt, EV_FL_takedamage, DAMAGE_NO );
entity_set_int( iEnt, EV_INT_sequence, 0 );
entity_set_float( iEnt, EV_FL_animtime, 1.0 );
entity_set_float( iEnt, EV_FL_framerate, 1.0 );
set_task( 1.0, "CompleteBuilding", iEnt );
set_rendering( iEnt, kRenderFxGlowShell, 255, 255, 255, kRenderNormal, 30 );
drop_to_floor( iEnt );
ClearPlayerBit( g_iBought, iId );
return PLUGIN_HANDLED;
}
remove_entity( iEnt );
client_print_color( iId, print_team_default, "^x04[TTT]^x01 No habia espacio para la torreta." );
}
else
client_print_color( iId, print_team_default, "^x04[TTT]^x01 No puedes poner una torreta en este momento." );
return PLUGIN_HANDLED;
}
public CompleteBuilding( iEnt )
{
if( is_valid_ent( iEnt ) )
{
set_rendering( iEnt );
emit_sound( iEnt, CHAN_WEAPON, g_szSentryBuiltSound, 0.3, ATTN_NORM, 0, PITCH_NORM );
entity_set_float( iEnt, EV_FL_takedamage, DAMAGE_YES );
entity_set_float( iEnt, EV_FL_nextthink, halflife_time( ) + 0.1 );
}
}
public client_disconnect( iId ) ClearPlayerBit( g_iBought, iId );
/* ===============================================================================
* [ Other useful stuff ]
* =============================================================================== */
SetEntityAiming( iEnt,iTarget )
{
static Float:fOrigin[ 3 ], Float:fTarget[ 3 ];
entity_get_vector( iEnt, EV_VEC_origin, fOrigin );
entity_get_vector( iTarget, EV_VEC_origin, fTarget );
xs_vec_sub( fTarget, fOrigin, fTarget );
xs_vec_normalize( fTarget, fTarget );
vector_to_angle( fTarget, fTarget ); fTarget[ 0 ] = 0.0;
entity_set_vector( iEnt, EV_VEC_angles, fTarget );
return 1;
}
GetSentryOrigin( const iId, Float:vOrigin[ 3 ], Float:vSentryAngles[ 3 ] )
{
static iTrace, Float:vAngles[ 3 ], Float:vViewOfs[ 3 ], Float:vEnd[ 3 ], Float:fFraction;
entity_get_vector( iId, EV_VEC_origin, vOrigin );
entity_get_vector( iId, EV_VEC_view_ofs, vViewOfs );
entity_get_vector( iId, EV_VEC_v_angle, vAngles );
vSentryAngles[ 1 ] = vAngles[ 1 ];
xs_vec_add( vOrigin, vViewOfs, vOrigin );
angle_vector( vAngles, ANGLEVECTOR_FORWARD, vAngles );
xs_vec_mul_scalar( vAngles, 128.0, vAngles );
xs_vec_add( vOrigin, vAngles, vEnd );
engfunc( EngFunc_TraceLine, vOrigin, vEnd, DONT_IGNORE_MONSTERS, iId, iTrace );
get_tr2( iTrace, TR_flFraction, fFraction ); get_tr2( iTrace, TR_vecEndPos, vOrigin ); free_tr2( iTrace );
xs_vec_copy( vOrigin,vEnd ); vEnd[ 2 ] += 18;
if( fFraction >= 1.0 || trace_hull( vEnd, HULL_HEAD, _, DONT_IGNORE_MONSTERS ) != 0 )
return 0;
return 1;
}
IsPlayerShootable( const iEnt,const iPlayer )
{
if( is_user_alive( iPlayer ) && ttt_get_playerstate( iPlayer ) != PC_TRAITOR && entity_range( iEnt,iPlayer ) <= 900.0 )
{
static Float:vOrigin[ 3 ], Float:vEnd[ 3 ], Float:fFraction;
entity_get_vector( iPlayer, EV_VEC_origin, vOrigin );
entity_get_vector( iEnt, EV_VEC_origin, vEnd );
engfunc( EngFunc_TraceLine, vOrigin, vEnd, IGNORE_MONSTERS, iEnt, 0 ); get_tr2( 0, TR_flFraction, fFraction );
return ( fFraction >= 1.0 );
}
return false;
}
TraceBullet( const iEnt,const iTarget )
{
static Float:vOrigin[ 3 ],Float:vTarget[ 3 ],iStart[ 3 ],iEnd[ 3 ];
entity_get_vector( iEnt, EV_VEC_origin, vOrigin ); entity_get_vector( iTarget, EV_VEC_origin, vTarget );
FVecIVec( vOrigin, iStart ); FVecIVec( vTarget, iEnd );
message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
write_byte( TE_TRACER );
write_coord( iStart[ 0 ] );
write_coord( iStart[ 1 ] );
write_coord( iStart[ 2 ] );
write_coord( iEnd[ 0 ] );
write_coord( iEnd[ 1 ] );
write_coord( iEnd[ 2 ] );
message_end( );
}
PlaySequence( iEnt, iSequence )
{
if( !is_valid_ent( iEnt ) )
return;
entity_set_float( iEnt, EV_FL_animtime, get_gametime( ) );
entity_set_float( iEnt, EV_FL_framerate, 1.0 );
entity_set_int( iEnt, EV_INT_sequence, iSequence );
}