Veteran Member
Join Date: Feb 2016
Location: brazil
|
03-02-2019
, 11:27
Re: Custom smoke
|
#2
|
Quote:
Originally Posted by uselessguy28
Hello there,
I need some help with making a custom smoke grenade. I mean, when it explodes, the smoke is a custom sprite. I've found this plugin by xPaw a made some adjustments as shown here:
PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#define VERSION "1.1"
new const g_szClassname[] = "colored_smokenade";
new g_szSmokeSprites;
new g_Cvar_Enabled;
public plugin_init( ) {
register_plugin( "Colored Smoke", VERSION, "xPaw" );
register_cvar( "colored_smoke", VERSION, FCVAR_SERVER | FCVAR_SPONLY );
set_cvar_string( "colored_smoke", VERSION );
g_Cvar_Enabled = register_cvar( "sv_colored_smoke", "1" );
register_forward( FM_EmitSound, "FwdEmitSound" );
register_touch( g_szClassname, "worldspawn", "FwdTouch_FakeSmoke" );
register_think( g_szClassname, "FwdThink_FakeSmoke" );
}
public logevent_round_end()
{
// cleanup, copied from some other plugin
new ent = -1
while((ent = find_ent_by_class(ent, g_szClassname)))
{
remove_entity( ent );
}
}
public plugin_precache( ) {
g_szSmokeSprites = precache_model( "sprites/gas_puff_01g.spr" );
precache_sound( "weapons/grenade_hit1.wav" );
}
public FwdEmitSound( iOrigEnt, iChannel, const szSample[], Float:fVol, Float:fAttn, iFlags, iPitch ) {
new iCvar = get_pcvar_num( g_Cvar_Enabled );
if( iCvar > 0 ) {
static const szSmokeSound[] = "weapons/sg_explode.wav";
if( equal( szSample, szSmokeSound ) ) {
// cache origin, angles and model
new Float:vOrigin[ 3 ], Float:vAngles[ 3 ], szModel[ 64 ], iOwner;
iOwner = entity_get_edict( iOrigEnt, EV_ENT_owner );
entity_get_vector( iOrigEnt, EV_VEC_origin, vOrigin );
entity_get_vector( iOrigEnt, EV_VEC_angles, vAngles );
entity_get_string( iOrigEnt, EV_SZ_model, szModel, charsmax( szModel ) );
// remove entity from world
entity_set_vector( iOrigEnt, EV_VEC_origin, Float:{ 9999.9, 9999.9, 9999.9 } );
entity_set_int( iOrigEnt, EV_INT_flags, FL_KILLME );
// create new entity
new iEntity = create_entity( "info_target" );
if( iEntity > 0 ) {
entity_set_string( iEntity, EV_SZ_classname, g_szClassname );
entity_set_origin( iEntity, vOrigin );
entity_set_vector( iEntity, EV_VEC_angles, vAngles );
entity_set_int( iEntity, EV_INT_movetype, MOVETYPE_TOSS );
entity_set_int( iEntity, EV_INT_solid, SOLID_BBOX );
entity_set_float( iEntity, EV_FL_nextthink, get_gametime( ) + 21.5 );
entity_set_float( iEntity, EV_FL_gravity, 0.5 );
entity_set_float( iEntity, EV_FL_friction, 0.8 );
entity_set_model( iEntity, szModel );
new Float:vVelocity[ 3 ];
vVelocity[ 0 ] = random_float( -220.0, 220.0 );
vVelocity[ 1 ] = random_float( -220.0, 220.0 );
vVelocity[ 2 ] = random_float( 200.0, 300.0 );
entity_set_vector( iEntity, EV_VEC_velocity, vVelocity );
emit_sound( iEntity, iChannel, szSample, fVol, fAttn, iFlags, iPitch );
// Create fake smoke
new iSmoke;
if( iCvar == 2 )
iSmoke = get_user_team( iOwner ); // i did indexes as team, 1 - red, 2 - blue, 3 - green( spec oO )
else
iSmoke = random_num( 0, 5 );
// Store the smoke number in entity, we will use it later
entity_set_int( iEntity, EV_INT_iuser4, iSmoke );
message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
write_byte( TE_FIREFIELD );
engfunc( EngFunc_WriteCoord, vOrigin[ 0 ] ); //startpos
engfunc( EngFunc_WriteCoord, vOrigin[ 1 ] );
engfunc( EngFunc_WriteCoord, vOrigin[ 2 ] + 50 );
write_short( 90 ); //spread
write_short( g_szSmokeSprites ); //sprite
write_byte( 150 ); //not scale
write_byte( TEFIRE_FLAG_ALPHA );
write_byte( 1000 ); //time
message_end();
message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
write_byte( TE_FIREFIELD );
engfunc( EngFunc_WriteCoord, vOrigin[ 0 ] ); //startpos
engfunc( EngFunc_WriteCoord, vOrigin[ 1 ] );
engfunc( EngFunc_WriteCoord, vOrigin[ 2 ] + 50 );
write_short( 110 ); //spread
write_short( g_szSmokeSprites ); //sprite
write_byte( 150 ); //not scale
write_byte( TEFIRE_FLAG_ALPHA );
write_byte( 1000 ); //time
message_end( );
}
}
}
}
public FwdTouch_FakeSmoke( iEntity, iWorld ) {
if( !is_valid_ent( iEntity ) )
return PLUGIN_CONTINUE;
// Bounce sound
emit_sound( iEntity, CHAN_VOICE, "weapons/grenade_hit1.wav", 0.25, ATTN_NORM, 0, PITCH_NORM );
new Float:vVelocity[ 3 ];
entity_get_vector( iEntity, EV_VEC_velocity, vVelocity );
if( vVelocity[ 1 ] <= 0.0 && vVelocity[ 2 ] <= 0.0 ) {
new Float:vOrigin[ 3 ];
new iSmoke = entity_get_int( iEntity, EV_INT_iuser4 );
entity_get_vector( iEntity, EV_VEC_origin, vOrigin );
// Make small smoke near grenade on ground
message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
write_byte( TE_FIREFIELD );
engfunc( EngFunc_WriteCoord, vOrigin[ 0 ] );
engfunc( EngFunc_WriteCoord, vOrigin[ 1 ] );
engfunc( EngFunc_WriteCoord, vOrigin[ 2 ] + 10 );
write_short( 2 );
write_short( g_szSmokeSprites );
write_byte( 2 );
write_byte( TEFIRE_FLAG_ALLFLOAT | TEFIRE_FLAG_ALPHA );
write_byte( 30 );
message_end();
}
return PLUGIN_CONTINUE;
}
public FwdThink_FakeSmoke( iEntity ) {
if( !is_valid_ent( iEntity ) )
return PLUGIN_CONTINUE;
remove_entity( iEntity );
return PLUGIN_CONTINUE;
}
Now my question is - is it possible to make the entities (sprites, idk) bigger ? They're quite small compared to the default smoke.
And also, is there possibly any way to remove the smoke on a new round?
I've also included the custom smoke sprite, just in case.
Thanks in advance.
|
There is already a fixed version by bionext
PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#if !defined write_coord_f
#define write_coord_f(%1) engfunc( EngFunc_WriteCoord, %1 )
#endif
#define VERSION "1.06"
#define SMOKE_SPRITE "sprites/gas_puff_gray_opaque.spr"
new const g_szClassname[] = "custom_smoke";
new g_fwid
new g_evCreateSmoke;
new g_szSmokeSprite;
new g_Cvar_Enabled;
new g_Cvar_Duration;
new g_Cvar_CountSprites;
new g_Clear;
new g_iCvar_Enebled;
new g_iCountSprites;
public plugin_init( )
{
register_plugin( "Custom Smoke", VERSION, "bionext" );
g_Clear = 0;
g_iCvar_Enebled = 0;
g_Cvar_Enabled = register_cvar( "sv_customsmoke", "1" );
g_Cvar_Duration = register_cvar( "sv_smokeduration", "10.0" );
g_Cvar_CountSprites = register_cvar( "sv_smokespritescount", "100" );
unregister_forward(FM_PrecacheEvent, g_fwid, 1);
register_think( g_szClassname, "FwdThink_BlackSmoke" );
register_forward(FM_PlaybackEvent, "FwdPlaybackEvent");
register_logevent("FwdClear", 2, "1=Round_End");
register_logevent("FwdStart", 2, "1=Round_Start");
register_event("TextMsg", "FwdClear", "a", "2=#Game_will_restart_in","2=#Game_Commencing");
}
public FwdClear( )
{
g_Clear = 1;
}
public FwdStart( )
{
g_iCvar_Enebled = get_pcvar_num( g_Cvar_Enabled );
g_Clear = 0;
}
public plugin_precache( )
{
g_szSmokeSprite = precache_model( SMOKE_SPRITE );
g_fwid = register_forward(FM_PrecacheEvent, "FwdPrecacheEvent", 1);
force_unmodified(force_exactfile, {0,0,0},{0,0,0}, SMOKE_SPRITE);
}
public FwdPlaybackEvent( iFlags , iEntity , iEventindex, Float:fDelay, Float:vOrigin[3], Float:vAngles[3], Float:fParam1, Float:fParam2, iParam1, iParam2, iBparam1, iBparam2 )
{
if(iEventindex != g_evCreateSmoke || iBparam2 || !g_iCvar_Enebled)
return FMRES_IGNORED;
new iEnt = create_entity( "info_target" );
if( !iEnt )
return FMRES_IGNORED;
g_iCountSprites = get_pcvar_num( g_Cvar_CountSprites );
new Float:fDuration = get_pcvar_float( g_Cvar_Duration );
entity_set_string( iEnt, EV_SZ_classname, g_szClassname );
entity_set_float( iEnt, EV_FL_nextthink, get_gametime( ));
entity_set_vector( iEnt, EV_VEC_origin, vOrigin );
entity_set_float( iEnt, EV_FL_animtime, fDuration );
return FMRES_SUPERCEDE;
}
public FwdPrecacheEvent(type, const name[])
{
if (equal("events/createsmoke.sc", name))
{
g_evCreateSmoke = get_orig_retval();
return FMRES_HANDLED;
}
return FMRES_IGNORED;
}
public FwdThink_BlackSmoke( iEntity )
{
if( !is_valid_ent( iEntity ) )
return PLUGIN_CONTINUE;
if( g_Clear > 0 )
{
entity_set_int( iEntity,EV_INT_flags, FL_KILLME );
return PLUGIN_CONTINUE;
}
new Float:vOrigin[3];
entity_get_vector( iEntity, EV_VEC_origin, vOrigin );
message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
write_byte( TE_FIREFIELD );
write_coord_f( vOrigin[ 0 ] );
write_coord_f( vOrigin[ 1 ] );
write_coord_f( vOrigin[ 2 ] + 50 );
write_short( 100 );
write_short( g_szSmokeSprite );
write_byte( g_iCountSprites );
write_byte( TEFIRE_FLAG_ALPHA );
write_byte( 11 );
message_end();
message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
write_byte( TE_FIREFIELD );
write_coord_f( vOrigin[ 0 ] );
write_coord_f( vOrigin[ 1 ] );
write_coord_f( vOrigin[ 2 ] + 50 );
write_short( 150 );
write_short( g_szSmokeSprite );
write_byte( 10 );
write_byte( TEFIRE_FLAG_ALPHA | TEFIRE_FLAG_SOMEFLOAT );
write_byte( 11 );
message_end( );
new Float:time = entity_get_float(iEntity,EV_FL_animtime);
time = time - 1.0;
if( time > 0.0 )
{
entity_set_float( iEntity, EV_FL_nextthink, get_gametime( ) + 1.0 );
entity_set_float( iEntity, EV_FL_animtime, time );
}
else
{
entity_set_int( iEntity,EV_INT_flags, FL_KILLME );
}
return PLUGIN_CONTINUE;
}C
|
|