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 → Sentry Gun problem!
Sentry Gun problem!
2003-12-14, 2:57 AM #1
Hi!
Sorry if I asked you guys to make a sentry gun COG for me... I made a class cog and it doesn't seem to work... Help?
Code:
# Sentry Gun Class COG
#
# By Edward
symbols

message		created
message		pulse

thing		sentry			local

template	boom=+grenade_exp	local
template	proj=+stlaser		local

keyframe	opening=Sentry_Open.key	local
keyframe	idle=Sentry_Idle.key	local
keyframe	over=Sentry_Down.key	local

sound		open=Ed_Sadar_Ready.wav	local
sound		going=scalarm.wav	local
sound		empty=pistout1.wav	local
sound		moving=weegeemove01.wav	local
sound		firy=SentryGun_Fire.wav	local

int		ammo			local
int		thekey=-1		local
int		chan=1			local

flex		dot			local
flex		maxdot=0		local

model		xeno=alien.3do		local
thing		victim=-1		local
int		potential=-1		local

end
#
code
created:
	sentry=GetSenderRef();
	thekey=PlayKey(sentry,opening,1,0x1);
	ammo=500;
	sleep(0.2);
	while(IsThingMoving(sentry))
	{
		sleep(0.1);
	}
	StopKey(sentry,thekey,0.1);
	PlaySoundThing(open,sentry,1,-1,10,0xC0);
	thekey=PlayKey(sentry,opening,1,0x4);
	sleep(1);
	StopKey(sentry,thekey,0.1);
	thekey=PlayKey(sentry,idle,1,0x0);
	SetPulse(.1);
return;
pulse:
	victim=-1;
	maxdot=0;
	potential=FirstThingInView(sentry,90,1,0x404);
	while(potential!=-1)
	{
		if(HasLOS(sentry,potential) && (potential!=sentry) && (VectorDist(GetThingPos(sentry), GetThingPos(potential)) <= 1) && !(GetThingFlags(potential) & 0x200) && !((jkGetFlags(potential) & 0x20) && !IsInvActivated(sentry, 23)))
		{
			dot=ThingViewDot(sentry,potential);
			if(dot>maxdot)
			{
				victim=potential;
				maxdot=dot;
				PlaySoundThing(firy,sentry,1,-1,10,0xC0);
			}
		}
		Potential=NextThingInView();
	}

############################################################################

	if(ammo<=0)
	{
		PlaySoundThing(empty,sentry,1,-1,10,0xC0);
		SetPulse(0);
		StopKey(sentry,thekey,1);
		thekey=PlayKey(sentry,over,1,0x4);
		chan=PlaySoundThing(moving,sentry,1,-1,10,0xC0);
		ChangeSoundPitch(chan,.1,1);
		sleep(1);
		PlaySoundThing(going,sentry,1,-1,10,0xC0);
		Sleep(GetSoundLen(going) + 0.25);
		PlaySoundThing(going,sentry,1,-1,10,0xC0);
		Sleep(GetSoundLen(going) + 0.25);
		CreateThing(boom,sentry);
		DestroyThing(sentry);
	}
return;
end

In the while I test to see if the thing is moving cause I want it to NOT unfold if it's falling. I want it to unfold when it has come to a complete stop and has attached itself to a surface.
BUT, non of the keys seem to respond. It plays the sound but it doesn't unfold, nor does it target me and fire. OK not fire, but play the sound of fireing. Doesn't move at all. I've given it this template:
Code:
sentrygun         _weapon            timer=86400 size=0.04 movesize=0.04 model3d=Sentry.3DO vel=(0/.1/0) physflags=0x429B typeflags=0x00A81 explode=+grenade_exp fleshhit=+sequencer_exp cog=class_sentrygun.cog soundclass=sentry.snd surfdrag=100.000000 airdrag=10.000000 collide=1 pup=sentry.pup mass=5

Oh, and it keeps sliding off the walls when I want it to stick! And I don't collide into it!
Keys will come...
Edward's Cognative Hazards
2003-12-15, 6:56 AM #2
Ok, first of all, we don't need all the text of all the files that pertain to your project. Posting the text of a 3do/key is useless because your 3do/key should work properly if you saw it all in pjedi.

Ok, time for enlightenment:

Weapons will not collide with their parents, nor children of their parents.

The reason why it slides down walls is innappropriate flag settings. Obviously gravity is affecting it.

Sleep() is of the devil. There should be no reason, other than sheer lazyness to implement timers, to use Sleep() at all.

Lastly, I'm surprised the while loop under created: didn't take over your JK.exe thread from windows and lock up the process. Never use while loops unless the condition can be broken inside the while loop itself.

Fix all that (points up) and re-organize your cog and see where that takes you.

------------------
-Blessed Be-
A solid challenge will bring forth your finest abilities.
DBZ: The Destruction is Real
-Hell Raiser
2003-12-15, 12:04 PM #3
Sorry about the 3 in one posts... Just figured out last night in my bed that I had misspelled puppet...

The while loop is basically a test to see if the thing has come to a complete stop. You see, I don't what the thing to open up until it has reached solid ground... And I want it to act like a seq mine. Funny how it slips, I thought I gave it the OK flags... And I tried dropping it at a high height, but it acted as if it had partial gravity.

/Edward
Edward's Cognative Hazards
2003-12-16, 2:59 AM #4
Oh yea, it's puppet=mypuppet.pup not pup=mypuppet.pup [http://forums.massassi.net/html/smile.gif] That lost a few hairs on my head back in the day. [http://forums.massassi.net/html/wink.gif]

As for slipping off walls, there's another thread in here talking about the Physics flag 0x800, sounds like you need to take a read. [http://forums.massassi.net/html/smile.gif] Also the mass property affects how 'heavy' things are.

As for checking if it's stopped, it'd be better executed inside a pulse or 'timer loop'. Your While loop should lock up JK because the while/for loops will execute and complete themselves before any JK.exe related commands will. Your sentry should be forever moving because the while loop never releases control back to JK.exe to actually move or stop the sentry. So I'm blaming the sleep() commands for any anomilies you experiance in your cog. Get rid of 'em. [http://forums.massassi.net/html/tongue.gif]

------------------
-Blessed Be-
A solid challenge will bring forth your finest abilities.
DBZ: The Destruction is Real
-Hell Raiser
2003-12-16, 5:38 AM #5
OK, point out 0x800 in the PhysFlags in the template.
And I changed the Mass to 1.
And the while does not seem to give problems, all keys work. And sounds, BUT! No explotion when I blow it up, and... Any experts working on this?
Edward's Cognative Hazards
2003-12-16, 6:34 AM #6
I mearly give first hand suggestions or train of thought for you to do it all yourself. I'm not going to run and test your cog for you, thats just stupidity waiting to happen. You're not going to learn a damn thing if you just say "Here, fix it for me."

Let the 'experts' work on it and have them tell you the same thing about Sleep() and while loops as I did.

Oh, by the by, things of the weapon type can't collide with other things of the weapon type....

Good day.

------------------
-Blessed Be-
A solid challenge will bring forth your finest abilities.
DBZ: The Destruction is Real
-Hell Raiser

↑ Up to the top!