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 → Target-Locking Cog... Need advance help...
Target-Locking Cog... Need advance help...
2002-06-13, 5:12 AM #1
I'm trying to make a cog that, when you activate it, it creates the targetting reticle. If you release the key, it leaves the reticle on the enemy, and makes you look only toward it... The problem is, there's gotta be a problem with the syntax, because it doesn't even show the initial message... here it is (i don't know how to do it in UBB)

# ITEM_TARGETLOCK.COG
# Looks around for an enemy to lock on to,
# then keeps the player centered around the
# enemy for the time the hotkey is used.
#
# By Darth Reed, darthreed@earthlink.net
#
# This cog is not made or supported by LucasArts Entertainment Company.

symbols

int player local
int potential local
int victim local
int lockedon=0 local

flex maxdist=3 local

vector playerlook local
vector victimlook local
vector lockedlook local

message startup
message activated
message deactivated
message pulse
message user1

end

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

code

startup:

player = GetLocalPlayerThing();

return;

# ........................................................................................

activated:

if(lockedon == 0)
{
Print("Locking Now...");
victim = -1;
SetPulse(0.3);
}

if(lockedon == 1)
{
call user1;
}

return;

# ........................................................................................

pulse:

if(lockedon == 1)
{
if(victim != -1)
{
playerlook = GetThingLVec(player);
victimlook = GetThingLVec(victim);
lockedlook = VectorCross(playerlook, victimlook);

SetThingLook(player, lockedlook);

if(VectorDist(GetThingPos(player), GetThingPos(victim)) > maxdist)
{
call user1;
}
}
}

if(lockedon == 0)
{
victim = -1;
potential = FirstThingInView(player, 90, 8, 2);

while(potential != -1)
{
if(potential != player)
{
victim = potential;
}

potential = NextThingInView();
}

if(victim != -1)
{
jkSetTargetColors(29, 30, 31);
jkSetTarget(victim);
}
else
{
jkEndTarget();
}
}

return;

# ........................................................................................

deactivated:

if(victim != -1)
{
lockedon = 1;
Print("Locked On!");
}
else
{
SetPulse(0);
jkEndTarget();
}

return;

# ........................................................................................

user1:

if(victim != -1)
{
SetPulse(0);
jkEndTarget();
lockedon = 0;
}

return;

# ........................................................................................

end


------------------
"We've compiled 43 songs on one CD... But it's a big one... And it's made outta chocolate!"

- Ryan Stiles of 'Whose Line Is It Anyway?'
2002-06-13, 12:30 PM #2
use parsec to check the syntax...couldn't see any errors, though. The closing UBB code tag for preformatted text is [/code]. Put that after your code block. The opening tag is
Code:
 and it has to go in front of your block.

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2002-06-13, 5:54 PM #3
Did you model it after a cog with targeting like force_choke.cog? Doesn't look right. FirstThingInView(player, 90, 8, 0x400); will work. [edit]sorry, too blunt, should've helped[/edit]

------------------
The Sniper Missions. Current project, The Sniper Missions


[This message has been edited by Descent_pilot (edited June 15, 2002).]
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2002-06-14, 5:03 AM #4
potential = FirstThingInView(player, 90, 8, 2);

Im guessing the 2 in there is for testing purposes? Because if you want to target another player you have to use:

potential = FirstThingInView(player, 90, 8, 0x400);
- Wisdom is 99% experience, 1% knowledge. -
2002-06-15, 6:58 AM #5
Your cog's syntax is correct, but make sure your cog is running. Put a sleep and then a
print in the startup message. Then make sure you've set up your hotkey correctly.

A few things:

The variable, lockedon, should be set to zero on startup. Because if you quit the
level while lockedon is 1, lockedon will be one in the beginning of the next level.
Remember that variable assigments in the symbols section are done only when the first
level is loaded.

You should use VectorSub(pos_target, pos_player); instead of your VectorCross() system.
If you don't understand it, there's a comprehensive explanation in the DataMaster.

User messages start with user0, and anyway, you shouldn't be using a user message unless
you intend to call that message from another cog. Instead, make it a custom message and
give it a descriptive name. Custom messages don't need to be listed in the symbols section.

As has been said, you should be using 0x400 or 0x404 mask flags to find targets.

You trimmed out some important code from the target-finding code your using. As it is,
you'll find dead targets, target's that you can't really see, target's you shouldn't
see, etc. That ThingViewDot() system is important.

-------------

Besides that, your overall method looks alright. You seem to have a good grasp on
what your doing. Good luck. [http://forums.massassi.net/html/wink.gif]

------------------
Author of the JK DataMaster, Parsec, and the EditPlus Cog Files.
Visit Saber's Domain.

[This message has been edited by SaberMaster (edited June 15, 2002).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-06-15, 9:27 PM #6
It's been a while, but my locking code looks very different. I remember using the LOS command for locking, and a lot more code. I . It's been a long long time, I'll see if i can find my old COG.

I pretty much cannibalized the Force powers code to get my target lock code. Sorry i can't be any more help =D
[url = "http://www.DelphiDragon.cjb.net"]The Dragon's Lair[/url]. Game Programming in Borland Delphi.
2002-06-17, 3:45 AM #7
Darth Reed, you need to compare this to force_grip.cog in Res2.gob. To really make this work you should cut and paste out of there and change whatever part of that you want, but don't delete a major line, ex. the dot lines. [http://forums.massassi.net/html/wink.gif]

------------------
The Sniper Missions. Current project, The Sniper Missions
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2002-06-17, 12:23 PM #8
Thats what I did.
[url = "http://www.DelphiDragon.cjb.net"]The Dragon's Lair[/url]. Game Programming in Borland Delphi.

↑ Up to the top!