Think Functions
Moderator: InsideQC Admins
10 posts
• Page 1 of 1
Think Functions
I've been rehashing whats already been done... spikes that stick into walls. Figured this would be a simple way to become accustomed to using "angles" and working with "think" functions.
The "think" part is puzzling me. I'm using the standard launch_spike function and have set newmis.touch = spike_touch2;
spike_touch2 is the function that sticks the spike to a wall... works great. I shoot, the spikes stick to the wall, then, starting with the first spike, they disappear one-by-one.
Just for fun, I moved newmis.think = SUB_Remove; and newmis.nextthink = time + 6; from launch_spike to spike_touch2.
What now happens is that after several spikes are fired the first two spikes do not remove themselves. Why does this happen?
Also, I've looked at other authors code that stick spikes to walls. In their code it appears that they remove the spike when it hits the wall, then spawn a new spike at the last location of the old spike, then orient the new spike so that it is stuck to the wall. Why spawn a new spike? Is this better to do for some reason?
The "think" part is puzzling me. I'm using the standard launch_spike function and have set newmis.touch = spike_touch2;
spike_touch2 is the function that sticks the spike to a wall... works great. I shoot, the spikes stick to the wall, then, starting with the first spike, they disappear one-by-one.
Just for fun, I moved newmis.think = SUB_Remove; and newmis.nextthink = time + 6; from launch_spike to spike_touch2.
What now happens is that after several spikes are fired the first two spikes do not remove themselves. Why does this happen?
Also, I've looked at other authors code that stick spikes to walls. In their code it appears that they remove the spike when it hits the wall, then spawn a new spike at the last location of the old spike, then orient the new spike so that it is stuck to the wall. Why spawn a new spike? Is this better to do for some reason?
Good God! You shot my leg off!
-

Junrall - Posts: 191
- Joined: Mon Sep 21, 2009 12:27 am
- Location: North West Oregon, USA
you should be using self.think and such in the touch function, not newmis. maybe that's it... as newmis isn't a local entity, it's global. or whatever it's called.
-

Error - InsideQC Staff
- Posts: 865
- Joined: Fri Nov 05, 2004 5:15 am
- Location: VA, USA
Error wrote:you should be using self.think and such in the touch function, not newmis. maybe that's it... as newmis isn't a local entity, it's global. or whatever it's called.
Sorry, I forgot to mention that I did rename newmis.think and newmis.nextthink to self.think and self.nextthink.
Good God! You shot my leg off!
-

Junrall - Posts: 191
- Joined: Mon Sep 21, 2009 12:27 am
- Location: North West Oregon, USA
Yes, self and newmis (as with other pointers) shouldn't be mixed up. What's happening is you're firing a spray of spikes, and then one of them touches the wall and tells the most recently fired spike to change its nextthink & think (instead of setting its own). Easy mistake.
I like what you're doing with the spikes. Spikes sticking into the wall is a nice effect, and it's fine to do even in multiplayer so long as they disappear quickly. It would rock on monsters but Quake doesn't lend itself well to attaching entities to polys on the monster's model and following animations.
Though loading a pet dog with sticky grenades and sending it running at a shalrath is a rather nice effect nonetheless. Bwahahaha.
I like what you're doing with the spikes. Spikes sticking into the wall is a nice effect, and it's fine to do even in multiplayer so long as they disappear quickly. It would rock on monsters but Quake doesn't lend itself well to attaching entities to polys on the monster's model and following animations.
Though loading a pet dog with sticky grenades and sending it running at a shalrath is a rather nice effect nonetheless. Bwahahaha.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
- Wazat
- Posts: 771
- Joined: Fri Oct 15, 2004 9:50 pm
- Location: Middle 'o the desert, USA
Wazat wrote:Yes, self and newmis (as with other pointers) shouldn't be mixed up.
Heheh, I did use self.think and self.nextthink in my touch function. I failed to mention that in my first post
Wazat wrote: It would rock on monsters but Quake doesn't lend itself well to attaching entities to polys on the monster's model and following animations.
Yes it would rock!... probably be horrible in multiplayer as well.
Wazat wrote:Though loading a pet dog with sticky grenades and sending it running at a shalrath is a rather nice effect nonetheless. Bwahahaha.
Hahaha! Gives a whole new meaning to "Sick 'em boy!"
Good God! You shot my leg off!
-

Junrall - Posts: 191
- Joined: Mon Sep 21, 2009 12:27 am
- Location: North West Oregon, USA
Junrall wrote:Wazat wrote:Yes, self and newmis (as with other pointers) shouldn't be mixed up.
Heheh, I did use self.think and self.nextthink in my touch function. I failed to mention that in my first postThe problem with the first two nails not removing themselves persists. The fix is to keep the "think" in the launch_spike function. I was just curious why the nails weren't being removed with "think" in the touch function.
When everything else fails, remember: bprint() is your friend.
Don't be shy, place it in all key points in the code, even points you may think are useless. You may be surprised how things frequently don't work as expected during gameplay.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
@#$##%!$!!! (Banging my head against my key board... I think the "L" stuck to my forehead)
I'm such a dolt! I was sure I renamed newmis to self in my touch function. I must have hit "undo" or just plain missed it
Here are the two functions. Take note of the last line in spike_touch2.
Error and Wazat... you were right. I fixed my mistake and all is well.
I'm such a dolt! I was sure I renamed newmis to self in my touch function. I must have hit "undo" or just plain missed it
Here are the two functions. Take note of the last line in spike_touch2.
Error and Wazat... you were right. I fixed my mistake and all is well.
- Code: Select all
void() spike_touch2 =
{
if (other.solid == SOLID_TRIGGER)
return;
if (pointcontents(self.origin) == CONTENT_SKY)
{
remove(self);
return;
}
// hit something that bleeds
if (other.takedamage)
{
spawn_touchblood (9);
T_Damage (other, self, self.owner, 9);
if (other.health <= 0 && other != world)
other.solid = SOLID_NOT;
remove(self);
}
else
{
WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
WriteByte (MSG_BROADCAST, TE_SPIKE);
WriteCoord (MSG_BROADCAST, self.origin_x);
WriteCoord (MSG_BROADCAST, self.origin_y);
WriteCoord (MSG_BROADCAST, self.origin_z);
self.angles = vectoangles(self.velocity);
setorigin (self, self.origin + v_forward * -8);
self.avelocity = '0 0 0';
self.velocity = '0 0 0';
self.think = SUB_Remove;
newmis.nextthink = time + 6; <--------AAAAARRRG! Should be self.nextthink!!
}
};
- Code: Select all
void(vector org, vector dir) launch_spike =
{
newmis = spawn ();
newmis.owner = self;
newmis.movetype = MOVETYPE_FLYMISSILE;
newmis.solid = SOLID_BBOX;
newmis.angles = vectoangles(dir);
newmis.touch = spike_touch2;
newmis.classname = "spike";
//newmis.think = SUB_Remove;
//newmis.nextthink = time + 6;
setmodel (newmis, "progs/spike.mdl");
setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);
setorigin (newmis, org);
newmis.velocity = dir * 1000;
};
Good God! You shot my leg off!
-

Junrall - Posts: 191
- Joined: Mon Sep 21, 2009 12:27 am
- Location: North West Oregon, USA
Junrall wrote:@#$##%!$!!! (Banging my head against my key board... I think the "L" stuck to my forehead)
I'm such a dolt! I was sure I renamed newmis to self in my touch function. I must have hit "undo" or just plain missed it
Here are the two functions. Take note of the last line in spike_touch2.
Error and Wazat... you were right. I fixed my mistake and all is well.
Yay! Glad to help.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
- Wazat
- Posts: 771
- Joined: Fri Oct 15, 2004 9:50 pm
- Location: Middle 'o the desert, USA
-

Error - InsideQC Staff
- Posts: 865
- Joined: Fri Nov 05, 2004 5:15 am
- Location: VA, USA
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest