Raised This Month: $100 Target: $400
 25% 

[TUT] Replace Weapon Firing Sounds


Post New Thread Reply   
 
Thread Tools Display Modes
CrazY.
Veteran Member
Join Date: May 2015
Location: Brazil [<o>]
Old 08-23-2017 , 19:36   Re: [TUT] Replace Weapon Firing Sounds
Reply With Quote #31

Here is an example, needs some conditions to avoid problems, but is the base:

Code:
public fw_UpdateClientData_Post(id, sendweapons, cd_handle) {     // Block default sounds and animation of a weapon     set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001) } public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2) {     if (((1<<eventid) != g_iEventId))         return FMRES_IGNORED;     if (!(1 <= invoker <= g_MaxPlayers))         return FMRES_IGNORED;     // PlaybackEvent (play custom sounds to all clients, don't only the owner)     playback_event(flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2);     return FMRES_SUPERCEDE; } public fw_PrecacheEvent_Post(type, const name[]) {     if (!equal("events/weapon_event.sc", name))         return;     // Precache gun event     g_iEventId |= (1<<get_orig_retval()) } public fw_Item_Deploy_Post(entity) {     new id = get_pdata_cbase(entity, 41, 4)     // Play 'draw' animation     Util_PlayWeaponAnim(id, 1)     // Play 'draw' sound     emit_sound(id, "weapons/draw.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM) } public fw_Weapon_PrimaryAttack_Post(entity) {     new id = get_pdata_cbase(entity, 41, 4)     // Play 'fire' animation     Util_PlayWeaponAnim(id, 3)     // Play 'fire' sound     emit_sound(id, "weapons/fire.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM) } stock Util_PlayWeaponAnim(id, sequence) {     entity_set_int(id, EV_INT_weaponanim, sequence)     message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = id)     write_byte(sequence)     write_byte(entity_get_int(id, EV_INT_body))     message_end() }

Last edited by CrazY.; 08-23-2017 at 19:38.
CrazY. is offline
Send a message via Skype™ to CrazY.
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 08-23-2017 , 22:19   Re: [TUT] Replace Weapon Firing Sounds
Reply With Quote #32

Quote:
Originally Posted by Depresie View Post
Still don't understand what he is explaining there..

Why would you just hook three events and do nothing ? then proceed to emit the sound on PrimaryAttack ?
I see you didn't read what I wrote to you. Too bad

I would like to see your basis about your snippet, because you're assuming it's right.

What is @CrazY. doing is called "weapon prediction removal" and it's an accurate (and expensive, wasteful) way to make client avoid completely his gun prediction, so you can safely skip shoot sound, and it also removes firing animation and bullet holes with smokes. That's why it's not a friendly way.
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-24-2017 , 04:56   Re: [TUT] Replace Weapon Firing Sounds
Reply With Quote #33

Crazy, it's not the body of the player but the body of weapon entity. It works both ways because the param is not used.
__________________
HamletEagle is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: Brazil [<o>]
Old 08-24-2017 , 12:43   Re: [TUT] Replace Weapon Firing Sounds
Reply With Quote #34

@meTaLiCroSS, ah ok, now I understand.

@HamletEagle, oh sorry, my bad. Enjoying your comment, I see that sometimes a few sprites pops up in the weapons I used this procedure. I believe the problem should be in this stock haha
CrazY. is offline
Send a message via Skype™ to CrazY.
[email protected]
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 08-24-2017 , 21:09   Re: [TUT] Replace Weapon Firing Sounds
Reply With Quote #35

Quote:
Originally Posted by CrazY. View Post
Hook FM_UpdateClientData (Post) and set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001);
Better just to use some value, about 2 and bigger.

Quote:
Originally Posted by CrazY. View Post
Code:
// PlaybackEvent (play custom sounds to all clients, don't only the owner) playback_event(flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2); return FMRES_SUPERCEDE;
??? Why not just block it? Actually it will send event only for invoker and only if he has cl_lw 0.

Quote:
Originally Posted by HamletEagle View Post
It works both ways because the param is not used.
It is used in svc_weaponanim and it actually works. Looks like you mean Ham_Weapon_SendWeaponAnim.
__________________

Last edited by [email protected]; 08-24-2017 at 21:33.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
CrazY.
Veteran Member
Join Date: May 2015
Location: Brazil [<o>]
Old 08-24-2017 , 22:08   Re: [TUT] Replace Weapon Firing Sounds
Reply With Quote #36

Quote:
Originally Posted by [email protected] View Post
Better just to use some value, about 2 and bigger.
Why that statement exactly?

Quote:
Originally Posted by [email protected] View Post
??? Why not just block it? Actually it will send event only for invoker and only if he has cl_lw 0..
Hm, probably you're right, I'm too lazy to update the code now.

Quote:
Originally Posted by [email protected] View Post
It is used in svc_weaponanim and it actually works. Looks like you mean Ham_Weapon_SendWeaponAnim.
Ham_Weapon_SendWeaponAnim do the same thing of the stock Util_PlayWeaponAnim?
CrazY. is offline
Send a message via Skype™ to CrazY.
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 08-25-2017 , 17:11   Re: [TUT] Replace Weapon Firing Sounds
Reply With Quote #37

Quote:
Originally Posted by CrazY. View Post
Why that statement exactly?



Hm, probably you're right, I'm too lazy to update the code now.



Ham_Weapon_SendWeaponAnim do the same thing of the stock Util_PlayWeaponAnim?
Because delay between server and client can be higher than 0.1, so client would not have a real reload sensation.

You should not keep reusing code you see on internet. That playback event trick is an useless snippet.

Yeah, both are the same, but you can hook one with extra addons. That's a good coding habit.

--

Clarifying:

Quote:
// PlaybackEvent (play custom sounds to all clients, don't only the owner)
playback_event(flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2);
return FMRES_SUPERCEDE;
Don't know who started with this **trick** (dias maybe?), but it's some kind of HIV virus. Original flag param has the FEV_NOTHOST flag, then you're setting FEV_HOSTONLY, so I guess he was high as f*ck. Then, everybody started copying their addons with this. Sad
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross

Last edited by meTaLiCroSS; 08-25-2017 at 17:16.
meTaLiCroSS is offline
[email protected]
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 08-25-2017 , 17:24   Re: [TUT] Replace Weapon Firing Sounds
Reply With Quote #38

Quote:
Originally Posted by CrazY. View Post
Why that statement exactly?
I meant that it is not gametime based. So instead of 'get_gametime() + const' you can just put 'const', but this const should be equal or bigger than the biggest delay between client and server, so 2 seconds should be ok, but you can put any value bigger than 2 for reliability.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
CrazY.
Veteran Member
Join Date: May 2015
Location: Brazil [<o>]
Old 08-25-2017 , 18:01   Re: [TUT] Replace Weapon Firing Sounds
Reply With Quote #39

Well, I do not know exactly what plugin I extract that part of the code but it was in a time that I did not know how much haha

Oh yes, now I understand, thanks for the explanations, but anyway, I can't think of any other way to do that... what about you?

Last edited by CrazY.; 08-25-2017 at 18:02.
CrazY. is offline
Send a message via Skype™ to CrazY.
Old 08-30-2017, 02:26
Depresie
This message has been deleted by Depresie. Reason: nevermind
Reply


Thread Tools
Display Modes

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 16:36.


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