Headshot/Legshot message
Headshot/Legshot message
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.
Any ideas? Thanks.
[color=#FF0000]/callvote kick all_enemies[/color]
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Headshot/Legshot message
There are (at least) two solutions to this problem. Simple:
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.
Code: Select all
trap_SendServerCommand(client - level.clients, "cp \"Headshot!\n\"");
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);
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Headshot/Legshot message
Note I only mentioned how to implement headshot messages but the same advice applies to locational damage, of course.
Re: Headshot/Legshot message
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?
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?
[color=#FF0000]/callvote kick all_enemies[/color]
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Headshot/Legshot message
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
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
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

[color=#FF0000]/callvote kick all_enemies[/color]
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Headshot/Legshot message
Post the entire function, please. A hunch: did you initialize ent?
Re: Headshot/Legshot message
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]
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Headshot/Legshot message
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
uh, oh...
LOL!
I finally got it
Works perfectly now.
Thanks to misantropia
LOL!
I finally got it

Works perfectly now.

[color=#FF0000]/callvote kick all_enemies[/color]