Код:
#define VERSION "1.0"
#include <amxmodx>
#include <engine>
#include <fakemeta>
// const
const HUD_COLOR = 22 + ( 166 << 8 ) + ( 60 << 16 ) // B + ( G << 8 ) + ( R << 16 )
// resources
new const mdl_rpgammo [ ] = "models/w_rpgammo.mdl"
new const mdl_rpgrocket[ ] = "models/rpgrocket.mdl"
new const s_weapondrop1[ ] = "items/weapondrop1.wav"
new const s_rocket1 [ ] = "fireworks/rocket1.wav"
new const spr_laserbeam[ ] = "sprites/laserbeam.spr"
new const spr_flare6 [ ] = "sprites/flare6.spr"
new const spr_lgtning [ ] = "sprites/lgtning.spr"
new const spr_explode1 [ ] = "sprites/explode1.spr"
new const spr_steam1 [ ] = "sprites/steam1.spr"
new const spr_flares[ ][ ] =
{
"sprites/fireworks/bflare.spr",
"sprites/fireworks/rflare.spr",
"sprites/fireworks/gflare.spr",
"sprites/fireworks/tflare.spr",
"sprites/fireworks/oflare.spr",
"sprites/fireworks/pflare.spr",
"sprites/fireworks/yflare.spr"
}
// resources index
new spr_laserbeam_id
new spr_flare6_id
new spr_lgtning_id
new spr_explode1_id
new spr_steam1_id
new spr_flares_id[ sizeof spr_flares ]
// entity
new const xmas_shooter [ ] = "xmas_shooter" // shooter classname
new const xmas_fireworks[ ] = "xmas_fireworks" // firework classname
new const Float:vecMins[ 3 ] = { -4.0, -4.0, -1.0 }
new const Float:vecMaxs[ 3 ] = { 4.0 , 4.0 , 12.0 }
// arrays
new Array:aOrigins
// cvars
new cvar_enable
new cvar_times
new cvar_shots
new cvar_lights
// global
new g_originsnum
new g_rocketsnum
new g_showhudmsg
public plugin_precache( )
{
precache_model( mdl_rpgammo )
precache_model( "models/w_rpgammot.mdl" )
precache_model( mdl_rpgrocket )
precache_sound( s_weapondrop1 )
precache_sound( s_rocket1 )
spr_laserbeam_id = precache_model( spr_laserbeam )
spr_flare6_id = precache_model( spr_flare6 )
spr_lgtning_id = precache_model( spr_lgtning )
spr_explode1_id = precache_model( spr_explode1 )
spr_steam1_id = precache_model( spr_steam1 )
for( new i; i < sizeof spr_flares; i++ )
{
spr_flares_id[ i ] = precache_model( spr_flares[i] )
}
}
public plugin_init( )
{
// original plugin: https://forums.alliedmods.net/showthread.php?t=3638
register_plugin( "Xmas Fireworks", VERSION, "Milashkasiya" )
register_think( xmas_fireworks, "think_fireworks" )
register_touch( "*", xmas_fireworks, "touch_fireworks" )
cvar_enable = register_cvar( "xfireworks_enable", "1" )
cvar_times = register_cvar( "xfireworks_times", "4" )
cvar_shots = register_cvar( "xfireworks_shots", "8" )
cvar_lights = register_cvar( "xfireworks_lights", "1" )
load_origins( )
set_task( 0.8, "task_realtime" )
}
public task_realtime( )
{
#define T_COMPENSATION 10.0
#define EF_DURATION 10.0
new Float:flTimeleft = float( get_timeleft() )
new Float:flTimes = get_pcvar_float( cvar_times )
new Float:flTimer
if( !flTimeleft )
{
flTimer = random_float( 600.0, 900.0 )
}
else
{
flTimer = ( flTimeleft / flTimes ) - ( T_COMPENSATION / flTimes )
if( flTimer < EF_DURATION )
{
flTimes = flTimeleft / EF_DURATION
flTimer = ( flTimeleft / flTimes ) - ( T_COMPENSATION / flTimes )
}
}
set_task( flTimer, "task_prepare_shooter", _, _, _, "a", floatround(flTimes) )
}
public task_prepare_shooter( )
{
if( !get_pcvar_num(cvar_enable) )
return
create_shooter( )
}
create_shooter( )
{
new entity
new Float:vecOrigin[ 3 ]
new shots = get_pcvar_num( cvar_shots )
g_rocketsnum = shots * g_originsnum
g_showhudmsg = g_originsnum / 2
for( new i; i < g_originsnum; i++ )
{
entity = create_entity( "info_target" )
assert entity
entity_set_string( entity, EV_SZ_classname, xmas_shooter )
entity_set_model( entity, mdl_rpgammo )
entity_set_int( entity, EV_INT_movetype, MOVETYPE_TOSS )
entity_set_int( entity, EV_INT_iuser1, shots )
ArrayGetArray( aOrigins, i, vecOrigin )
entity_set_origin( entity, vecOrigin )
DispatchSpawn( entity )
emit_sound( entity, CHAN_WEAPON, s_weapondrop1, VOL_NORM, ATTN_NORM, 0, PITCH_NORM )
set_task( random_float(0.1, 1.5), "task_prepare_fireworks", entity, _:vecOrigin , 3, "a", shots )
}
}
public task_prepare_fireworks( origin[3], shooter )
{
create_fireworks( shooter, Float:origin )
new iShots = entity_get_int( shooter, EV_INT_iuser1 ) - 1
if( !iShots )
{
remove_entity( shooter )
}
else
{
entity_set_int( shooter, EV_INT_iuser1, iShots )
}
}
create_fireworks( shooter, Float:origin[3] )
{
new entity = create_entity( "info_target" )
assert entity
entity_set_string( entity, EV_SZ_classname, xmas_fireworks )
entity_set_model( entity, mdl_rpgrocket )
entity_set_size( entity, vecMins, vecMaxs )
entity_set_int( entity, EV_INT_solid, SOLID_SLIDEBOX )
entity_set_int( entity, EV_INT_movetype, MOVETYPE_TOSS )
entity_set_float( entity, EV_FL_fuser1, get_gametime() + random_float(2.0, 4.0) + 0.1 )
entity_set_edict( entity, EV_ENT_owner, shooter )
entity_set_vector( entity, EV_VEC_angles, Float:{90.0, 0.0, 0.0} )
entity_set_origin( entity, origin )
DispatchSpawn( entity )
// beamfollow effect
message_begin( MSG_BROADCAST, SVC_TEMPENTITY )
write_byte( TE_BEAMFOLLOW )
write_short( entity )
write_short( spr_laserbeam_id )
write_byte( 60 )
write_byte( 4 )
write_byte( random(256) )
write_byte( random(256) )
write_byte( random(256) )
write_byte( random_num(200, 255) )
message_end( )
emit_sound( entity, CHAN_WEAPON, s_rocket1, VOL_NORM, ATTN_NORM, 0, PITCH_NORM )
entity_set_float( entity, EV_FL_nextthink, get_gametime() + 0.1 )
}
public think_fireworks( const entity )
{
static Float:flGametime
flGametime = get_gametime( )
if( entity_get_float(entity, EV_FL_fuser1) <= flGametime )
{
explode_rocket( entity )
}
else
{
static Float:vecVelocity[ 3 ]
vecVelocity[ 0 ] = random_float( -100.0, 100.0 )
vecVelocity[ 1 ] = random_float( -100.0, 100.0 )
vecVelocity[ 2 ] = random_float( 800.0, 1800.0 )
entity_set_vector( entity, EV_VEC_velocity, vecVelocity )
entity_set_float( entity, EV_FL_nextthink, flGametime + random_float( 0.1, 1.5) )
}
}
public touch_fireworks( const touched, const toucher )
{
explode_rocket( toucher )
}
explode_rocket( const rocket )
{
new output[ 64 ]
if( get_pcvar_num(cvar_lights) )
{
if( --g_rocketsnum > 0 )
{
formatex( output, charsmax(output), "%c", random_num('d','z') )
}
else
{
formatex( output, charsmax(output), "#OFF" )
}
set_lights( output )
}
if( g_rocketsnum <= g_showhudmsg )
{
new len = formatex( output, charsmax(output), "MERRY CHRISTMAS AND HAPPY NEW YEAR :)" ) + 31
__show__dhudmessage( output, len, _:-1.0, _:0.28 )
}
new Float:vecOrigin[ 3 ]
entity_get_vector( rocket, EV_VEC_origin, vecOrigin )
//////////////////////////////////////////////
engfunc( EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, vecOrigin, 0)
write_byte( TE_BEAMDISK )
engfunc( EngFunc_WriteCoord, vecOrigin[0] )
engfunc( EngFunc_WriteCoord, vecOrigin[1] )
engfunc( EngFunc_WriteCoord, vecOrigin[2] )
write_coord( 0 )
write_coord( 0 )
write_coord( 100 )
write_short( random(2) ? spr_flare6_id : spr_lgtning_id )
write_byte( 100 )
write_byte( 0 )
write_byte( 35 ) // life
write_byte( 0 ) // line width
write_byte( 150 ) // noise
write_byte( random(256) )
write_byte( random(256) )
write_byte( random(256) )
write_byte( 255 )
write_byte( 5 )
message_end( )
//////////////////////////////////////////////
message_begin( MSG_BROADCAST, SVC_TEMPENTITY )
write_byte( TE_SPRITETRAIL )
engfunc( EngFunc_WriteCoord, vecOrigin[0] )
engfunc( EngFunc_WriteCoord, vecOrigin[1] )
engfunc( EngFunc_WriteCoord, vecOrigin[2] - 20 )
engfunc( EngFunc_WriteCoord, vecOrigin[0] )
engfunc( EngFunc_WriteCoord, vecOrigin[1] )
engfunc( EngFunc_WriteCoord, vecOrigin[2] + 20 )
write_short( spr_flares_id[ random(sizeof spr_flares) ] )
write_byte( random_num(50, 100) ) // count
write_byte( 10 ) // life in 0.1's
write_byte( 10 ) // scale in 0.1's
write_byte( random_num(40, 100) ) // velocity along vector in 10's
write_byte( 60 ) // randomness of velocity in 10's
message_end( )
//////////////////////////////////////////////
engfunc( EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecOrigin, 0 )
write_byte( TE_EXPLOSION )
engfunc( EngFunc_WriteCoord, vecOrigin[0] )
engfunc( EngFunc_WriteCoord, vecOrigin[1] )
engfunc( EngFunc_WriteCoord, vecOrigin[2] )
write_short( spr_explode1_id )
write_byte( random_num(10, 20) ) // byte (scale in 0.1's) 188
write_byte( 10 ) // byte (framerate)
write_byte( 0 ) // byte flags
message_end( )
//////////////////////////////////////////////
engfunc( EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecOrigin, 0 )
write_byte( TE_TAREXPLOSION )
engfunc( EngFunc_WriteCoord, vecOrigin[0] )
engfunc( EngFunc_WriteCoord, vecOrigin[1] )
engfunc( EngFunc_WriteCoord, vecOrigin[2] - 40.0 )
message_end( )
//////////////////////////////////////////////
engfunc( EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, vecOrigin, 0 )
write_byte( TE_SMOKE )
engfunc( EngFunc_WriteCoord, vecOrigin[0] )
engfunc( EngFunc_WriteCoord, vecOrigin[1] )
engfunc( EngFunc_WriteCoord, vecOrigin[2] )
write_short( spr_steam1_id )
write_byte( random_num(20, 40) )
write_byte( 12 )
message_end( )
//////////////////////////////////////////////
engfunc( EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, vecOrigin, 0 )
write_byte( TE_DLIGHT )
engfunc( EngFunc_WriteCoord, vecOrigin[0] )
engfunc( EngFunc_WriteCoord, vecOrigin[1] )
engfunc( EngFunc_WriteCoord, vecOrigin[2] )
write_byte( random_num(20, 50) )
write_byte( random(256) )
write_byte( random(256) )
write_byte( random(256) )
write_byte( 100 )
write_byte( 15 )
message_end( )
remove_entity( rocket )
}
// http://forums.alliedmods.net/showthread.php?t=149210
__show__dhudmessage( const szMessage[], iLen, x, y )
{
message_begin( MSG_BROADCAST , SVC_DIRECTOR )
write_byte( iLen )
write_byte( DRC_CMD_MESSAGE )
write_byte( 0 ) // effect
write_long( HUD_COLOR )
write_long( x )
write_long( y )
write_long( 0x3F800000 ) // fadeintime
write_long( 0x3F800000 ) // fadeouttime
write_long( 0x40A00000 ) // holdtime
write_long( 0 ) // fxtime
write_string( szMessage )
message_end( )
}
load_origins( )
{
new output[ 128 ]
get_localinfo( "amxx_configsdir", output, charsmax(output) )
add( output, charsmax(output), "/xmas_fireworks.ini" )
if( !file_exists(output) )
{
set_fail_state( "xmas_fireworks.ini doesn't exist" )
return
}
aOrigins = ArrayCreate( 3 )
new map[ 64 ]
new len = get_mapname( map, charsmax(map) )
new bool:match
new origin[ 3 ][ 16 ]
new Float:vecOrigin[ 3 ]
new file = fopen( output, "rt" )
while( !feof(file) )
{
fgets( file, output, charsmax(output) )
trim( output )
if( !output[0] || output[0] == ';' )
continue
if( !match )
{
if( output[0] == '[' && equal(output[1], map, len) && output[len + 1] == ']' )
{
match = true
}
}
else
{
if( output[0] == '[' )
break
if( parse(output, origin[0], charsmax(origin[]), origin[1], charsmax(origin[]), origin[2], charsmax(origin[])) < 3 )
continue
vecOrigin[ 0 ] = str_to_float( origin[0] )
vecOrigin[ 1 ] = str_to_float( origin[1] )
vecOrigin[ 2 ] = str_to_float( origin[2] )
ArrayPushArray( aOrigins, vecOrigin )
g_originsnum++
}
}
fclose( file )
if( !g_originsnum )
{
log_amx( "%s doesn't exist in the xmas_fireworks.ini file", map )
pause( "ad" )
}
}