Page 1 of 1
calling a function when a missile hits something?
Posted: Wed Dec 03, 2008 11:41 am
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
Isn't there any other possibility to do this?
Re: calling a function when a missile hits something?
Posted: Wed Dec 03, 2008 12:42 pm
by ^misantropia^
I don't get what the problem is. Are ent and self different types?
Re: calling a function when a missile hits something?
Posted: Wed Dec 03, 2008 2:14 pm
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" ???!!!???
Re: calling a function when a missile hits something?
Posted: Wed Dec 03, 2008 2:47 pm
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?
Re: calling a function when a missile hits something?
Posted: Wed Dec 03, 2008 3:08 pm
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

Re: calling a function when a missile hits something?
Posted: Wed Dec 03, 2008 4:09 pm
by ^misantropia^
Rawing wrote:I can't call it like "G_KillRadius( ent );" can I?
Did you
actually try it?
Re: calling a function when a missile hits something?
Posted: Wed Dec 03, 2008 4:57 pm
by Rawing
Of course I did

There was an error message I don't remember it any more.
Re: calling a function when a missile hits something?
Posted: Thu Dec 04, 2008 6:35 am
by ^misantropia^
FFS, reproduce it.
Re: calling a function when a missile hits something?
Posted: Thu Dec 04, 2008 5:16 pm
by Rawing
warning: declaration of 'G_KillRadius' does not match previous declaration at g_missile.c: 286
Re: calling a function when a missile hits something?
Posted: Fri Dec 05, 2008 2:17 pm
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.
Re: calling a function when a missile hits something?
Posted: Tue Dec 09, 2008 1:40 pm
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

Re: calling a function when a missile hits something?
Posted: Wed Dec 10, 2008 6:45 am
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.
Re: calling a function when a missile hits something?
Posted: Wed Dec 10, 2008 4:50 pm
by Rawing
lol, I know you answered; it's already sorted out

thankx btw
