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 → FirstThingInView() is not returning valid things
FirstThingInView() is not returning valid things
2002-10-27, 1:51 AM #1
This code is from a class_cog:
Code:
potential = FirstThingInView(holo, 360, 1, 0x4);
	while(potential != -1)
	{
		jkStringClear();
		jkStringConcatAsciiString("Inside While");
		jkStringOutPut(-3, -1);
		if(potential != holo)
		{
			jkStringClear();
			jkStringConcatAsciiString("Potential found");
			jkStringOutPut(-3, -1);
			//AISetFireTarget(potential, holo);
		}
		potential = NextThingInView();
	}

It only prints:
"Inside While"
Any help would be greatly appreciated.

------------------
"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-10-27, 4:58 AM #2
Neat idea, having the hologram be the looking guy, seeing if there's any baddies around.

I see 3 major things right now. The first, I'm not so sure this is a problem, but what if there is 2 holgrams fighting for the same guy, he'd get stuck between the to, make a good romance. [http://forums.massassi.net/html/wink.gif] No real way around it. Just luck.

Secondly, in the code, increase the distance. You could/sould also check for LOS. It has to be a thing pulse (should start in a created message), and make sure you're using 'holo = GetSenderRef();'.

3rd thing, 'If(GetThingClassCog(potential) != GetSelfCog())' So just incase the holo targets a holo. Do most of these things and it should work, I think.

Post the whole code if you can't get this to work.

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

The Magician Saber System.

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

Completed
Judgement Day (HLP), My level pack
2002-10-27, 5:27 AM #3
Hmm, "Getthingclasscog(potential)" will return a cog number, not a cog string name . . . as will "Getselfcog()".. So, unless 'potential' is the same object that is bound to the calling cog, this condition will always return negative.


Also, I dont think it would be neccessary to run the second condition, checking to ensure the potential isnt the hologram. AFAIK, "Firstthinginview()" wont return the object its used on.


Oh, and, if the text is just for debugging, save some code, use 'Print()'...

------------------
I used to believe that we only want what we can't have. I was wrong. The truth is, the wonderful truth is, we only want what we think we can't have.

GBK oNline. Cogs, tuts, and total w00tage.
And when the moment is right, I'm gonna fly a kite.
2002-10-27, 5:46 AM #4
Quote:
<font face="Verdana, Arial" size="2">Originally posted by GBK:
Hmm, "Getthingclasscog(potential)" will return a cog number, not a cog string name . . . as will "Getselfcog()".. So, unless 'potential' is the same object that is bound to the calling cog, this condition will always return negative.

Also, I dont think it would be neccessary to run the second condition, checking to ensure the potential isnt the hologram. AFAIK, "Firstthinginview()" wont return the object its used on.
</font>


If you A - delete the line, or B - don't change it to the way I set it up, it won't work properly.

If the potential has the same class cog, even though its a different thing, it shall still say the potential is a holo, and stop right there. But if it doesn't have the same class cog, then it shall pass.

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

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2002-10-27, 6:13 PM #5
By memory you can only have the view angle up to 270, not 360 is it ?
2002-10-27, 6:46 PM #6
No, no, those verbs deal with actual cog ref numbers. Every cog in a level has its own ref number. Well, more than every cog, every instance of a cog. Every actor cog, no matter how many times its used in a level, they will each have their own unique cog ref number. Calling "Getselfcog()" will return that cog's ref number. NO OTHER COG in the level has that cog number, not any instance of any cog. Period.

------------------
I used to believe that we only want what we can't have. I was wrong. The truth is, the wonderful truth is, we only want what we think we can't have.

GBK oNline. Cogs, tuts, and total w00tage.
And when the moment is right, I'm gonna fly a kite.
2002-10-28, 3:01 AM #7
Sorry to post this, but I have to make a point.

This is a actor class cog. The friendlies don't attack each other!
Code:
# Jedi Knight COG Script
#
# FRIEND.COG
#
# A cog for a friendly actor.
# Kinda like Max, just better.
# Class Cog - Guard/Stationary version.
#
# [DP]
#

symbols

thing		friend				local
thing		player		nolink	local
thing		target				local
int		count=0				local

message	startup
message	killed
message	pulse

end

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

code

Startup:
	player = GetLocalPlayerThing();
	SetThingPulse(GetSenderRef(), 1);
	AIClearMode(GetSenderRef(), 0x1206);
	Return;

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

Killed:
	If(GetThingClassCog(GetSenderRef()) != GetSelfCog()) Return;
	SetThingPulse(GetSenderRef(), 0);
	AIClearMode(GetSenderRef(), 0x1206);
	AISetMode(GetSenderRef(), 0x1);
	Return;

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

Pulse:
      count = 0;
	friend = GetSenderRef();
	If(AIGetMode(friend) == 0x202) Return;		// So it keeps on the same target
	target = FirstThingInView(friend, 170, 12, 0x4);
	If((GetThingClassCog(target) == GetSelfCog())||(target == player)) target = -1;
	While((target == -1)&&(count < GetThingCount()))
	{
		target = NextThingInView();
		If(count == GetThingCount()) target = -1;
		If((GetThingClassCog(target) == GetSelfCog())||(target == player)) target = -1;
		count = count + 1;		// Incase there isn't anything in view
	}
	If(target != -1)		// If there's a target
	{
		CaptureThing(target);
		AISetFireTarget(friend, target);
		AISetMoveThing(friend, target);
		AISetLookPos(friend, GetThingPos(target));
		AISetMode(friend, 0x202);
		AIClearMode(friend, 0x1000);
	}
	Else AIClearMode(friend, 0x1206);
	Return;

end

I hear you telling me it doesn't work, but try it out GBK. Because it sure works for me.

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

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2002-10-28, 6:08 AM #8
Well, I tried it, and it doesnt work for me. Problably because 'Friend' was never really defined. Startup does NOT have a senderref. Use "Created" for that, the senderref will be the actor. And yes, it works on startup too.

------------------
I used to believe that we only want what we can't have. I was wrong. The truth is, the wonderful truth is, we only want what we think we can't have.

GBK oNline. Cogs, tuts, and total w00tage.
And when the moment is right, I'm gonna fly a kite.
2002-10-28, 9:26 AM #9
Thanks for chatching that. This cog is the non-follow version of my AI class cogs, and it looks like I frogot to change that from the origanal single thing cogs. But change it to created and it will, garenteed, work.

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

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2002-10-28, 9:58 AM #10
Too bad im 80 miles away from my computer now...till saturday...thanks for the replies meanwhile

------------------
"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-11-08, 12:07 PM #11
This is just too complicated for me. Here is the whole code I have so far:
Code:
# Jedi Knight Cog Script
# "TD-11" Hologram
# zagibu@gmx.ch

symbols

thing		holo			local
thing		hand			local
thing		potential		local

template	hologram=+hologram	local
template	hand1=+rhand1		local
template	hand2=+rhand2		local
template	hand3=+rhand3		local
template	walky=walkplayer	local

flex		randhand		local

message		created
message		timer
message		pulse

end

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

code

created:
	SetTimerEx(1, GetSenderRef(), GetThingSignature(GetSenderRef()), 1);
	Return;

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

timer:
	if(GetParam(0) == GetThingSignature(GetSenderId()))
	{
		if(GetParam(1) == 1)
		{
			holo = CreateThing(hologram, GetSenderId());
			AttachThingToThing(holo, GetSenderId());
			SetTimerEx(30, holo, GetThingSignature(holo), 2);
			SetThingModel(holo, GetThingModel(GetThingParent(GetSenderId())));

			randhand = Rand();
			if(randhand < 0.34)
				hand = FireProjectile(holo, hand1, -1, -1, '0.028 0.0216 -0.0001', '0 0 0', 1, 0x0, 0, 0);
			if(randhand >= 0.34 && randhand < 0.68)
				hand = FireProjectile(holo, hand2, -1, -1, '0.028 0.0216 -0.0001', '0 0 0', 1, 0x0, 0, 0);
			if(randhand >= 0.68)
				hand = FireProjectile(holo, hand3, -1, -1, '0.028 0.0216 -0.0001', '0 0 0', 1, 0x0, 0, 0);
			AttachThingToThing(hand, GetSenderId());

			SetThingPulse(1);
		}
		
		if(GetParam(1) == 2)
		{
			SetPulse(0);
			DetachThing(GetSenderId());
			DestroyThing(GetSenderId());
		}
	}

	Return;

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

pulse:
	PrintInt(GetSenderRef());
	PrintInt(GetSourceRef());
	Print("Pulse called");

	potential = FirstThingInView(holo, 270, 1, 0x4);
	while(potential != -1)
	{
		Print("Inside while");
		if(GetThingTemplate(potential) != hologram)
		{
			Print("Potential found");
			//AISetFireTarget(potential, holo);
		}
		potential = NextThingInView();
	}

	Return;
end

It does not print anymore...

------------------
"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-11-08, 3:10 PM #12
Here's what's wrong. First, SetThingPulse(GetSenderID(), 1);

Secondly, Under GetParam(1) == 2 should be SetThingPulse() as well.

Third, In pulse, add this as the top line. holo = GetSenderRef();

Try these and see if it works. [http://forums.massassi.net/html/wink.gif]

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

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2002-11-09, 12:31 AM #13
Hey thanks a lot. It works now. Here is the whole code:
Code:
# Jedi Knight Cog Script
# "TD-11" Hologram
# zagibu@gmx.ch

symbols

thing			holo				local
thing			hand				local
thing			potential			local

template		hologram=+hologram		local
template		hand1=+rhand1			local
template		hand2=+rhand2			local
template		hand3=+rhand3			local

flex			randhand			local

message			created
message			timer
message			pulse

end

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

code

created:
	SetTimerEx(1, GetSenderRef(), GetThingSignature(GetSenderRef()), 1);
	SetThingPulse(GetSenderRef(), 1);

	Return;

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

timer:
	if(GetParam(0) == GetThingSignature(GetSenderId()))
	{
		if(GetParam(1) == 1)
		{
			holo = CreateThing(hologram, GetSenderId());
			AttachThingToThing(holo, GetSenderId());
			SetTimerEx(30, holo, GetThingSignature(holo), 2);
			SetThingModel(holo, GetThingModel(GetThingParent(GetSenderId())));

			randhand = Rand();
			if(randhand < 0.34)
				hand = FireProjectile(holo, hand1, -1, -1, '0.028 0.0216 -0.0001', '0 0 0', 1, 0x0, 0, 0);
			if(randhand >= 0.34 && randhand < 0.68)
				hand = FireProjectile(holo, hand2, -1, -1, '0.028 0.0216 -0.0001', '0 0 0', 1, 0x0, 0, 0);
			if(randhand >= 0.68)
				hand = FireProjectile(holo, hand3, -1, -1, '0.028 0.0216 -0.0001', '0 0 0', 1, 0x0, 0, 0);
			AttachThingToThing(hand, GetSenderId());
		}
		
		if(GetParam(1) == 2)
		{
			SetThingPulse(GetSenderId(), 0);
			DetachThing(GetSenderId());
			DestroyThing(GetSenderId());
		}
	}

	Return;

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

pulse:
	holo = GetSenderRef();

	potential = FirstThingInView(holo, 270, 1, 0x4);
	while(potential != -1)
	{
		if((GetThingTemplate(potential) != hologram) && HasLOS(holo, potential))
		{
			AISetMoveThing(potential, holo);
			AISetFireTarget(potential, holo);
		}
		potential = NextThingInView();
	}

	Return;
end

I'm not sure yet if I'm going to insert an if(IsMulti) Return; statement to save some resources for MP...

Hmm. What's wrong with the spacing? It seems to be fine in Notepad...

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)

[This message has been edited by zagibu (edited November 09, 2002).]
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2002-11-10, 10:47 PM #14
The ultimate answer to any FTIV error is to rip code from Force Blinding.

That has truly l33t FTIV coding.
2002-11-11, 4:11 AM #15
You should do that. (edit - clarification of that. [http://forums.massassi.net/html/redface.gif] If(IsMulti()) Return [http://forums.massassi.net/html/wink.gif] You should also include some animations of some kind. [http://forums.massassi.net/html/wink.gif]

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

The Magician Saber System.

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

Completed
Judgement Day (HLP), My level pack

↑ Up to the top!