Headshot/Legshot message

Locked
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Headshot/Legshot message

Post by Rawing »

I've programmed "locational damage" (http://code3arena.planetquake.gamespy.c ... al14.shtml) but I'd like to have a message on the screen whenever I hit someone in the head and whenever I GET hit in the legs or feet. I've checked how the low ammo warning / no ammo message are done, but that's all in "cgame" directory and I can't use it in coz the locational damage is done in "game".
Any ideas? Thanks.
[color=#FF0000]/callvote kick all_enemies[/color]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Headshot/Legshot message

Post by ^misantropia^ »

There are (at least) two solutions to this problem. Simple:

Code: Select all

trap_SendServerCommand(client - level.clients, "cp \"Headshot!\n\"");
The more complex but more flexible solution involves:

1. Adding a custom event EV_HEADSHOT to the entity_event_t enum in game/bg_public.h
2. Sending the event in (for example) g_active.c or g_combat.c:

Code: Select all

G_AddEvent(ent, EV_HEADSHOT, 0);
3. Catching the event in CG_EntityEvent() in cgame/cg_event.c and show a message, play a sound, etc.
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Headshot/Legshot message

Post by ^misantropia^ »

Note I only mentioned how to implement headshot messages but the same advice applies to locational damage, of course.
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: Headshot/Legshot message

Post by Rawing »

I'm too stupid to get it right...

case LOCATION_HEAD:
trap_SendServerCommand(client - level.clients, "cp \"Headshot!\n\"");
take *= 3.0;
break;

error message when compiling: undeclared identifier client

case LOCATION_HEAD:
G_AddEvent(ent, EV_HEADSHOT, 0);
take *= 3.0;
break;

error message when compiling: undeclared identifier ent

:confused:
btw: You see the headshot message when you hit someone in the head, but how can I send a message when you get hit?
[color=#FF0000]/callvote kick all_enemies[/color]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Headshot/Legshot message

Post by ^misantropia^ »

The basic rules of C still apply. Search the code for examples of how to use trap_SendServerCommand and G_AddEvent, taking notice of where the ent and client objects come from.
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: Headshot/Legshot message

Post by Rawing »

erm... I've added these lines :

trap_SendServerCommand( client - level.clients, "cp \"Headshot!\n\"" ); and
trap_SendServerCommand( client - level.clients, "cp \"You were hit in the legs\n\"" ); at the appropriate location and
gentity_t *ent;
gclient_t *client;
client=ent->client;

That just makes the game crash when I shoot someone in the legs :shrug:
[color=#FF0000]/callvote kick all_enemies[/color]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Headshot/Legshot message

Post by ^misantropia^ »

Post the entire function, please. A hunch: did you initialize ent?
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: Headshot/Legshot message

Post by Rawing »

Code: Select all

/* 
============
G_LocationDamage
============
*/
int G_LocationDamage(vec3_t point, gentity_t* targ, gentity_t* attacker, int take) {
	vec3_t bulletPath;
	vec3_t bulletAngle;

	int clientHeight;
	int clientFeetZ;
	int clientRotation;
	int bulletHeight;
	int bulletRotation;	// Degrees rotation around client.
				// used to check Back of head vs. Face
	int impactRotation;
gentity_t *ent;
gclient_t	*client;

client = ent->client;
(...)

Code: Select all

case LOCATION_HEAD:
trap_SendServerCommand( client - level.clients, "cp \"Headshot!\n\"" );
take *= 3.0;
break;
[color=#FF0000]/callvote kick all_enemies[/color]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Headshot/Legshot message

Post by ^misantropia^ »

Like I thought. ent isn't initialized, so you enter the realm of Undefined Behaviour. Looking at the code, you probably want to use 'attacker'.
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: Headshot/Legshot message

Post by Rawing »

uh, oh...
LOL!
I finally got it :owned:
Works perfectly now.
:arrow: Thanks to misantropia
[color=#FF0000]/callvote kick all_enemies[/color]
Locked