Script for the Smasher: improved but still broken script

Script for the Smasher: improved but still broken script

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
FoeOfTheBee
Posts: 557
Joined: 12 May 2005, 18:26

Script for the Smasher: improved but still broken script

Post by FoeOfTheBee »

Code: Select all

AimWeapon1(heading, pitch)
	{
	signal SIG_AIM1;
	set-signal-mask SIG_AIM1;
	//   Place aiming animation code here
	turn frontturret to y-axis heading speed <50>;
	turn frontturret to x-axis pitch speed <50>;
	wait-for-turn frontturret around y-axis;
	wait-for-turn frontturret around x-axis;
	start-script RestoreAfterDelay();
	return(TRUE);
	}
I'm not sure why this doesn't work... Odds are it's something easy, I'm no expert at scripting. Not even a novice yet, really.

The tank doesn't fire. Without the animation code, it fires regardless of where the turret is pointing.
Last edited by FoeOfTheBee on 22 Feb 2006, 17:20, edited 1 time in total.
Archangel of Death
Posts: 854
Joined: 28 Jan 2005, 18:15

Post by Archangel of Death »

Rest of the code might be helpful.
User avatar
FoeOfTheBee
Posts: 557
Joined: 12 May 2005, 18:26

Post by FoeOfTheBee »

Here it is:

Code: Select all

 Old broken script was here.
Last edited by FoeOfTheBee on 23 Feb 2006, 23:33, edited 1 time in total.
Archangel of Death
Posts: 854
Joined: 28 Jan 2005, 18:15

Post by Archangel of Death »

Obscure rule #27 of bos/cob: Though shalt never use thy signals for more than one function.

You need six different SIG_AIM's. The numbers they are defined as at the top are in powers of 2, so 2, 4, 8, 16, 32, 64.
mongus
Posts: 1463
Joined: 15 Apr 2005, 18:52

Post by mongus »

Im illustrating myself here too, but, it seems you are using a variable called sig_aim3 in the fireweapon scripts.. but it seems its not defined in the header.
User avatar
FoeOfTheBee
Posts: 557
Joined: 12 May 2005, 18:26

Post by FoeOfTheBee »

I fixed the SIG_AIM problem...

But the tank still doesn't fire.

It does fire if I remove thes four lines:

Code: Select all

   turn frontturret to y-axis heading speed <50>;
   turn frontturret to x-axis pitch speed <50>;
   wait-for-turn frontturret around y-axis;
   wait-for-turn frontturret around x-axis; 
But of course the turret doesn't move. Does a turret have to include a sleeve? Am I missing something obvious?
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Post by yuritch »

You are trying to turn one piece around two axes at the same time. I'm not sure if this can work with wait-for-turns, never tried to make turrets like that.
Try adding a barrel piece and pitch it separately from turret (or just commenting out the turret pitch part). If it will work with just the turret pitch part commented out (and turret heading remaining in), then that was the problem and you'll need a separate barrel; if not, then I don't know what else could be the cause of this.
User avatar
SwiftSpear
Classic Community Lead
Posts: 7287
Joined: 12 Aug 2005, 09:29

Post by SwiftSpear »

yuritch wrote:You are trying to turn one piece around two axes at the same time. I'm not sure if this can work with wait-for-turns, never tried to make turrets like that.
Try adding a barrel piece and pitch it separately from turret (or just commenting out the turret pitch part). If it will work with just the turret pitch part commented out (and turret heading remaining in), then that was the problem and you'll need a separate barrel; if not, then I don't know what else could be the cause of this.
Don't your standard HLT and LLT have one peice that moves on 2 axis at the same time?
Archangel of Death
Posts: 854
Joined: 28 Jan 2005, 18:15

Post by Archangel of Death »

SwiftSpear wrote:Don't your standard HLT and LLT have one peice that moves on 2 axis at the same time?
No, but I have a few units that do it, and work.

Hmm, it can't possibly be that it is expecting "(0-pitch)" and not just "pitch" can it? That is how its normally done, but shouldn't it just go backwards then?
SpikedHelmet
MC: Legacy & Spring 1944 Developer
Posts: 1948
Joined: 21 Sep 2004, 08:25

Post by SpikedHelmet »

A) In lines such as "QueryWeapon1 (piecenum)" there should be no space between Weapon1 and (piecenum). It should look like" QueryWeapon1(piecenum).

B) To make a piece properly turn towards a target that is at a different height your script should be: "turn piece to x-axis <0> - pitch speed <whatever>" You do not have the <0> - pitch. So it should look like:

turn frontturret to y-axis heading speed <50>;
turn frontturret to x-axis <0> - pitch speed <50>;

C) In RestoreAfterDelay(), put the lines:

turn frontturret to y-axis <0> speed <50>;
turn frontturret to x-axis <0> speed <50>;

in.

D) Change your "return(TRUE)" to "return(1)". No real difference - maybe Spring fucks up with it.

E) It's probably been mentioned, but you have a ton of weapons using the same SIG_AIM. Here's a tip: don't bother setting signal as signal SIG_AIM3 or something that is defined at the top. Instead simply number them right there, as in:

signal 2;
set-signal-mask 2;

and

signal 4;
set-signal-mask 4;

etc. Also be sure that starting from Weapon1, every signal be to the power of 2, ie, weapon 1 = signal 2, weapon 2 = signal 4, weapon 3 = signal 8, weapon 4 = signal 16, etc... just double the signal number every weapon. IIRC there is no (realistic) limit.

I have a hunch that your tank isn't firing solely because you do not have "turn object to x-axis <0> - pitch". Try doing that first. No, it shouldn't go backwards. Telling it to go to 0 is basically making sure that it resets to normal alignment before pointing at the target. If you've ever made a unit with a turret ontop of another turret you'd know what I mean. Basically, if you have two turrets, one ontop of the other, and have both fire at something 90 degrees to the right... the bottom turret will turn 90 degrees but the top one will as well. Because the top one is ON the bottom turret, it will in effect be turning 90 degrees twice, ending up pointing in a completely wrong direction. Same thing goes for pitch; say your tank is rumbling along and another tank appears directly behind it (180 degrees). Your turn along y-axis script tells the turret to turn 180 degrees along the y-axis; your turn along x-axis script tells the turret to turn 180 degrees along the x-axis as well - basically meaning your turret will make two 180 degree rotations, which equals a complete 360 degree rotation, effectively making it NOT MOVE.

Hence, telling it to go to 0 first in the aiming script makes it "realize" where to begin calculating rotation from.
User avatar
FoeOfTheBee
Posts: 557
Joined: 12 May 2005, 18:26

Post by FoeOfTheBee »

Thanks for all the suggestions. I think I've fixed everything that's been mentioned. Here is the new, improved, still non-working script. New problem: everything fires now, but the turrets don't move.

Could it be that there is a problem with the model? It's the same model that's posted on the XTA unit request thread.

Code: Select all

old broken script was here
Last edited by FoeOfTheBee on 24 Feb 2006, 00:36, edited 1 time in total.
SpikedHelmet
MC: Legacy & Spring 1944 Developer
Posts: 1948
Joined: 21 Sep 2004, 08:25

Post by SpikedHelmet »

*insert forehead-slapping smiley here*

Adding "//" infront of a line effectively negates the line and that line will not be read. Your turret isn't turning because you've nulled the "turn frontturret to y-axis heading speed <50>" line.

Also, for your - pitch speed line, COPY AND PASTE THIS EXACTLY:

Code: Select all

turn frontturret to x-axis <0> - pitch speed <50>;
Change frontturret to backturret, rightturret or whatever the fuck turret the script is for. There are no spaces between the <0>, the - and the pitch, nor are there supposed to be ( ) brackets around it. Your AimWeapon scripts should look like, for example:

Code: Select all

AimWeapon1(heading, pitch) 
   { 
   signal SIG_AIM1; 
   set-signal-mask SIG_AIM1; 
   //Place aiming animation code here 
   turn frontturret to y-axis heading speed <50>;
   turn frontturret to x-axis <0> - pitch speed <50>;
   wait-for-turn frontturret around y-axis;
   wait-for-turn frontturret around x-axis;
   start-script RestoreAfterDelay(); 
   return(1); 
   } 

Again, make necessary changes to fit that into other weapons, ie, by changing AimWeapon1 to AimWeapon2 or whatever; by changing frontturret to backturret, sideturret etc; and there you go.
Archangel of Death
Posts: 854
Joined: 28 Jan 2005, 18:15

Post by Archangel of Death »

I think he purposefully commented out some lines to try to isolate if certain ones were causing problems, with weapon1 only trying to turn to its heading, weapon2 pitch, weapon 3 not at all, and all the rest both.

And uh, put that "sleep restore_delay;" before the turns to reset positions in RestoreAfterDelay().
User avatar
FoeOfTheBee
Posts: 557
Joined: 12 May 2005, 18:26

Post by FoeOfTheBee »

Here is the newest broken script. I am getting demoralized.

Code: Select all

//  script generated by Marcosoft LazyScripter
//   by Marco for Quantum Design - www.annihilated.com/quantum

piece base, body, frontturret, frontturretflare, backturret, backturretflare, rightturret, rightturretflare, leftturret, leftturretflare, leftturrettwo, leftturretflaretwo, rightturrettwo, rightturretflaretwo;

static-var restore_delay;
#define	SIG_AIM1	2
#define	SIG_AIM2	4
#define	SIG_AIM3	8
#define	SIG_AIM4	16
#define	SIG_AIM5	32
#define	SIG_AIM6	64
#define SMOKEPIECE1 base
#include "smokeunit.h"
#include "exptype.h"
#include "rockunit.h"
#include "hitweap.h"


Create()
	{
	restore_delay = 2000;
	start-script SmokeUnit();
	}

SetMaxReloadTime(time)
	{
	restore_delay = time * 2;
	}

RestoreAfterDelay()
	{
	// Add code to reset turret(s) to normal position
	sleep restore_delay;
	turn frontturret to y-axis <0> speed <50>;
	turn frontturret to x-axis <0> speed <50>; 
	turn backturret to y-axis <0> speed <50>;
	turn backturret to x-axis <0> speed <50>; 
	turn rightturret to y-axis <0> speed <50>;
	turn rightturret to x-axis <0> speed <50>; 
	turn leftturret to y-axis <0> speed <50>;
	turn leftturret to x-axis <0> speed <50>; 
	turn rightturrettwo to y-axis <0> speed <50>;
	turn rightturrettwo to x-axis <0> speed <50>; 
	turn leftturrettwo to y-axis <0> speed <50>;
	turn leftturrettwo to x-axis <0> speed <50>; 
	return 0;
	}

SweetSpot(piecenum)
	{
	piecenum = base;
	}

QueryWeapon1(piecenum)
	{
	piecenum = frontturretflare;
	}

AimFromWeapon1(piecenum)
	{
	piecenum = frontturret;
	}

AimWeapon1(heading, pitch)
	{
	signal SIG_AIM1;
	set-signal-mask SIG_AIM1;
	//   Place aiming animation code here
	turn frontturret to y-axis heading speed <50>;
	turn frontturret to x-axis <0> - pitch speed <50>;
	wait-for-turn frontturret around y-axis;
	wait-for-turn frontturret around x-axis;
	start-script RestoreAfterDelay();
	return(1);
	}

FireWeapon1()
	{
	show frontturretflare;
	sleep 150;
	hide frontturretflare;
	return(0);
	}

QueryWeapon2(piecenum)
	{
	piecenum = backturretflare;
	}

AimFromWeapon2(piecenum)
	{
	piecenum = backturret;
	}

AimWeapon2(heading, pitch)
	{
	signal SIG_AIM2;
	set-signal-mask SIG_AIM2;
	//   Place aiming animation code here
	turn backturret to y-axis heading speed <50>;
	turn backturret to x-axis <0> - pitch speed <50>;
	wait-for-turn backturret around y-axis;
	wait-for-turn backturret around x-axis;
	start-script RestoreAfterDelay();
	return(1);
	}

FireWeapon2()
	{
	show backturretflare;
	sleep 150;
	hide backturretflare;
	return(0);
	}

QueryWeapon3(piecenum)
	{
	piecenum = rightturretflare;
	}

AimFromWeapon3(piecenum)
	{
	piecenum = rightturret;
	}

AimWeapon3(heading, pitch)
	{
	signal SIG_AIM3;
	set-signal-mask SIG_AIM3;
	//   Place aiming animation code here
	turn rightturret to y-axis heading speed <50>;
	turn rightturret to x-axis <0> - pitch speed <50>;
	wait-for-turn rightturret around y-axis;
	wait-for-turn rightturret around x-axis;
	start-script RestoreAfterDelay();
	return(1);
	}

FireWeapon3()
	{
	show rightturretflare;
	sleep 150;
	hide rightturretflare;
	return(0);
	}

QueryWeapon4(piecenum)
	{
	piecenum = leftturretflare;
	}

AimFromWeapon4(piecenum)
	{
	piecenum = leftturret;
	}

AimWeapon4(heading, pitch)
	{
	signal SIG_AIM4;
	set-signal-mask SIG_AIM4;
	//   Place aiming animation code here
	turn leftturret to y-axis heading speed <50>;
	turn leftturret to x-axis <0> - pitch speed <50>;
	wait-for-turn leftturret around y-axis;
	wait-for-turn leftturret around x-axis;
	start-script RestoreAfterDelay();
	return(1);
	}

FireWeapon4()
	{
	show leftturretflare;
	sleep 150;
	hide leftturretflare;
	return(0);
	}

QueryWeapon5(piecenum)
	{
	piecenum = rightturretflaretwo;
	}

AimFromWeapon5(piecenum)
	{
	piecenum = rightturrettwo;
	}

AimWeapon5(heading, pitch)
	{
	signal SIG_AIM5;
	set-signal-mask SIG_AIM5;
	//   Place aiming animation code here
	turn rightturrettwo to y-axis heading speed <50>;
	turn rightturrettwo to x-axis <0> - pitch speed <50>;
	wait-for-turn rightturrettwo around y-axis;
	wait-for-turn rightturrettwo around x-axis;
	start-script RestoreAfterDelay();	
	return(1);
	}

FireWeapon5()
	{
	show rightturretflaretwo;
	sleep 150;
	hide rightturretflaretwo;
	return(0);
	}

QueryWeapon6(piecenum)
	{
	piecenum = leftturretflaretwo;
	}

AimFromWeapon6(piecenum)
	{
	piecenum = leftturrettwo;
	}

AimWeapon6(heading, pitch)
	{
	signal SIG_AIM6;
	set-signal-mask SIG_AIM6;
	//   Place aiming animation code here
	turn leftturrettwo to y-axis heading speed <50>;
	turn leftturrettwo to x-axis <0> - pitch speed <50>;
	wait-for-turn leftturrettwo around y-axis;
	wait-for-turn leftturrettwo around x-axis;
	start-script RestoreAfterDelay();
	return(1);
	}

FireWeapon6()
	{
	show leftturretflaretwo;
	sleep 150;
	hide leftturretflaretwo;
	return(0);
	}

Killed(severity, corpsetype)
	{
	if (severity <= 25)
		{
		corpsetype = 1;
		explode base type	BITMAPONLY | BITMAP1;
		explode body type	BITMAPONLY | BITMAP1;
		explode frontturret type	BITMAPONLY | BITMAP1;
		explode frontturretflare type	BITMAPONLY | BITMAP1;
		explode backturret type	BITMAPONLY | BITMAP1;
		explode backturretflare type	BITMAPONLY | BITMAP1;
		explode rightturret type	BITMAPONLY | BITMAP1;
		explode rightturretflare type	BITMAPONLY | BITMAP1;
		explode leftturret type	BITMAPONLY | BITMAP1;
		explode leftturretflare type	BITMAPONLY | BITMAP1;
		explode leftturrettwo type	BITMAPONLY | BITMAP1;
		explode leftturretflaretwo type	BITMAPONLY | BITMAP1;
		explode rightturrettwo type	BITMAPONLY | BITMAP1;
		explode rightturretflaretwo type	BITMAPONLY | BITMAP1;
		return(0);
		}
	if (severity <= 50)
		{
		corpsetype = 2;
		explode base type	SHATTER | BITMAP4;
		explode body type	SHATTER | BITMAP4;
		explode frontturret type	SHATTER | BITMAP4;
		explode frontturretflare type	SHATTER | BITMAP4;
		explode backturret type	SHATTER | BITMAP4;
		explode backturretflare type	SHATTER | BITMAP4;
		explode rightturret type	SHATTER | BITMAP4;
		explode rightturretflare type	SHATTER | BITMAP4;
		explode leftturret type	SHATTER | BITMAP4;
		explode leftturretflare type	SHATTER | BITMAP4;
		explode leftturrettwo type	SHATTER | BITMAP4;
		explode leftturretflaretwo type	SHATTER | BITMAP4;
		explode rightturrettwo type	SHATTER | BITMAP4;
		explode rightturretflaretwo type	SHATTER | BITMAP4;
		return(0);
		}
	if (severity <= 99)
		{
		corpsetype = 3;
		explode base type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
		explode body type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
		explode frontturret type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
		explode frontturretflare type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
		explode backturret type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
		explode backturretflare type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
		explode rightturret type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
		explode rightturretflare type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
		explode leftturret type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
		explode leftturretflare type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
		explode leftturrettwo type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
		explode leftturretflaretwo type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
		explode rightturrettwo type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
		explode rightturretflaretwo type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
		return(0);
		}
	corpsetype = 3;
	explode base type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
	explode body type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
	explode frontturret type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
	explode frontturretflare type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
	explode backturret type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
	explode backturretflare type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
	explode rightturret type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
	explode rightturretflare type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
	explode leftturret type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
	explode leftturretflare type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
	explode leftturrettwo type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
	explode leftturretflaretwo type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
	explode rightturrettwo type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
	explode rightturretflaretwo type	FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP2;
	return(0);
	}
Archangel of Death
Posts: 854
Joined: 28 Jan 2005, 18:15

Post by Archangel of Death »

What are you using to compile it? If your using Scriptor, make sure your linear and angular constants are set right (in Scripts/settings).

If its not that, which I have reason to believe it isn't, it might be time to start over. I'd suggest taking a work tank .cob (any tank) out of any mod, decompiling it back into a bos (easy if you are using scriptor, and the settings aren't borked), then base it off that. Only adding in the additional Sig_Aim's, weapons, and position resets in the restoreafterdelay.
SpikedHelmet
MC: Legacy & Spring 1944 Developer
Posts: 1948
Joined: 21 Sep 2004, 08:25

Post by SpikedHelmet »

Remove the entire line "return 0;" from RestoreAfterDelay. That should not be there (nor should the 0 be without brackets; should, under other circumstances, be "return (0);" -- but like I said remove that entire line)
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

SpikedHelmet wrote:I have a hunch that your tank isn't firing solely because you do not have "turn object to x-axis <0> - pitch". Try doing that first. No, it shouldn't go backwards. Telling it to go to 0 is basically making sure that it resets to normal alignment before pointing at the target. If you've ever made a unit with a turret ontop of another turret you'd know what I mean. Basically, if you have two turrets, one ontop of the other, and have both fire at something 90 degrees to the right... the bottom turret will turn 90 degrees but the top one will as well. Because the top one is ON the bottom turret, it will in effect be turning 90 degrees twice, ending up pointing in a completely wrong direction. Same thing goes for pitch; say your tank is rumbling along and another tank appears directly behind it (180 degrees). Your turn along y-axis script tells the turret to turn 180 degrees along the y-axis; your turn along x-axis script tells the turret to turn 180 degrees along the x-axis as well - basically meaning your turret will make two 180 degree rotations, which equals a complete 360 degree rotation, effectively making it NOT MOVE.

Hence, telling it to go to 0 first in the aiming script makes it "realize" where to begin calculating rotation from.
B.S.: turn 0 - pitch is just because of the axis convention used, you have turn negatively around the x-axis for the front part of a piece to go up. It doesn't at all mean anything like reseting to normal before moving or setting where to begin calculation from. The engine just passes a pitch between -90° and +90°, and a heading between -180° and +180° (Note that TA will pass positive values, so negative angle will have a +360° shift, but the Spring engine doesn't mind just passing the negative angle to the script). Either way it won't ever pass a pitch angle beyond vertical. If you don't believe me, just remove that "0 -" from "turn frontturret to x-axis <0> - pitch speed <50>; " and watch the tank aims down instead of up, yet still behave the same even when the target is backward.

Having 'return 0' at the end of each function won't hurt anything, it could even solve some potential (but very rare, don't worry) bugs where scriptor forget to add them at the last } of a function. I think return; return(0); and return 0; all are the same once compiled.

Something that bugs me into that script is that every turret use the same "RestoreAfterDelay". I'm not very sure about what happens when the same function is called many time, and has no signal thing. Does it create many independant instance of the function? Does each new starting of the function kill previous one even when there is no signal? Does it break everything? I just know that calling/starting several time the same function in old TA could bring total havoc and inconceivable bugs. But I don't know about Spring. But just to be safe, I'd comment all those start-script RestoreDelay(); And then later once the bug is squashed, give each aiming script its own RestoreAfterDelay, otherwise if, let's say, leftturret has not target for a while, then by restoring its position it will make also right turret turn to 0 even if right turret is busy firing!

What about simplifying the unit to have only one weapon, Primary, and then trying to put all your six aiming script one by one into AimPrimary to test each turret individually, before trying to script all six turrets at once?

Only when it works fine with one weapon then gradually augment the number of weapon and used turrets.
Post Reply

Return to “Game Development”