View previous topic :: View next topic |
Author |
Message |
Junrall

Joined: 21 Sep 2009 Posts: 136 Location: North West Oregon, USA
|
Posted: Wed Feb 17, 2010 5:18 am Post subject: 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? _________________ Good God! You shot my leg off! |
|
Back to top |
|
 |
Error Inside3D Staff

Joined: 05 Nov 2004 Posts: 558 Location: VA, USA
|
|
Back to top |
|
 |
Junrall

Joined: 21 Sep 2009 Posts: 136 Location: North West Oregon, USA
|
Posted: Wed Feb 17, 2010 6:43 am Post subject: |
|
|
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! |
|
Back to top |
|
 |
Wazat
Joined: 15 Oct 2004 Posts: 732 Location: Middle 'o the desert, USA
|
Posted: Wed Feb 17, 2010 6:47 am Post subject: |
|
|
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. _________________ 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. |
|
Back to top |
|
 |
Junrall

Joined: 21 Sep 2009 Posts: 136 Location: North West Oregon, USA
|
Posted: Wed Feb 17, 2010 2:56 pm Post subject: |
|
|
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 The 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.
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! |
|
Back to top |
|
 |
Teiman
Joined: 03 Jun 2007 Posts: 309
|
Posted: Wed Feb 17, 2010 4:15 pm Post subject: |
|
|
Post the code, of at least the 3 functions, since is hard to see the problem from your words. |
|
Back to top |
|
 |
frag.machine

Joined: 25 Nov 2006 Posts: 728
|
Posted: Wed Feb 17, 2010 6:41 pm Post subject: |
|
|
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 post The 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.  _________________ frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/ |
|
Back to top |
|
 |
Junrall

Joined: 21 Sep 2009 Posts: 136 Location: North West Oregon, USA
|
Posted: Thu Feb 18, 2010 2:41 am Post subject: |
|
|
@#$##%!$!!! (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.
Code: | 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: | 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! |
|
Back to top |
|
 |
Wazat
Joined: 15 Oct 2004 Posts: 732 Location: Middle 'o the desert, USA
|
Posted: Sun Feb 21, 2010 3:34 am Post subject: |
|
|
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. |
|
Back to top |
|
 |
Error Inside3D Staff

Joined: 05 Nov 2004 Posts: 558 Location: VA, USA
|
|
Back to top |
|
 |
|