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 → New problem
New problem
2004-02-07, 4:54 AM #1
Hi!
While I wait for respons on my old problem, I do other stuff, and I have a problem.
I'm making a weapon that you place and it turns. When it sees someone, it should shoot. I've used the same piece of code as force pull would use... Actually no... I took this piece of code from the GOLEM mod's Assassin Droids. And I've edited it so it would take even actors that were immune to force targets. But there is a problem, or 2..
Code:
if(HasLOS(GetSenderRef(),potential) && (potential != GetSenderRef()) && (potential != player) && !(GetThingFlags(potential) & 0x200) && !((jkGetFlags(potential) & 0x20) && !IsInvActivated(player, 23)))

Problem 1: The HasLOS is not working. The object is targetting something on the other side of the level!
Problem 2: The object won't target droids, ATSTs, or turrets. Please help me make it so.

/Edward

If you want the whole code (weapon COG, class COG, template) Just ask!
Edward's Cognative Hazards
2004-02-07, 6:06 AM #2
Do post the whole cog.


HasLOS is funny sometimes, and its always a good idea to set a max distance...

------------------
The future is here, and all bets are off.
And when the moment is right, I'm gonna fly a kite.
2004-02-07, 6:13 AM #3
If it's targeting something on the other side of the level, try having your cog print the thing number that's being targeted. Maybe from there, you could see why it's targeting something else... or maybe not. *shrug*

------------------
"Now faith is the substance of things hoped for, the evidence of things not seen." -Hebrews 11:1
"There is one body, and one Spirit, even as ye are called in one hope of your calling; One Lord, one faith, one baptism, One God and Father of all, who is above all, and through all, and in you all. But unto every one of us[/i] is given grace according to the measure of the gift of Christ." -Ephesians 4:4-7

The Giant Internet IC Masturbator - Index of IC pinouts
Catalog of Electronic Components - Complete IC information
National Electrical Code (NEC) Online - Don't do wiring without consulting it. OR ELSE!
Catloaf, meet mouseloaf.
My music
2004-02-07, 7:07 AM #4
The whole class COG.
Code:
# Sequencer32 class COG
#
# By Edward
symbols

message		created
message		pulse

thing		seq		local
thing		player		local
thing		victim=-1	local
thing		potential=-1	local
template	damager=+line1	local
sound		fires=LASER4.WAV	local

flex		dot		local
flex		maxdot		local

end
#
code
created:
	seq=GetSenderRef();
	player=GetSourceRef();
	SetThingPulse(seq,0.1);
	ParseArg(GetSenderRef(), "angvel=(0/90/0)");
return;
pulse:
	StopThing(GetSenderRef());
	victim = -1;
	maxDot = 0;
	potential = FirstThingInView(GetSenderRef(), 180, 100, 0x404);
	while(potential != -1)
	{
		if((HasLOS(GetSenderRef(),potential)) && (potential != GetSenderRef()) && (potential != player) && !(GetThingFlags(potential) & 0x200) && !((jkGetFlags(potential) & 0x20) && !IsInvActivated(player, 23)))
		{
			dot = ThingViewDot(GetSenderRef(), potential);
			if(dot > maxDot)
			{
				victim = potential;
				maxDot = dot;
			}
		}
		potential = NextThingInView();
	}
	if(victim != -1)
	{
		jkSetTargetColors(21,22,23,24,25,26,27,28,29,30);
		jkSetTarget(victim);
		printint(victim);
		ParseArg(GetSenderRef(), "angvel=(0/0/0)");
		FireProjectile(GetSenderRef(),damager,fires,-1,'0 0 0','0 0 0',0,0x60,360,360);
	}
	else
	{
		jkEndTarget();
		ParseArg(GetSenderRef(), "angvel=(0/90/0)");
		//Rotate(GetSenderRef(),'0 90 0');
	}
return;
end

And As you see, I added a printint. I tried it in level 06 - Into the dark palace, and I fired to the first Probe Droid. It started shooting and the droid exploded, and it started shooting me, although its target was thing 18, which was a Probe Droid about 5 JKUs North. And I want this thing to fire miles away as long as it can see it.

If you need more, just say!

/Edward
Edward's Cognative Hazards
2004-02-08, 4:45 PM #5
I agree with GBK. Make the cog check the distance between the potential and the victim. If the potential's is less than the victim's, set the potential to victim. This way should get the thing closest to the weapon.

------------------
I am Darth Slaw.
The Dark Lord of the Sith,
And part of the Nightfire mod team
May the mass times acceleration be with you.
2004-02-12, 6:25 AM #6
OK, I've done some checking on stuff and I decided to take away the 'Stop Rotate' piece when it finds something, so now it rotates and shoots anything in view.
Although, before I did that, I noticed something in the numbers. They changed depending on what I saw. Imagine level 6, Into the dark Palace, you start with a probe droid, you shoot your seq. It fires at you (because of the 0x60,360,360 attribs on FireProj...) and targets thing 168. You move through the 'stable' and the target number changes to 17.
Anyway, now that it rotates all the time, it targets stuff all over the place. And I added the VectorDist() in the If statment. Same value as was assigned to the Assassin Droids from GOLEM (100).
And something else! In a sector where there were no enemies, the seq wasn't shooting. When I left the sector, it targeted thing 16, and starget to shoot. How fun! Target 16, is me! Hm... Tell me, if my projectile is the same type as force lightning (weapon disappears and creates explosion at it's destonation, leaving trailthing) and the explosion is this Sequencer, who would be the SourceRef? Me, or the projectile I shot?

/Edward
Edward's Cognative Hazards
2004-02-12, 7:05 AM #7
The most obvious problems to me are that A) Pulse message has no getsenderref, and B) You're using parsearg instead of a simple setthingrotvel. Parsearg will start giving you crap as the cog gets more complicated, and it tends to crash in MP.

Edit: Oh yeah, and jksettargetcolors() only has three parameters.

[This message has been edited by Checksum (edited February 12, 2004).]
2004-02-12, 11:58 AM #8
I see...
Comparisen:
Code:
# Sequencer32 class COG
#
# By Edward
symbols

message		created
message		pulse
message		removed

thing		seq		local
thing		player		local
thing		victim=-1	local
thing		potential=-1	local
template	damager=+line1	local
sound		fires=LASER4.WAV	local

flex		dot		local
flex		maxdot		local

end
#
code
created:
	seq=GetSenderRef();
	player=GetSourceRef();
	SetThingPulse(seq,0.1);
	ParseArg(GetSenderRef(), "angvel=(0/360/0)");
return;
pulse:
	victim = -1;
	maxDot = 0;
	potential = FirstThingInView(GetSenderRef(), 180, 100, 0x404);
	while(potential != -1)
	{
		if((HasLOS(GetSenderRef(),potential)) && (VectorDist(GetThingPos(GetSenderRef()),GetThingPos(potential)) <= 10) && (potential != GetSenderRef()) && (potential != player) && !(GetThingFlags(potential) & 0x200) && !((jkGetFlags(potential) & 0x20) && !IsInvActivated(player, 23)))
		{
			dot = ThingViewDot(GetSenderRef(), potential);
			if(dot > maxDot)
			{
				victim = potential;
				maxDot = dot;
			}
		}
		potential = NextThingInView();
	}
	if(victim != -1)
	{
		jkSetTargetColors(21,22,23,24,25,26,27,28,29,30);
		jkSetTarget(victim);
		printint(victim);
		FireProjectile(GetSenderRef(),damager,fires,-1,'0 0 0','0 0 0',0,0x60,360,360);
	}
	else
	{
		jkEndTarget();
		//Rotate(GetSenderRef(),'0 90 0');
	}
return;
end

Code:
symbols

thing        player                             local                         
thing        victim                             local                         
thing        potential                          local                         

flex         dot                                local                         
flex         maxDot                             local                         

template     bolt=+onebolt                      local

int          apply                              local                         
int          exist                              local

message      startup                                                          
message      created                                                          
message      removed                                                          
message      pulse                                                            
message      timer                                                            

end                                                                           

#####

code

startup:
player = GetLocalPlayerThing();
return;

#####

created:
exist = 1;
SetThingPulse(GetSenderRef(), 0.005);
apply = 1;
SetTimerEx(0.5, 0, 0, 0);
return;

#####

removed:
exist = 0;
Setpulse(0);
 jkEndTarget();
 Return;

#####
pulse:

if(apply == 1)
ApplyForce(GetSenderRef(), VectorScale(GetThingLVec(GetSenderRef()), 0));
ParseArg(GetSenderRef(), "angvel=(0/150/0)");

   victim = -1;
   maxDot = 0;

   // Search for all players and actors.
   potential = FirstThingInView(GetSenderRef(), 180, 100, 0x404);
   while(potential != -1)
   {
      if(
         HasLOS(GetSenderRef(), potential) &&
         (potential != GetSenderRef()) && (potential != player) &&
         (VectorDist(GetThingPos(GetSenderRef()), GetThingPos(potential)) <= 100) &&
         !(GetThingFlags(potential) & 0x200) &&
         !(GetActorFlags(potential) & 0x100) &&
         !((jkGetFlags(potential) & 0x20) && !IsInvActivated(player, 23))
        )
      {
         dot = ThingViewDot(GetSenderRef(), potential);
         if(dot > maxDot)
         {
            victim = potential;
            maxDot = dot;
         }
      }
      potential = NextThingInView();
   }

   // If we have a victim...
	if((victim != -1) && (exist == 1)) 
{
ParseArg(GetSenderRef(), "angvel=(0/0/0)");
jkSetTargetColors(1, 2, 3);
jkSetTarget(victim);
SetThingLook(GetSenderRef(), VectorSub(GetThingPos(victim), GetThingPos(GetSenderRef())));
CreateThing(bolt, GetSenderRef());
ApplyForce(GetSenderRef(), VectorScale(GetThingLVec(GetSenderRef()), .05));
}
else
{
jkEndTarget();
ParseArg(GetSenderRef(), "angvel=(0/150/0)");
ApplyForce(GetSenderRef(), VectorScale(GetThingLVec(GetSenderRef()), 0));
}

return;

#####

timer:
if(GetSenderID() == 0)
apply = 0;
return;

end

Top, my COG. Latter, Golems Sentry Droids. They work, but my seqs don't. What am I missing?
Edward's Cognative Hazards

↑ Up to the top!