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 → How to make thing shoot.
How to make thing shoot.
2004-03-01, 11:07 AM #1
Ok... I'm sortof confuesed here.. How would I make a cog that would make a 'thing' fire a projectile, but KEEP shooting...

Basicly, Its an AI. But, I dont want the Template visible,.. And, i need the projectile aimed directly at the 'player'.. And, if there is more then one player, that it shoots at both.. Any idea anyone?
"Greetings young Padawan."
2004-03-01, 3:17 PM #2
I remember seeing something like this in a recent mod for JK. Its from FORGE.gob and one of the weapons is "multiple target laser weapon" and when you fire it fires at every player/actor in sight.

When you mean "but keep firing" do you mean like a laser beam weapon? the FORGE.gob has those too. Just extracto the cogs and study them is all I cna think of

[edit] here it is: GOLEM forge:
http://www.massassi.net/levels/files/2898.shtml
I really enjoy this mod

[This message has been edited by F-Body (edited March 01, 2004).]
This is retarded, and I mean drooling at the mouth
2004-03-02, 3:55 AM #3
Ok.. I figured out the little damn FirProjectile command.. I remember the thing in nar shadda loading terminal, how laser shoot at you by a switch.. I extracted it and looked through it, and finally got it to work the way I want. Now, I just have to get it to loop, without messing up the rest of my cog..

The 'call' command, it says in datamaster it will only loop the same thing 5 times, what if its like this:

Code:
fire1:
        //command
        call fire2;
        return;
fire2
        //command
        call fire1;
        return;
end
"Greetings young Padawan."
2004-03-02, 4:09 AM #4
Every time you use a call command, JK will push the stack, thinking you intend to come back to the parent function to execute more code. It will only push the stack a limited number of times before

a) your computer generates an out of memory error because the stack has grown in size and occupies your entire memory...

or

b) JK detects you have pushed the stack too many times, assumes it's a programming bug, and aborts.

Be glad A didn't happen... LA has good programmers. :P

In short: Use a for loop, don't use call.

------------------
The Mega-ZZTer's Gaming Haven!

Bot Pack JO | Let's Roll JK | Bespin JA | Patch Enforcer JK/Mots | Pac-Man JK

2004-03-02, 7:20 AM #5
Code:
while(i<10)
{
	i=i+1;
	//run fireprojectile code...
}


------------------
The future is here, and all bets are off.
And when the moment is right, I'm gonna fly a kite.
2004-03-03, 5:22 AM #6
Ok.. I have -- another problem.. I have everything as I need, its all perfect.. Except for the autoaim thing.. I have the flags set correctly, but, it will only fire at the player when hes in Firt view.. When you go in secondary, it wont fire at you.. Werid.

Heres my code, I hope you can help! ^_^
Code:
flags=0x240
symbols
	message	startup
	message	arrived
	message	activated

	thing		hovercraft
	surface		switch
	flex		MoveSpeed=1.0
	sound		HoverSound
	sound		Butnsnd
	flex		Volume=.5
	flex		mindist=10
	flex		maxdist=10
	flex		fade=1

	template	temp=+stlaser	local
	flex		firerate=1
	sound		lsnd=sprobegun01.wav

	int	shoot=0	local
	int	dummy	local
	int	flag=0	local
	int	flag2=0	local
	int	snd=0	local
end
# ...................................................................................................
code
startup:
	SetWallCel(switch,0);
	return;
arrived:
	If(flag == 0)
	{
		MoveToFrame(hovercraft, 0, MoveSpeed);
		flag = 1;
		flag2 = 0;
	}
	else If(flag2 == 0)
	{
		MoveToFrame(hovercraft, 9, MoveSpeed);
		flag = 0;
		flag2 = 1;
	}
	else if(GetWallCel(switch) == 0) StopSound(dummy, fade);
	return;

activated:
	If(GetWallCel(switch) == 0)
	{
		PlaySoundPos(Butnsnd, GetSurfaceCenter(switch), 1, -1, -1, 0);
		shoot = 1;
		call move_hc;
	}
	else if(GetWallCel(switch) == 1)
	{
		PlaySoundPos(Butnsnd, GetSurfaceCenter(switch), 1, -1, -1, 0);
		shoot = 0;
		call stop_move;
	}

	While(shoot == 1)
	{
		FireProjectile(hovercraft, temp, lsnd, -1, '0 0 0', '0 0 0', 1.0, 0x60, 180, 180);
		sleep(firerate);
	}
	return;
# ...................................................................................................
move_hc:
	If(snd == 0) dummy = PlaySoundThing(hoversound, hovercraft,volume,mindist,maxdist,0x81);
	MoveToFrame(hovercraft, 9, movespeed);
	SetWallCel(switch,1);
	flag = 0;
	flag2 = 0;
	snd = 1;
	return;
#..............................
stop_move:
	MoveToFrame(hovercraft, 0, movespeed);
	SetWallCel(switch,0);
	flag = 1;
	flag2 = 1;
	WaitForStop(hovercraft);
	snd = 0;
	return;
#..............................
end
"Greetings young Padawan."
2004-03-03, 5:25 AM #7
Also - another problem, if the switch or the thing is Activated to many times, really fast, it will just stop, and fire.. And cant be reactivated.. I dont get it.. I added the flag=240 to see if it would make a difference, didnt.
"Greetings young Padawan."
2004-03-03, 8:12 AM #8
Code:
	While(shoot == 1)
	{
		FireProjectile(hovercraft, temp, lsnd, -1, '0 0 0', '0 0 0', 1.0, 0x60, 180, 180);
		sleep(firerate);
	}



Thats gonna cause problems. Try this method...


Code:
activated:

	//blah blah blah

	Setpulse(firerate);
Stop;

Pulse:
	FireProjectile(hovercraft, temp, lsnd, -1, '0 0 0', '0 0 0', 1.0, 0x60, 180, 180);
Stop;


...Then, when you want to shut it off, "Setpulse(0)"...

------------------
The future is here, and all bets are off.
And when the moment is right, I'm gonna fly a kite.
2004-03-03, 9:03 AM #9
I was thinking about using Pulse, but I always had trouble with it. Ill try it though, thanks!
"Greetings young Padawan."
2004-03-03, 10:41 AM #10
Yeah, sleep() can run into problems really easy if not used carefully. JK can only handle like 4 or 5 at a time.

Also, never use sleeps in weapon cogs (like weap_bryar.cog); use timers.

If it helps any, pulses are essentially loops that have a specified flex delay between iterations -- SetPulse(delay);

------------------
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-03-03, 11:06 AM #11
Thanks.. It worked great.. But, theres still the problem with the Auto aim, it will only fire at the target when the First view is selected, but when in secondary, it wont fire at the player.. Cant figure this out..
"Greetings young Padawan."
2004-03-04, 4:27 AM #12
Erm, maybe I can make it a little more clear.. O_O..

When the player is in first view,(The view you start off in) the thing will fire at the player, auto-aim.. But, when the player changes to secondary view, when you can see the player, the thing will just fire straight infront of it.. And not at the player. -_-... I cannot figure this out at all.
"Greetings young Padawan."
2004-03-04, 9:38 AM #13
[http://forums.massassi.net/html/confused.gif]
I'm clueless, as you can see [http://forums.massassi.net/html/wink.gif]

------------------
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-03-05, 5:41 AM #14
It just doesnt make any sense to me.. -_-...

I was really hopeing that GBK would know.. O_o
"Greetings young Padawan."
2004-03-05, 6:17 AM #15
Try decreasing your AA_FOVX values.

------------------
The future is here, and all bets are off.
And when the moment is right, I'm gonna fly a kite.

↑ Up to the top!