Adding hitsounds


(NewName) #1

Hi guys, quick question.

Been editing the ET SDK 2.60, fixing some bugs here and there as I go along…

I’ve never had to do this, but how would I go about adding hitsounds when the client hits another client. Exactly like the current mods about now, anyone care to share?

Where does this code go?

Thank you very much.


(Indloon) #2

Hello iDan.

Got g_combat.c

Add this function

void G_Hitsound(gentity_t *targ, gentity_t *attacker, int mod, qboolean headShot) 
{
	int snd;
	gentity_t *hs_ent;

	if(!g_hitsounds.integer)
		return;

	if(!attacker->client)
		return;
	
	if(!attacker->client->pers.hitsounds)
		return;	

	if(!targ->client) 
		return;

	if( !g_friendlyFire.integer && targ->client->ps.powerups[PW_OPS_DISGUISED] && !OnSameTeam(targ, attacker)) {
		return;
	}

	if( targ->health <= 0 && attacker->s.weapon == WP_KNIFE)
		return;

	hs_ent = G_TempEntity(attacker->client->ps.origin, EV_GLOBAL_CLIENT_SOUND);
	hs_ent->s.teamNum = (attacker->client - level.clients);

	snd = G_SoundIndex("sound/hit.wav");

	if(headShot)
		snd = G_SoundIndex("sound/headshot.wav");

	if(OnSameTeam(targ, attacker) || targ->client->ps.powerups[PW_OPS_DISGUISED])	
		snd = G_SoundIndex("sound/hitteammate.wav");
	

	hs_ent->s.eventParm = snd;
}

Then go to G_Damage function and add this somewhere:


G_Hitsound(targ, attacker, mod, headShot);

And don’t forget to register g_hitsounds cmd,if you want :stuck_out_tongue:

E:Crap,forgotted
Go to g_local.h
Add

int hitsounds;

at clientPersistant_t struct.

Go to g_client.c
Add at ClientUserinfoChanged


s = Info_ValueForKey(userinfo, "cg_hitsounds");

	if (*s)
		client->pers.hitsounds = atoi(s);
	else
		client->pers.hitsounds = 1;

Now add the cg_hitsounds cvar at cg_local.h and cg_main.c


(NewName) #3

Hi Indloon, thanks for the reply.

Can the function go anywhere inside g_combat.c?

I can’t seem to find G_Damage, where abouts is this? Where shall I insert the [ G_Hitsound(targ, attacker, mod, headShot); ]
?

Looking for the clientPersistant_t struct brings back these results:

[ // the rest of the structure is private to game
clientPersistant_t pers; ]

&

[ ipFilter_t complaintips[MAX_COMPLAINTIPS];
} clientPersistant_t; ]

where does the [ int hitsounds; ] go inside here?

Also the

ClientUserinfoChanged part, where does the supplied code go?

Sorry for such idiot questions, I’m no pro obviously lol.

Thanks man, I appreciate the help.


(Indloon) #4

Yes,but before G_Damage function.

G_Damage is function what gives feedback to game where the shoot was at the hitboxes.

At ET SDK,it should be at 1004 line and starts like:
void G_Damage( gentity_t *targ, gentity_t *inflictor, gentity_t *attacker, vec3_t dir, vec3_t point, int damage, int dflags, int mod )

Add G_Hitsound(targ,attacker,mod,headShot) before

if ( targ->flags & FL_GODMODE ) {
		return;
	}

The struct clientPersistant_t is located at g_local.h after ipXPStorage_t struct.

Yes,you need to add it to struct.

And yes,the structs at cg_local/g_local/ui_local are for storing values/data.

[QUOTE=iDan;392850]
ClientUserinfoChanged part, where does the supplied code go?

[quote]

g_client.c

Just add it somewhere,it doesn’t effect the goal of that one.