Page 1 of 1
Headshot/Legshot message
Posted: Sat Nov 22, 2008 3:59 am
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.
Re: Headshot/Legshot message
Posted: Sat Nov 22, 2008 9:56 am
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:
3. Catching the event in CG_EntityEvent() in cgame/cg_event.c and show a message, play a sound, etc.
Re: Headshot/Legshot message
Posted: Sat Nov 22, 2008 10:00 am
by ^misantropia^
Note I only mentioned how to implement headshot messages but the same advice applies to locational damage, of course.
Re: Headshot/Legshot message
Posted: Sat Nov 22, 2008 10:48 am
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
btw: You see the headshot message when you hit someone in the head, but how can I send a message when you get hit?
Re: Headshot/Legshot message
Posted: Sat Nov 22, 2008 1:46 pm
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.
Re: Headshot/Legshot message
Posted: Sun Nov 23, 2008 5:35 am
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

Re: Headshot/Legshot message
Posted: Sun Nov 23, 2008 9:45 am
by ^misantropia^
Post the entire function, please. A hunch: did you initialize ent?
Re: Headshot/Legshot message
Posted: Sun Nov 23, 2008 2:34 pm
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;
Re: Headshot/Legshot message
Posted: Sun Nov 23, 2008 3:36 pm
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'.
Re: Headshot/Legshot message
Posted: Sun Nov 23, 2008 4:33 pm
by Rawing
uh, oh...
LOL!
I finally got it
Works perfectly now.

Thanks to misantropia