Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Homing Rail dets
Homing Rail dets
2003-07-14, 7:01 PM #1
I saw a post about this awhile ago, but it looks like it got pruned...

Anyway, what I remember from it was the pulse message, it was something like
Code:
pulse:

   victim = FirstThinginView(player, 50, 10, 0x4FE);
   curvel = VectorScale(GetThingLVec(rail), 2.7);
   SetThingLook(rail, VectorSub(GetThingPos(victim), GetThingPos(rail)));
   lookvel = VectorScale(GetThingLVec(rail), 2.0);
   seekvel = VectorAdd(curvel, lookvel);
   SetThingVel(rocket, seekvel);

From that I have made this cog.
Code:
symbols

thing       player                           local
thing       rail                             local
thing       victim                           local

vector      curvel                           local
vector      lookvel                          local
vector      seekvel                          local

message     created
message     pulse

end

# ========================================================================================

code

created:

   SetPulse(.5);

return;
# ========================================================================================

pulse:

   player = GetSenderRef();
   rail = GetSourceRef();

   victim = FirstThinginView(player, 50, 10, 0x4FE);
   curvel = VectorScale(GetThingLVec(rail), 2.7);
   SetThingLook(rail, VectorSub(GetThingPos(victim), GetThingPos(rail)));
   lookvel = VectorScale(GetThingLVec(rail), 2.0);
   seekvel = VectorAdd(curvel, lookvel);
   SetThingVel(rail, seekvel);

return;

But It doesn't work. When I tested it, after the raildet was fired, the player started moving at different speeds and in random directions. Any ideas on how to make it work right? (Oh yeah, it's a class cog for the raildet.)

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"
2003-07-14, 8:26 PM #2
Try this:

Code:
player = GetLocalPlayerThing();
rail = GetSenderRef();


------------------
Bassoon, n. A brazen instrument into which a fool blows out his brains.
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2003-07-14, 9:18 PM #3
You'll also need to use SetThingPulse() and probably make it pulse a little more quickly. A half-second might be too long to wait.

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-07-15, 5:20 AM #4
Yeah, that too, unless you want it to home only a little, like for long ranges.

------------------
Bassoon, n. A brazen instrument into which a fool blows out his brains.
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2003-07-15, 5:48 AM #5
OK, I changed SetPulse(.5); to SetThingPulse(rail, .15); and changed player and rail to what Emon said to. Now, the player doesn't move around randomly, but the rail still doesn't seek the actor.

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"

[This message has been edited by Stormtrooper (edited July 15, 2003).]
2003-07-15, 6:25 AM #6
I fixed the homing problem, I added rail = GetSenderRef(); to the created message, but it homes on all things, not just actors. I assume that this has to do with a certain flag of some sort, bit I don't know what to change.

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"
2003-07-15, 6:44 AM #7
Code:
victim = FirstThinginView(player, 50, 10, 0x4FE);
if(GetThingType(victim) != 2 || GetThingType(victim) != 10 || GetThingType(victim) != 6) Return;


This will make it track actors, players and explosions. I assume you're doing a heat seeking weapon, so I thought it would be cool to have it track explosions as well. Also would make it less cheap by allowing players do utilize a countermeasure tactic. [http://forums.massassi.net/html/smile.gif]

Here are all thing types, courtesy of SM's DataMaster:

Quote:
<font face="Verdana, Arial" size="2">
0 Free.
1 Camera.
2 Actor.
3 Weapon.
4 Debris.
5 Item.
6 Explosion.
7 Cog.
8 Ghost.
9 Corpse.
10 Player.
11 Particle.
</font>


I also suggest you insert Sleep() before the SetThingPulse, with a value of one or two. Would look cool if the projectile took a second or two to lock onto something.

------------------
Bassoon, n. A brazen instrument into which a fool blows out his brains.
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2003-07-15, 9:20 AM #8
It's still not working, I ran it through Parsec and it says "Message expected, but return; found on line 55."

Heres the updated cog:
Code:
# Jedi Knight Cog Script
#
# SEEKRAIL.COG
#
# Seeking Rail Detonator cog.
#
# [Stormtrooper]
#
# Much thanks to Emon and SaberMaster for helping me with this.
# NOT SUPPORTED by LucasArts Entertainment Co.

symbols

thing       player                           local
thing       rail                             local
thing       victim                           local

vector      curvel                           local
vector      lookvel                          local
vector      seekvel                          local

message     created
message     pulse

end

# ========================================================================================

code

created:

   rail = GetSenderRef();

   Sleep(1);
   SetThingPulse(rail, .05);

return;
# ========================================================================================

pulse:

   player = GetLocalPlayerThing();
   rail = GetSenderRef();

   victim = FirstThinginView(player, 50, 10, 0x4FE);
   if(GetThingType(victim) != 2 || GetThingType(victim) != 10 || GetThingType(victim) != 6) Return;
   curvel = VectorScale(GetThingLVec(rail), 2.7);
   SetThingLook(rail, VectorSub(GetThingPos(victim), GetThingPos(rail)));
   lookvel = VectorScale(GetThingLVec(rail), 2.0);
   seekvel = VectorAdd(curvel, lookvel);
   SetThingVel(rail, seekvel);

return;

Any ideas?

[EDIT]Grr, I need a new keyboard [http://forums.massassi.net/html/frown.gif][/EDIT]

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"

[This message has been edited by Stormtrooper (edited July 15, 2003).]

[This message has been edited by Stormtrooper (edited July 15, 2003).]
2003-07-15, 10:17 AM #9
Well the only thing my parsec found wrong was that you are missing and 'end' after the last return. I don't see how you got an error on line 55, there are only 40 lines [http://forums.massassi.net/html/smile.gif]

------------------
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"
2003-07-15, 11:23 AM #10
Darn, I always forget that end...

Yes, it has 55 lines, the code tags take out blank lines.

Thanks.

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"
2003-07-15, 11:35 AM #11
It still doesn't work.. [http://forums.massassi.net/html/frown.gif]
Maybe it's my template?

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"

[This message has been edited by Stormtrooper (edited July 15, 2003).]
2003-07-16, 7:03 AM #12
Code:
if(GetThingType(victim) != 2 || GetThingType(victim) != 10 || GetThingType(victim) != 6) Return;


Looks like a catch-all to me, Emon. [http://forums.massassi.net/html/tongue.gif]

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-07-16, 7:57 AM #13
Here you go,
Code:
# seekrail.cog
#
# Seeking Rail Detonator class cog.
#
# [Stormtrooper + SM]
#==============================================================#
symbols

thing     player         local
thing     rail           local
thing     victim         local
thing     target         local

vector    curvel         local
vector    lookvel        local
vector    seekvel        local

flex      speed=4        local
flex      data           local
flex      dist           local
flex      lastdist       local

template  smoke=+smoke   local

message   created
message   pulse

end
#==============================================================#
code
#------------------------------------------------------
created:
	player = GetLocalPlayerThing();
	SetThingUserData(GetSenderRef(), 0.2);
	SetThingPulse(GetSenderRef(), 0.05);

Return;
#------------------------------------------------------
pulse:
	rail = GetSenderRef();
	data = GetThingUserData(rail);
	if(data > 0)
	{
		SetThingUserData(rail, data - 0.05);
	}
	else
	{
		victim = FirstThingInView(player, 50, 10, 0x404);
		lastdist = 11;
		target = -1;
		while(victim != -1)
		{
			dist = VectorDist(GetThingPos(victim), GetThingPos(rail));
			if(HasLOS(rail, victim) && dist < lastdist) target = victim;
			lastdist = dist;
			victim = NextThingInView();
		}
		if(target != -1)
		{
			curvel = VectorScale(GetThingLVec(rail), speed * 0.6);
			lookvel = VectorScale(VectorNorm(VectorSub(GetThingPos(target), GetThingPos(rail))), speed * 0.4);
			seekvel = VectorAdd(curvel, lookvel);
		}
		else seekvel = GetThingLVec(rail);
		SetThingLook(rail, seekvel);
		SetThingVel(rail, seekvel);
	}
	CreateThing(smoke, rail);

Return;
#------------------------------------------------------
end


Targeting explosions doesn't work too well. Suppose you have a stormtrooper shooting at you, each of his bryarbolt's explosions will become a target. Since they often enough land right in front of you, you'll get more damage than the stormtrooper.

As I have it, the raildet will home on the closest enemy. And instead of using a Sleep() to stop the rail from homing, I used it's userdata. So there won't be a problem if more than four raildets are fired, and smoke will be created even when it's not homing.

FTIV() isn't a great verb. It loves to find things behind walls, and sometimes it won't find things right in front you. But using FTIV() is certainly easier (and maybe better for JK) than searching through all of the things in the level.

Good luck. [http://forums.massassi.net/html/wink.gif]

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-07-16, 8:07 AM #14
W00t!!
Thank you, it worked.

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"

↑ Up to the top!