Raised This Month: $ Target: $400
 0% 

[STOCK] Creating explosions by the engine


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 11-05-2010 , 14:53   [STOCK] Creating explosions by the engine
Reply With Quote #1

Here is a stock I usually use for my plugins. With this one you can create an explosion effect (dmg included only if enabled) without caching sprites, and these sh*ts.

PHP Code:
/**
 * Creates an explosion which the engine will do.
 * Note: Requieres Engine Module. Tested only on CS Steam.
 *
 * @param vecCenter                Position where the explosion should be created.
 * @param iMagnitude            Explosion size. This defines the explosion's max damage and sprite's size
 * @param iFlags                Explosion flags which you can find on hlsdk_const.inc
 * @param bDoDamage                Should do a radius damage?
 * @param bNoActivate        If this param is on true, the entity won't explode, and you must do it manually
 * @return                    Entity index on sucess, 0 on failure.
 */

stock ExplosionCreate(const Float:vecCenter[3], iMagnitudeiFlags 0bool:bDoDamage truebool:bNoActivate false)
{
    
// env_explosion entities are the ones
    // who creates explosions. So we are available
    // for using this one for creating explosions
    
new iEnt create_entity("env_explosion")
    
    if(!
iEnt// Invalid?
    
return 0
    
    
// The center of the explosion
    
entity_set_origin(iEntvecCenter)
    
    
// Key values must be only string, so we must
    // convert it from Int to String.
    
new szMagnitude[8// In explode.cpp the char size is 128 lol.
    
formatex(szMagnitudecharsmax(szMagnitude), "%3d"iMagnitude// Exactly as how the engine does it.
    
DispatchKeyValue(iEnt"iMagnitude"szMagnitude// This will modify m_iMagnitude value.
    
    // In hlsdk_const.inc you can find env_explosion's spawn flags
    
if(!bDoDamage// If you don't want to create a damage sphere, so we must only add this flag.
        
entity_set_int(iEntEV_INT_spawnflagsiFlags SF_ENVEXPLOSION_NODAMAGE)
    else
        
entity_set_int(iEntEV_INT_spawnflagsiFlags// 3rd parameter flags.
    
    // Applying some pev values, and offset modifications
    
DispatchSpawn(iEnt)
    
    if(!
bNoActivate)
        
force_use(iEntiEnt// The engine doesn't care who used it. Btw, this actives the explosion.
    
    
return iEnt

Code from explode.cpp (HLSDK, line 257):

PHP Code:
// HACKHACK -- create one of these and fake a keyvalue to get the right explosion setup
void ExplosionCreate( const Vector &center, const Vector &anglesedict_t *pOwnerint magnitudeBOOL doDamage )
{
    
KeyValueData    kvd;
    
char            buf[128];

    
CBaseEntity *pExplosion CBaseEntity::Create"env_explosion"centeranglespOwner );
    
sprintfbuf"%3d"magnitude );
    
kvd.szKeyName "iMagnitude";
    
kvd.szValue buf;
    
pExplosion->KeyValue( &kvd );
    if ( !
doDamage )
        
pExplosion->pev->spawnflags |= SF_ENVEXPLOSION_NODAMAGE;

    
pExplosion->Spawn();
    
pExplosion->UseNULLNULLUSE_TOGGLE);

You can easily use it like in this example:

PHP Code:
// HamSandwich forward "Ham_Killed" on "player"
// Called when someone killed.
public fw_Player_Killed(iVictim
{
    new 
Float:vecOrigin[3]
    
entity_get_vector(iVictimEV_VEC_originvecOrigin)
    
    
ExplosionCreate(vecOrigin100.0)

If you want to modify engine default values, check this example of how to it:

PHP Code:
// HamSandwich forward "Ham_Killed" on "player"
// Called when someone killed.
public fw_Player_Killed(iVictim
{
    new 
Float:vecOrigin[3]
    
entity_get_vector(iVictimEV_VEC_originvecOrigin)
    
    
// Registering Ham_TakeDamage fwd
    
new HamHook:hTakeDamageFwd RegisterHam(Ham_TakeDamage"player""fw_Player_TakeDamage")
    
    
// Creating explosion entity
    
new iEntId ExplosionCreate(vecOrigin100.0/* no flags */truetrue /* we must activate it manually */)
    
    
// His owner would be the victim, here is where we should
    
entity_set_edict(iEntIdEV_ENT_owneriVictim)
    
    
// Manually activation
    
force_use(iEntIdiEntId
    
    
// We don't need the Ham forward, so we must disable it
    
DisableHamForward(hTakeDamageFwd)
}

// HamSandwich forward "Ham_TakeDamage" on "player"
// Called when "in this case" someone takes damage by an explosion entity.
public fw_Player_TakeDamage(iVictimiInflictoriAttackerFloat:flDamageiDamageType)
{
    
// iVictim -> Any player on the radius
    // iInflictor -> Explosion entity
    // iAttacker -> iInflictor
    // flDamage -> Damage done
    // iDamageType -> DMG_BLAST
    
    // The attacker will be the player who got killed
    // If mp_friendlyfire cvar is off, won't do team kill
    
SetHamParamEntity(3entity_get_edict(iInflictorEV_ENT_owner))
    
    
// Fix DMG_BLAST value which does not able to send DeathMsg HUD
    
SetHamParamInteger(5DMG_GENERIC// DMG_GENERIC works fine without probles
    
    // Any code that you want to put, do it here.
    // Like restrictions for special players, etc.
    // ...

For usage, you must Copy-Paste this code to your plugin, and including "engine".

If there is something wrong, please let me know.
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross

Last edited by meTaLiCroSS; 11-08-2010 at 21:45.
meTaLiCroSS is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 11-05-2010 , 15:22   Re: [STOCK] Creating explosions by the engine
Reply With Quote #2

You have others spawn flags for this entity, why don't you let to pass directly the flags. Also it's a bad idea to remove right away the entity, there is a chance the smoke/spark won't be showed. If you look the HLSDK, the entity is removed after the smoke creation, so it will be removed automatically. Another thing is I would return the entity index if you don't remove the entity right away.
__________________

Last edited by Arkshine; 11-05-2010 at 15:30.
Arkshine is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 11-05-2010 , 15:30   Re: [STOCK] Creating explosions by the engine
Reply With Quote #3

Quote:
Originally Posted by Arkshine View Post
You have others spawn flags for this entity, why don't you let to pass directly the flags. Also it's a bad idea to remove right away the entity, there is a chance the smoke/spark won't be showed. If you look the HLSDK, the entity is removed after the smoke creation. And it will be done automatically. Another thing is I would return the entity index so.
So what you recommend me?

Also, the both things works without problems on-game...
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 11-05-2010 , 15:36   Re: [STOCK] Creating explosions by the engine
Reply With Quote #4

Sorry about the spawnflags, i've read too fastly your code, it's fine what you do.

What you should do :

- Remove remove_entity() : it will be done automatically after the smoke.
- Return the entity index : In case you need to get the index to be used later. (like with the Repeatable flag)
__________________
Arkshine is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 11-05-2010 , 15:56   Re: [STOCK] Creating explosions by the engine
Reply With Quote #5

Quote:
Originally Posted by Arkshine View Post
Sorry about the spawnflags, i've read too fastly your code, it's fine what you do.

What you should do :

- Remove remove_entity() : it will be done automatically after the smoke.
- Return the entity index : In case you need to get the index to be used later. (like with the Repeatable flag)
I was thinking exactly on that, thanks Arkshine.
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
fearAR
Veteran Member
Join Date: Oct 2010
Old 11-06-2010 , 10:30   Re: [STOCK] Creating explosions by the engine
Reply With Quote #6

Please correct it, If I kill to someone, All players explode!
fearAR is offline
Send a message via MSN to fearAR
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 11-06-2010 , 10:38   Re: [STOCK] Creating explosions by the engine
Reply With Quote #7

Quote:
Originally Posted by fearAR View Post
Please correct it, If I kill to someone, All players explode!
You're saying about the example?

That's only for the usage man.
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 11-06-2010 , 12:08   Re: [STOCK] Creating explosions by the engine
Reply With Quote #8

Problem is that damage done is DMG_BLAST, i guess it makes player explode.
You can't alter it with a stock.

Code:
	// do damage
	if ( !( pev->spawnflags & SF_ENVEXPLOSION_NODAMAGE ) )
	{
		RadiusDamage ( pev, pev, m_iMagnitude, CLASS_NONE, DMG_BLAST );
	}
What you have to do is to hook TakeDamage or Killed in your plugin and change damagebit or bGib value, or hook RadiusDamage with orpheu.

Nice stock anyway.

Doesn't engine allow force_use(entity, 0) ? (doesn't matter, just wondered).
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
dFF
sıɹɹoɥɔ ʞɔnu
Join Date: Oct 2009
Old 11-06-2010 , 12:22   Re: [STOCK] Creating explosions by the engine
Reply With Quote #9

Possible to no kill teammate ?

@ConnorMcLeod: [ENGINE] Invalid player 0 (not in-game)

@meTaLiCroSS
Code:
stock ExplosionCreate(const Float:vecCenter[3], iMagnitude, iFlags = 0, bool:bDoDamage)


Should be:
Quote:
stock ExplosionCreate( const Float:vecCenter[ 3 ], Float:iMagnitude, iFlags = 0, bool:bDoDamage )

Last edited by dFF; 11-06-2010 at 12:30.
dFF is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 11-06-2010 , 12:40   Re: [STOCK] Creating explosions by the engine
Reply With Quote #10

Quote:
Originally Posted by ConnorMcLeod View Post
Problem is that damage done is DMG_BLAST, i guess it makes player explode.
You can't alter it with a stock.

Code:
    // do damage
    if ( !( pev->spawnflags & SF_ENVEXPLOSION_NODAMAGE ) )
    {
        RadiusDamage ( pev, pev, m_iMagnitude, CLASS_NONE, DMG_BLAST );
    }
What you have to do is to hook TakeDamage or Killed in your plugin and change damagebit or bGib value, or hook RadiusDamage with orpheu.

Nice stock anyway.

Doesn't engine allow force_use(entity, 0) ? (doesn't matter, just wondered).
With DMG_BLAST does not appear the DeathMsg HUD. It's a little bit weirds, I tested some damage codes, and all of these if they are with "DMG_BLAST" included, no DeathMsg HUD appear...

About the force_use native, dFF answered you. Also, watching the "Use" call on explode.cpp, the engine does not care who activated it. I did "force_use(same, same)" because If in the 2nd parameter I put "0", will give me an error, and I don't want to use dllfunc(DLLFunc_Use, id, 0) bcoz will be the unique fm native :B

Quote:
Originally Posted by dFF View Post
Possible to no kill teammate ?

@ConnorMcLeod: [ENGINE] Invalid player 0 (not in-game)

@meTaLiCroSS
Code:
stock ExplosionCreate(const Float:vecCenter[3], iMagnitude, iFlags = 0, bool:bDoDamage)


Should be:
About team kill:

PHP Code:
RadiusDamage pevpevm_iMagnitudeCLASS_NONEDMG_BLAST 
The damage is done by the same explosion.

About the float param, I didn't understand "why" you want as float, bcoz the engine catch that keyvalue as an integer...

Right now I'm doing an example of how changing the default explosion values.
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:56.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode