Gun Smoke effect Created 6 years ago2017-06-13 20:46:04 UTC by abbadon abbadon

Created 6 years ago2017-06-13 20:46:04 UTC by abbadon abbadon

Posted 6 years ago2017-06-13 20:47:07 UTC Post #335453
Hi all of you. I am trying to add the effect of a gun that smokes when overheated. The code compiles fine, the weapon on which I have added the code works fine, but the effect won´t show. What I have done is:

1st. Include explode.h into the weapon´s includes.
2nd. In the Primary and Secondary fire function I added...

[quote]
if ( m_iHeat >= 200 )

{
#ifndef CLIENT_DLL//Whitout it cl.dll won´t compile!!
// lots of smoke
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_SMOKE );
WRITE_COORD( RANDOM_FLOAT( pev->absmin.x, pev->absmax.x ) );
WRITE_COORD( RANDOM_FLOAT( pev->absmin.y, pev->absmax.y ) );
WRITE_COORD( pev->origin.z);
WRITE_SHORT( g_sModelIndexSmoke );//Tried m_iSpriteTexture
WRITE_BYTE( 25 ); // scale * 10
WRITE_BYTE( 10 ); // framerate
MESSAGE_END();
#endif
}
[/quote]

...which is directly taken from turret.cpp

Any ideas?. If I put it on the main conditional of the overheat code (thanks Solokiller and Shepard ;) ) the game crashes. :(

I remember of it have worked in the first attempts I did on 2007 or 2008, but the smoke covered the player, it does not exit from the gun.

Then I discarded the code because the effect was shown when the ammo was less of 100 instead of happening when a certain number of degrees celsius overheated the weapon.

Pity I do not remember what I did to make this code work, 10 years are a lot to remember something like that... :(
Nowadays, if I try to put it on the primary or secondary fire function outside the conditional of above, the game crashes or freezes (remember, abbadon coding skills = 0.5 ). XD

Thanks in anticipation. :)
Posted 6 years ago2017-06-13 21:52:59 UTC Post #335457
You should use the owning player for positions, the weapon itself will likely have the wrong position and its size is probably 0. Use GetGunPosition, i'm sure there's code to get the exact position in some of the other weapons in the SDK.
Posted 6 years ago2017-06-13 22:18:34 UTC Post #335458
The problem is that I can´t see any smoke :/ , but, will it work if I try to add GetGunPosition inside the "()"...
WRITE_COORD( GetGunPosition );
[quote]

Nevermind, I tried ;)

1st. 1 error because GetGunPosition was not declared
2nd. Added basemonster.h in the includes
3rd. 1 error sayng that it is still not declared...
4th. Tried to declare it as vector vecSrc = m->pPlayer GetGunPosition(more or less) copied from the very weapon´s cpp.
5th. 1 error saying it cannot convert from float to vector.
6th. Smashed my head on the keyboard, realized my limitations and quited to continue with the last touch-ups.

:crowbar:
:walter:

Btw:
Any ideas?. If I put it on the main conditional of the overheat code (thanks Solokiller and Shepard wink-wink - ;) ) the game crashes. unhappy - :(
I know that overheat code is (c) Shepard, but I consider that Overheat is together with the "reload call" (c) Solokiller a whole which made this mod as it is now, so I always thank them every time I can. :)
Posted 6 years ago2017-06-14 05:40:08 UTC Post #335464
Try this:
Vector vecSrc = m_pPlayer->GetGunPosition();

WRITE_COORD( vecSrc.x );
WRITE_COORD( vecSrc.y );
WRITE_COORD( vecSrc.z );
That should put the smoke right in the middle of the gun.
Posted 6 years ago2017-06-14 12:37:56 UTC Post #335470
Hi again!!. I have tried your solution, but, unfortunately it still won´t show the smoke. :(

Here´s the code:
[quote]
if ( m_iHeat >= 200 )
{
Vector vecSrc = m_pPlayer->GetGunPosition();

// lots of smoke
 MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
 WRITE_BYTE ( TE_SMOKE );
 WRITE_COORD( RANDOM_FLOAT( pev->absmin.x, pev->absmax.x ) );
 WRITE_COORD( RANDOM_FLOAT( pev->absmin.y, pev->absmax.y ) );
 WRITE_COORD( vecSrc.x );
 WRITE_COORD( vecSrc.y );
 WRITE_COORD( vecSrc.z );
 WRITE_SHORT( m_iSpriteTexture );
 WRITE_BYTE ( 2 ); [green]// life[/green]
 WRITE_BYTE ( 25 ); [green]// scale * 10[/green]
 WRITE_BYTE ( 10);  [green]// framerate[/green]
 MESSAGE_END();
}
[/quote]

The code compiles and the weapons works fine :) . I´ll bet you I did something wrong misplacing the vectors, the fact is that I don´t know where I failed this time...
Posted 6 years ago2017-06-14 14:10:33 UTC Post #335479
You're supposed to replace the WRITE_COORD calls, not add to them. TE_SMOKE has these parameters:
#define TE_SMOKE 5 // alphablend sprite, move vertically 30 pps
// coord coord coord (position)
// short (sprite index)
// byte (scale in 0.1's)
// byte (framerate)
It looks like you're passing in a parameter that doesn't exit: life isn't present for this message.
Posted 6 years ago2017-06-14 15:03:01 UTC Post #335481
Done!!...no luck. :(
[quote]
if ( m_iHeat >= 200 )
{
Vector vecSrc = m_pPlayer->GetGunPosition();
[green]// lots of smoke[/green]
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_SMOKE );
WRITE_COORD( vecSrc.x );
WRITE_COORD( vecSrc.y );
WRITE_COORD( vecSrc.z );
WRITE_SHORT( m_iSpriteTexture );
WRITE_BYTE( 25 ); [green]// scale * 10[/green]
WRITE_BYTE( 10);  [green]// framerate[/green]
MESSAGE_END();
}
[/quote]

Sure my fault, just see what I´ve done before. I did check if the sprite was precached (check!) and if it is in the sprites folder (check!).
Posted 6 years ago2017-06-14 15:35:31 UTC Post #335484
Try using the player's origin with a bit of offset so it's in front of you. If it still doesn't show then then something else is wrong.
Posted 6 years ago2017-06-14 20:33:31 UTC Post #335492
Tried again!, and... still no luck... :pwned:

I tried adding (+) values, multiply vecScr by values (As in the code below), even substracting (-) values...
[quote]
if ( m_iHeat >= 200 )
{
Vector vecSrc = m_pPlayer->pev->origin;
[green]// lots of smoke[/green]
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_SMOKE );
WRITE_COORD( vecSrc.x * 10 );
WRITE_COORD( vecSrc.y * 10 );
WRITE_COORD( vecSrc.z * 10 );
WRITE_SHORT( m_iSpriteTexture );
WRITE_BYTE( 25 ); [green]// scale * 10[/green]
WRITE_BYTE( 10);  [green]// framerate[/green]
MESSAGE_END();
}
[/quote]

What´s more incredible is that today also I found myself again in trouble with the map of the menu background, if I add cyclers, monster_generic in a certain number (sometimes 5, sometimes only 2) some effects dissapear... :nuts:
Posted 6 years ago2017-06-15 06:17:06 UTC Post #335502
Adding multipliers just makes it harder to see, so that won't help.
Can you show me what value you initialize m_iSpriteTexture to, and where you're doing this?

The other issue sounds like you have too many entities and/or effects at once.
Posted 6 years ago2017-06-15 12:13:59 UTC Post #335512
Ok, now I am not at home (I am using a smartphone to write), but I will post the whole code. The other problem is extrange because the smokes won't dissapear on normal gameplay with a hundred sentinels flying around, explosions and tracers coming from 31 bots and me :)

And I have also removed things like lights and other entities like the scripted sequences, explosion and shake effects, to reduce the entity count... :\

Haha, again at home ;)

Here´s where I initialized the sprite:
void CTwohand::Precache( void )
{
PRECACHE_MODEL("models/v_twohand.mdl");
PRECACHE_MODEL("models/w_twohand.mdl");
PRECACHE_MODEL("models/p_twohand.mdl");

m_iShell = PRECACHE_MODEL ("models/shell.mdl");// brass shellTE_MODEL
PRECACHE_MODEL("models/w_9mmARclip.mdl");
PRECACHE_SOUND("items/9mmclip1.wav");
PRECACHE_SOUND("items/clipinsert1.wav");
PRECACHE_SOUND("items/cliprelease1.wav");
PRECACHE_SOUND ("weapons/hks1.wav");// H to the K
PRECACHE_SOUND ("weapons/hks2.wav");// H to the K
PRECACHE_SOUND ("weapons/hks3.wav");// H to the K
PRECACHE_SOUND ("weapons/357_cock1.wav");
m_usTwohand = PRECACHE_EVENT( 1,"events/twohand.sc");
m_usTwohand2 = PRECACHE_EVENT( 1,"events/twohand2.sc");
m_iSpriteTexture = PRECACHE_MODEL("sprites/smoke.spr");//Here it is initialized, Solokiller. ;)
}
Posted 6 years ago2017-06-15 19:12:13 UTC Post #335528
Try using MSG_ALL instead of MSG_BROADCAST. If it still doesn't show you should verify that the code is actually being executed.
Posted 6 years ago2017-06-15 21:16:52 UTC Post #335529
Hi!!, tried, but MSG_ALL does not work, but what is more extrange is that the code is not executed, I put...
ALERT( at_console, "Smoke!!!\n" );
...inside the function, but the message does not show in the console neither in the log of the mod.

Tried also MSG_PVS (don´t know much what it does, but the FEMP weapon has it in the part of the code that draws the shockwaves).

I have also put the code into the original part which´s controlling the m_iHeat part, this way:
if(m_iHeat>=200)
{//New Bracket
{original code here}
{my code here}
}//New Bracket
Now the game does not crash or locks up ( :nuts: ?) , but it does not work either.

I don´t know what is happening. The code is more or less the same as in the FEMP countermeasure, and there the effect is shown flawlessly. I am sure that someting I did is not right, but blow me if I know where I screwed it this time... :(
Posted 6 years ago2017-06-15 21:18:49 UTC Post #335532
I can't say without seeing the rest of the weapon's code. Are you sure the condition can be true to begin with? Maybe heat is being clamped to a value less than 200 somewhere else, or the method this code is in is never called.
Posted 6 years ago2017-06-15 21:36:34 UTC Post #335536
Mmmm, I don´t know 100%; the code of the weapon is exactly as the code you have (the source previous to the reload call and the overheat code), but if you want I can send to you the link to the new source and the Mod as it is actually. ;)
Posted 6 years ago2017-06-16 05:58:04 UTC Post #335543
I checked the code i have and it doesn't have the heat variable in it, so you'll have to send me the latest version.
Posted 6 years ago2017-06-16 09:44:45 UTC Post #335545
Ok. Give me a little time to pack al stuff and I will pm you with the link to the files. ;)
Posted 6 years ago2017-06-17 07:21:02 UTC Post #335559
I see what the problem is:
[quote]
if ( m_iHeat >= 200 )
{

m_flCooldownTime = gpGlobals->time + 2.0f; // Shepard : This forces the player to wait 3 seconds for the weapon to cool down
m_flNextPrimaryAttack = 3.0f;//0.15f;
return;
}

if ( m_iHeat >= 200 )
{
//Vector vecSrc = m_pPlayer->GetGunPosition();
//	#ifndef CLIENT_DLL
	Vector vecSrc = m_pPlayer->pev->origin;
// lots of smoke
MESSAGE_BEGIN( MSG_ALL, SVC_TEMPENTITY );
	WRITE_BYTE( TE_SMOKE );
	WRITE_COORD( vecSrc.x );
	WRITE_COORD( vecSrc.y );
	WRITE_COORD( vecSrc.z );
WRITE_SHORT( m_iSpriteTexture );
	WRITE_BYTE( 25 ); // scale * 10
	WRITE_BYTE( 10);  // framerate
MESSAGE_END();
//#endif
}
[/quote]

If heat is >= 200 you return from the method. The code that handles smoke is never executed. You should merge the 2 if statements:
[quote]
if ( m_iHeat >= 200 )
{
m_flCooldownTime = gpGlobals->time + 2.0f; // Shepard : This forces the player to wait 3 seconds for the weapon to cool down
m_flNextPrimaryAttack = 3.0f;//0.15f;
//Vector vecSrc = m_pPlayer->GetGunPosition();
//	#ifndef CLIENT_DLL
	Vector vecSrc = m_pPlayer->pev->origin;
// lots of smoke
MESSAGE_BEGIN( MSG_ALL, SVC_TEMPENTITY );
	WRITE_BYTE( TE_SMOKE );
	WRITE_COORD( vecSrc.x );
	WRITE_COORD( vecSrc.y );
	WRITE_COORD( vecSrc.z );
WRITE_SHORT( m_iSpriteTexture );
	WRITE_BYTE( 25 ); // scale * 10
	WRITE_BYTE( 10);  // framerate
MESSAGE_END();
//#endif
return;
}
[/quote]

This way the smoke effects are handled when your heat is >= 200.
Posted 6 years ago2017-06-17 15:37:32 UTC Post #335561
Thanks!!, will post vídeo and pics tonight. :crowbar:

Owe you another one. :glad:
Posted 6 years ago2017-06-18 22:00:49 UTC Post #335578
Well. The code finally works!, well, being 100% accurate, the solution works, but what I was not able to do is making the smoke come from the weapon ( I am sure doing something wrong with GetGunPosition() ).

When I tried to offset the smoke in the X axis (vecSrc.x) the smoke appeared far away in front of the player. The y and z vectors seem to do little for the smoke placement, maybe the y Axis is moved a little if I substract 21 to it. :roll:

The code that I am using is this, it works, and seems to show the smoke coming from the ammo feeding system, wich is good, but it is not what I wanted. :glad:
if ( m_iHeat >= 200 )
{
m_flCooldownTime = gpGlobals->time + 2.0f;// Shepard : This forces the player to wait 3 seconds for the weapon to cool down
m_flNextSecondaryAttack = 3.0f;

#ifndef CLIENT_DLL

EMIT_SOUND(ENT(pev), CHAN_ITEM, "weapons/overheat.wav", 1, ATTN_NORM);//Sonido recalentamiento-OverHeat sound

// lots of smoke
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_SMOKE );
WRITE_COORD( RANDOM_FLOAT( pev->absmin.x, pev->absmax.x ) );
WRITE_COORD( RANDOM_FLOAT( pev->absmin.y, pev->absmax.y ) );
WRITE_COORD( pev->origin.z - 21 );
WRITE_SHORT( m_iSpriteTexture );
WRITE_BYTE( 12 );// scale * 10
WRITE_BYTE( 5); // framerate
MESSAGE_END();

#endif

return;
}
This is what it looks like. THe sprites look bad because the version of Xash3D I am using has this problem still unsolved (AFAIK).
User posted image
User posted image
Well, i hope this will be useful to someone!. :crowbar:

BTW: and VERY IMPORTANT!!, if you don´t use the #ifndef CLIENT_DLL part, the game WILL crash!!. :o
You must be logged in to post a response.