calling a function when a missile hits something?

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

calling a function when a missile hits something?

Post by Rawing »

I've found those two functions EF_BOUNCE and EF_BOUNCE_HALF that both are activated when any missile hits something. So, I've set up EF_KILLPLAYER (for one of my weapons) that calls a function called g_killradius:

Code: Select all

G_MissileImpact
(...)
if ( ent->s.eFlags & EF_KILLPLAYER ) {
		G_KillRadius( self );
}
But, g_killradius is called too when the missile doesn't hit anything for 3 seconds:

Code: Select all

fire_redlet
(...)
bolt->think = G_KillRadius;
The problem is, in the fire_redlet function the missile is called "*self" and in g_missileimpact it's called "*ent". I simply copied the g_killradius function, replaced the *self, gave it another name and called it in g_missileimpact:

Code: Select all

G_MissileImpact
(...)
if ( ent->s.eFlags & EF_KILLPLAYER ) {
		G_KillRadius_ef( ent );
}
This is a (quite) bad solution; everytime I change something I have to do it twice :disgust:
Isn't there any other possibility to do this?
[color=#FF0000]/callvote kick all_enemies[/color]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: calling a function when a missile hits something?

Post by ^misantropia^ »

I don't get what the problem is. Are ent and self different types?
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: calling a function when a missile hits something?

Post by Rawing »

fire_redlet, fire_grenade or others call it "*self":

Code: Select all

/*
=================
fire_redlet
=================
*/
gentity_t *fire_redlet (gentity_t [b]*self[/b], vec3_t start, vec3_t dir) {
	gentity_t	*bolt;
If I call a function from there...

Code: Select all

bolt->nextthink = level.time + 3000;
bolt->think = G_KillRadius;
g_killradius has to look like this:

Code: Select all

static void G_KillRadius( gentity_t *self ) {

In g_missileimpact it's called "*ent" and when I want to call g_killradius from here I have to write

Code: Select all

if ( ent->s.eFlags & EF_KILLPLAYER ) {
		G_KillRadius_ef( [b]ent[/b] );
}
By the way, this "if" here causes my grenades not to bounce any more >:( During compiling it says "G_KillRadius_ef doesn't match previous declaration at g_missile.c" ???!!!???
[color=#FF0000]/callvote kick all_enemies[/color]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: calling a function when a missile hits something?

Post by ^misantropia^ »

I still don't see what the problem is. ent and self are of the same type and, if I'm not mistaken, they both reference a missile entity.

Re: compilation error. Did your forward declare G_KillRadius_ef()? And if so, do the declaration and its implementation match?
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: calling a function when a missile hits something?

Post by Rawing »

you are right saying "self" and "ent" are the same type; but if it's like this...

Code: Select all

static void G_KillRadius( gentity_t *self ) {
I can't call it like "G_KillRadius( ent );" can I?

And, no, I didn't declare the function anywhere... I checked whether G_explodemissile is declared anywhere and it isn't :offended:
[color=#FF0000]/callvote kick all_enemies[/color]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: calling a function when a missile hits something?

Post by ^misantropia^ »

Rawing wrote:I can't call it like "G_KillRadius( ent );" can I?
Did you actually try it?
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: calling a function when a missile hits something?

Post by Rawing »

Of course I did :eek: There was an error message I don't remember it any more.
[color=#FF0000]/callvote kick all_enemies[/color]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: calling a function when a missile hits something?

Post by ^misantropia^ »

FFS, reproduce it.
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: calling a function when a missile hits something?

Post by Rawing »

warning: declaration of 'G_KillRadius' does not match previous declaration at g_missile.c: 286
[color=#FF0000]/callvote kick all_enemies[/color]
AnthonyJ
Posts: 130
Joined: Wed Nov 15, 2006 7:51 pm

Re: calling a function when a missile hits something?

Post by AnthonyJ »

This comes back around to the comments made some time ago - you really do need to understand C to be able to do what you're trying to do.

We can help with describing the sorts of things you might need to do, but we're not here to talk you through every line of code you write. You need to understand error messages from the compiler, and be able to read and understand the existing code.

In this case, the compiler is giving you a fairly clear description of the problem - you just need to compare the two lines of code and understand the code, and you should see the problem (if there really is one - this is just a warning, remember).

My guess would be that the warning is because you've not got a declaration of the function before you used it, and so the compiler has guessed at what you mean by the way you've used it, but not guessed that it is static. In reality, that probably makes no difference - declaring it properly, or removing the static keyword so that it guesses right would probably both stop the warning, but have no impact on how it works.
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: calling a function when a missile hits something?

Post by Rawing »

I know I don't really understand lots of the code and most of what I do is copy/paste ( but not everything :) ), but I guess I've really improved - in some parts of programming - and please, if you think I'm so stupid and don't know what I'm doing, just don't answer, ok :?:
[color=#FF0000]/callvote kick all_enemies[/color]
AnthonyJ
Posts: 130
Joined: Wed Nov 15, 2006 7:51 pm

Re: calling a function when a missile hits something?

Post by AnthonyJ »

Note that I did actually answer your problem - ie, re-stated the likely cause that misantropia mentioned above, complete with a link so you can learn about it if you do not understand what we're saying:
AnthonyJ wrote:My guess would be that the warning is because you've not got a declaration of the function before you used it, and so the compiler has guessed at what you mean by the way you've used it, but not guessed that it is static. In reality, that probably makes no difference - declaring it properly, or removing the static keyword so that it guesses right would probably both stop the warning, but have no impact on how it works.
The reason I commented on the rest is clearly misantropia was getting frustrated up a couple of comments.
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: calling a function when a missile hits something?

Post by Rawing »

lol, I know you answered; it's already sorted out :info: thankx btw :)
[color=#FF0000]/callvote kick all_enemies[/color]
Locked