#define TA // This is a TA script
#include "sfxtype.h"
#include "exptype.h"
piece base, body, launcher, missile, trail1, trail2, trail3, trail4, aim, door1, door2, flare1a, flare1b, flare1c, flare1d, flare1e, flare1f, flare1g, flare1h, flare1i, flare1j, flare2;
static-var gun_1, gun_2, gun_3, bMoving, bAiming, missilefire, missiles;
// Signal definitions
#define SIG_AIM 2
#define SIG_AIM_2 4
#define SIG_AIM_3 8
#define SIG_MOVE 16
SmokeUnit(healthpercent, sleeptime, smoketype)
{
while( get BUILD_PERCENT_LEFT )
{
sleep 400;
}
while( TRUE )
{
healthpercent = get HEALTH;
if( healthpercent < 66 )
{
smoketype = 256 | 2;
if( Rand( 1, 66 ) < healthpercent )
{
smoketype = 256 | 1;
}
emit-sfx smoketype from base;
}
sleeptime = healthpercent * 50;
if( sleeptime < 200 )
{
sleeptime = 200;
}
sleep sleeptime;
}
return (0);
}
Surface()
{
move body to y-axis [22.000000] speed [15.000000];
wait-for-move body along y-axis;
sleep 500;
bAiming = TRUE;
}
Dive()
{
move missile to z-axis [0.000000] speed [50.000000];
sleep 600;
turn launcher to x-axis <0.000> speed <150.000000>;
move launcher to z-axis [0.000000] speed [25.000000];
sleep 600;
move door1 to z-axis [0.000000] speed [25.000000];
move door1 to y-axis [0.000000] speed [25.000000];
move door2 to z-axis [0.000000] speed [25.000000];
move door2 to y-axis [0.000000] speed [25.000000];
sleep 600;
move body to y-axis [0.000000] speed [15.000000];
wait-for-move body along y-axis;
sleep 500;
show missile;
bAiming = FALSE;
}
Hatch1()
{
move door1 to z-axis [-15.000000] speed [25.000000];
move door1 to y-axis [-2.000000] speed [25.000000];
sleep 600;
turn launcher to x-axis <-90.000> speed <150.000000>;
move launcher to z-axis [5.000000] speed [25.000000];
sleep 600;
move missile to z-axis [1.000000] speed [50.000000];
sleep 600;
gun_2 = 1;
}
Hatch2()
{
move door2 to z-axis [15.000000] speed [25.000000];
move door2 to y-axis [-2.000000] speed [25.000000];
sleep 600;
}
Create()
{
gun_2 = 0;
gun_1 = 0;
missiles = 0;
start-script SmokeUnit();
}
SlowReload()
{
if( missilefire > 0 AND missilefire < 10 )
{
while( missilefire > 0 AND missiles == 0 )
{
--missilefire;
sleep 666;
}
}
}
Reload()
{
sleep 18000;
gun_1 = 0;
}
RestoreAfterDelay()
{
sleep 3000;
if( gun_1 == 0 )
{
start-script SlowReload();
}
call-script Dive();
missiles = 0;
}
AimWeapon1(heading, pitch)
{
signal SIG_AIM;
set-signal-mask SIG_AIM;
while( gun_1 == 1 )
{
sleep 100;
}
call-script Surface();
missiles = 1;
if(bAiming)
{
call-script Hatch2();
sleep 350;
}
start-script RestoreAfterDelay();
return (1);
}
FireWeapon1()
{
if( missilefire >= 0 AND missilefire < 10 )
{
if( missilefire == 0 )
{
show flare1a;
sleep 100;
hide flare1a;
}
if( missilefire == 1 )
{
show flare1b;
sleep 100;
hide flare1b;
}
if( missilefire == 2 )
{
show flare1c;
sleep 100;
hide flare1c;
}
if( missilefire == 3 )
{
show flare1d;
sleep 100;
hide flare1d;
}
if( missilefire == 4 )
{
show flare1e;
sleep 100;
hide flare1e;
}
if( missilefire == 5 )
{
show flare1f;
sleep 100;
hide flare1f;
}
if( missilefire == 6 )
{
show flare1g;
sleep 100;
hide flare1g;
}
if( missilefire == 7 )
{
show flare1h;
sleep 100;
hide flare1h;
}
if( missilefire == 8 )
{
show flare1i;
sleep 100;
hide flare1i;
}
if( missilefire == 9 )
{
gun_1 = 1;
start-script Reload();
show flare1j;
sleep 100;
hide flare1j;
}
}
++missilefire;
if( missilefire == 10 )
{
missilefire = 0;
}
}
AimFromWeapon1(piecenum)
{
piecenum = body;
}
QueryWeapon1(piecenum)
{
if( missilefire >= 0 AND missilefire < 10 )
{
if( missilefire == 0 )
{
piecenum = flare1a;
}
if( missilefire == 1 )
{
piecenum = flare1b;
}
if( missilefire == 2 )
{
piecenum = flare1c;
}
if( missilefire == 3 )
{
piecenum = flare1d;
}
if( missilefire == 4 )
{
piecenum = flare1e;
}
if( missilefire == 5 )
{
piecenum = flare1f;
}
if( missilefire == 6 )
{
piecenum = flare1g;
}
if( missilefire == 7 )
{
piecenum = flare1h;
}
if( missilefire == 8 )
{
piecenum = flare1i;
}
if( missilefire == 9 )
{
piecenum = flare1j;
}
}
}
AimWeapon2(heading, pitch)
{
signal SIG_AIM_2;
set-signal-mask SIG_AIM_2;
call-script Surface();
if(bAiming)
{
call-script Hatch1();
sleep 350;
}
start-script RestoreAfterDelay();
return (1);
}
FireWeapon2()
{
hide missile;
}
AimFromWeapon2(piecenum)
{
piecenum = body;
}
QueryWeapon2(piecenum)
{
piecenum = missile;
}
AimWeapon3(heading, pitch)
{
while( gun_3 >= 1)
{
sleep 100;
}
signal SIG_AIM_3;
set-signal-mask SIG_AIM_3;
return (1);
}
FireWeapon3()
{
if( gun_3 == 0 )
{
sleep 10;
}
gun_3= gun_3 + 1;
if( gun_3 >= 1 )
{
gun_3=0;
}
}
AimFromWeapon3(piecenum)
{
piecenum = body;
}
QueryWeapon3(piecenum)
{
if( gun_3 == 0 )
{
piecenum = flare2;
}
}
StartMoving()
{
signal SIG_MOVE;
set-signal-mask SIG_MOVE;
bMoving = TRUE;
while( TRUE )
{
emit-sfx 256 | 3 from trail1;
emit-sfx 256 | 3 from trail2;
emit-sfx 256 | 3 from trail3;
emit-sfx 256 | 3 from trail4;
sleep 200;
}
}
StopMoving()
{
signal SIG_MOVE;
bMoving = FALSE;
}
SweetSpot(piecenum)
{
piecenum = base;
}
Killed(severity, corpsetype)
{
if( severity <= 25 )
{
corpsetype = 1;
explode body type BITMAPONLY | BITMAP3;
return (0);
}
if( severity <= 50 )
{
corpsetype = 2;
explode body type BITMAPONLY | BITMAP3;
return (0);
}
if( severity <= 99 )
{
corpsetype = 3;
explode body type BITMAPONLY | BITMAP3;
return (0);
}
corpsetype = 3;
explode body type BITMAPONLY | BITMAP3;
}
Scripting Issue, Unit wont get past Aiming..
Moderator: Moderators
Scripting Issue, Unit wont get past Aiming..
The following script is what I have, and weapon 1 and 2 will not get past aiming, and fire their weapons.. I am at a loss.. any help would be appreciated..
Re: Scripting Issue, Unit wont get past Aiming..
Contrary to TA, Spring calls the aiming once every second, if not once every frame. This mean that if an aiming can't be instantenous (after previous aimings have already opened and pointed weapon), then new aimings are called before the previous can finish.
In you script it does like that:
- Units wants to fire
- AimWeapon1(heading,pitch) gets called
- It calls Surface(). Because it's a call-script, and not a start-script, AimWeapon1 has to wait for Surface to finish before proceeding further.
- Surface() encouters a sleep 500; so goes into pause for half a second.
- Meanwhile, a new AimWeapon1 is called.
- The signal stuff make that new AimWeapon1 kills the previous AimWeapon1.
So each AimWeapon1 gets killed by a new AimWeapon1 before having the time to finish, since the sleep 500; is compulsory. So not any AimWeapon1 ever complete, and so, the weapon never fire.
There are varied ways to solve that:
1) Write your aiming so that there is no "sleep". Use only "wait-for".
2) Instead of making new instance of aiming kills previous instance using signals, make new instance abort if a previous instance is already running (with some static-var).
3) Put all the animation into some everlooping immortal function, which communicate with the aiming with some static-var. Which is what I did in the following:
Oh and also, in your AimWeapon3, you had the "while" before the "signal" bit, which is potentially extremely dangerous. If gun_3 stays at 1 for, like ten seconds, then you'd have about 18000 instance of AimWeapon3 alive for each sub, which I suppose would create some performance drop / crash / error / bad stuff for Spring.
I don't have your sub, so haven't tested all my code really work. I hope it does, or that if it doesn't, it's a small typo you'll easily fix.
Also, you haven't rely specified what behavior you want, so I had to guess it. Currently:
- Wanting to fire 1 or 2 makes it surface.
- Wanting to fire 1 or 2 makes open corresponding hatch once surfaced.
- Not wanting to fire neither 1 nor 2 make it dives.
- Once 1 has depelted all ten missiles, it can't fire anymore.
- When it's dived, it slowly recharge missiles, one more every 0.66 seconds
- When it has fired the last of the ten missile, it waits 7sec then get all ten missiles back, surfaced or dived.
In you script it does like that:
- Units wants to fire
- AimWeapon1(heading,pitch) gets called
- It calls Surface(). Because it's a call-script, and not a start-script, AimWeapon1 has to wait for Surface to finish before proceeding further.
- Surface() encouters a sleep 500; so goes into pause for half a second.
- Meanwhile, a new AimWeapon1 is called.
- The signal stuff make that new AimWeapon1 kills the previous AimWeapon1.
So each AimWeapon1 gets killed by a new AimWeapon1 before having the time to finish, since the sleep 500; is compulsory. So not any AimWeapon1 ever complete, and so, the weapon never fire.
There are varied ways to solve that:
1) Write your aiming so that there is no "sleep". Use only "wait-for".
2) Instead of making new instance of aiming kills previous instance using signals, make new instance abort if a previous instance is already running (with some static-var).
3) Put all the animation into some everlooping immortal function, which communicate with the aiming with some static-var. Which is what I did in the following:
Oh and also, in your AimWeapon3, you had the "while" before the "signal" bit, which is potentially extremely dangerous. If gun_3 stays at 1 for, like ten seconds, then you'd have about 18000 instance of AimWeapon3 alive for each sub, which I suppose would create some performance drop / crash / error / bad stuff for Spring.
Code: Select all
#define TA // This is a TA script
#include "sfxtype.h"
#include "exptype.h"
piece base, body, launcher, missile, trail1, trail2, trail3, trail4, aim, door1, door2, flare1a, flare1b, flare1c, flare1d, flare1e, flare1f, flare1g, flare1h, flare1i, flare1j, flare2;
static-var gun_3, moving, surfaced, hatch1open, hatch2open, wannafire1, wannafire2, missilefire, missilestockpiled;
// Signal definitions
#define SIG_AIM_1 2
#define SIG_AIM_2 4
#define SIG_AIM_3 8
#define SIG_MOVE 16
#define SIG_FIRE1 32
SmokeUnit()
{
var healthpercent, sleeptime, smoketype;
while( get BUILD_PERCENT_LEFT )
{
sleep 400;
}
while( TRUE )
{
healthpercent = get HEALTH;
if( healthpercent < 66 )
{
smoketype = SFXTYPE_BLACKSMOKE;
if( Rand( 1, 66 ) < healthpercent )
{
smoketype = SFXTYPE_WHITESMOKE;
}
emit-sfx smoketype from base;
}
sleeptime = healthpercent * 50;
if( sleeptime < 200 )
{
sleeptime = 200;
}
sleep sleeptime;
}
}
Surface()
{
move body to y-axis [22] speed [15];
wait-for-move body along y-axis;
sleep 500;
surfaced=TRUE;
}
Dive()
{
hatch1open=FALSE;
hatch2open=FALSE;
surfaced=FALSE;
move missile to z-axis [0] speed [50];
sleep 600;
turn launcher to x-axis <0> speed <150>;
move launcher to z-axis [0] speed [25];
sleep 600;
move door1 to z-axis [0] speed [25];
move door1 to y-axis [0] speed [25];
move door2 to z-axis [0] speed [25];
move door2 to y-axis [0] speed [25];
sleep 600;
move body to y-axis [0] speed [15];
wait-for-move body along y-axis;
sleep 500;
show missile;
}
// So weap1 was firing from hatch2
// and weap2 was firing from hatch1 ?
// Sorry but I renamed your hatch for consitency
OpenHatch1()
{
move door2 to z-axis [15] speed [25];
move door2 to y-axis [-2] speed [25];
sleep 600;
hatch1open=TRUE;
}
OpenHatch2()
{
show missile;// I think the missile should be shown somehere.
move door1 to z-axis [-15] speed [25];
move door1 to y-axis [-2] speed [25];
sleep 600;
turn launcher to x-axis <-90> speed <150>;
move launcher to z-axis [5] speed [25];
sleep 600;
move missile to z-axis [1] speed [50];// move it .. [1]? Sure we'll see such a small move?
sleep 600;
hatch2open=TRUE;
}
SurfaceHatchNStuff()
{
while(TRUE)
{
if(wannafire1 || wannafire2 || !surfaced)
{
call-script Surface();
}
if(wannafire1 && surfaced)
{
call-script OpenHatch1();
}
if(wannafire2 && surfaced)
{
call-script OpenHatch2();
}
if((!wannafire1) && (!wannafire2))
{
call-script Dive();
}
sleep 666;
if((!surfaced) && (missilestockpiled<10))
{
++missilestockpiled;
if(missilefire>0)
{
--missilefire;
}
}
}
}
Create()
{
gun_3 = 0;
missilefire=0;
missilestockpiled=10;
wannafire1=FALSE;
wannafire2=FALSE;
surfaced=FALSE;
hatch1open=FALSE;
hatch2open=FALSE;
start-script SmokeUnit();
start-script SurfaceHatchNStuff();
}
Restore1()
{
sleep 3000;
wannafire1=FALSE;
}
Restore2()
{
sleep 3000;
wannafire2=FALSE;
}
AimWeapon1(heading, pitch)
{
signal SIG_AIM_1;
set-signal-mask SIG_AIM_1;
wannafire1=FALSE;
while(missilestockpiled==0)
{
sleep 200;
}
wannafire1=TRUE;
while(!hatch1open)
{
sleep 200;
}
start-script Restore1();
return (1);
}
// Arg! That FireWeapon1() has so many times
// almost the same duplicate paragraph
// It's nigh unreadable.
// I would have put all "sleep 100;hide flare"
// At the end, ouf of the "if"
// Or maybe I'd have use a macro
FireWeapon1()
{
signal SIG_FIRE1;
set-signal-mask SIG_FIRE1;
// Some signals because at the end
// there might be a long wait
//
--missilestockpiled;
//if( missilefire >= 0 AND missilefire < 10 )
//{
// WTF is the point of that IF?
// missilefire is always between 0 and 9 anyway
// And even if it' wasn't, then, well
// having that IF won't change anything
// since inside, you don't do anything
// if missilefire isn't 0,1,..9
if( missilefire == 0 )
{
show flare1a;
sleep 100;
hide flare1a;
}
if( missilefire == 1 )
{
show flare1b;
sleep 100;
hide flare1b;
}
if( missilefire == 2 )
{
show flare1c;
sleep 100;
hide flare1c;
}
if( missilefire == 3 )
{
show flare1d;
sleep 100;
hide flare1d;
}
if( missilefire == 4 )
{
show flare1e;
sleep 100;
hide flare1e;
}
if( missilefire == 5 )
{
show flare1f;
sleep 100;
hide flare1f;
}
if( missilefire == 6 )
{
show flare1g;
sleep 100;
hide flare1g;
}
if( missilefire == 7 )
{
show flare1h;
sleep 100;
hide flare1h;
}
if( missilefire == 8 )
{
show flare1i;
sleep 100;
hide flare1i;
}
if( missilefire == 9 )
{
show flare1j;
sleep 100;
hide flare1j;
}
//}
// Removed the } of the removed pointless if( missilefire >= 0 AND missilefire < 10 )
++missilefire;
// Pshh, either you do the "back to missile 0"
// in the if( missilefire == 9 ) { ... }
// Either you do it here, but why doing it in
// both place?
//if( missilefire == 10 )
//{
// missilefire = 0;
//}
if(missilestockpiled==0)
{
sleep 7000;
missilestockpiled=10;
}
}
AimFromWeapon1(piecenum)
{
piecenum = body;
}
QueryWeapon1(piecenum)
{
//if( missilefire >= 0 AND missilefire < 10 )
//{
// Think a bit a realise how pointless
// is that if, mkay?
// (Not to mention, .. if that condition
// would ever be false, which luckily should never
// happen, then you'd better tell the engine which piece
// to fire from nonetheless, or it'll choose by itself
if( missilefire == 0 )
{
piecenum = flare1a;
}
if( missilefire == 1 )
{
piecenum = flare1b;
}
if( missilefire == 2 )
{
piecenum = flare1c;
}
if( missilefire == 3 )
{
piecenum = flare1d;
}
if( missilefire == 4 )
{
piecenum = flare1e;
}
if( missilefire == 5 )
{
piecenum = flare1f;
}
if( missilefire == 6 )
{
piecenum = flare1g;
}
if( missilefire == 7 )
{
piecenum = flare1h;
}
if( missilefire == 8 )
{
piecenum = flare1i;
}
if( missilefire == 9 )
{
piecenum = flare1j;
}
//}
}
AimWeapon2(heading, pitch)
{
signal SIG_AIM_2;
set-signal-mask SIG_AIM_2;
wannafire2=TRUE;
while(!hatch2open)
{
sleep 200;
}
start-script Restore2();
return (1);
}
FireWeapon2()
{
hide missile;
// Where do you show it anyway?
}
AimFromWeapon2(piecenum)
{
piecenum = body;
}
QueryWeapon2(piecenum)
{
piecenum = missile;
}
AimWeapon3(heading, pitch)
{
signal SIG_AIM_3;
set-signal-mask SIG_AIM_3;
while(!gun_3)
{
sleep 100;
gun_3 = 1;
}
return (1);
}
FireWeapon3()
{
if(!gun_3)
{
sleep 10;
}
// I completly fail to see the point of that "sleep 10" if gun_3 is null.
// Since it does nothing, you migt as well... do nothing!
// Ah I understand now. It's meant to make the third weapon way a bit
// before firing anew once it has cycled around all its two fire point
// However ... 10ms is, like, shorter than frame.
// I don't think it'll make any difference if I remove it.
// Actually, maybe the one frame sleep is enough to get the new aiming
// called anew, and that new aiming has a sleep 100, about 0.1s,
// maybe almost noticeable. So ok I'll leave it.
// But I still think you'd be better of not bothering with
// that, considering the very small values.
//gun_3= gun_3 + 1;
//if( gun_3 >= 1 )
//{
//gun_3=0;
//}
gun_3 = !gun_3;
// I prefer this notation when a value has to switch between 1 and 0
// because it's only one line, and works even without initialisation
}
AimFromWeapon3(piecenum)
{
piecenum = body;
}
QueryWeapon3(piecenum)
{
//if( gun_3 == 0 )
//{
// piecenum = flare2;
//}
// And if gun_3 isn't 0? We'd fire from a random piece?
// Not good. You must specifiy a piece to fire from for any case.
piecenum = flare2;
}
StartMoving()
{
signal SIG_MOVE;
set-signal-mask SIG_MOVE;
moving = TRUE;
while( TRUE )
{
// I wish you'd make use of that "sfxtype.h"
// and type ... oh... are you sure wakes are
// pointed based? Because afaik they are
// vector based.
// Well, SFXTYPE_POINTBASED | SFXTYPE_WAKE2
// is exactly the same as 256 | 3
// however imo you should removed the SFXTYPE_POINTBASED |
// part, and make sure trailN have vectors pointing to
// where the trail should go. Or maybe the opposite way,
// In TA vertex 1 was start of wake, vertex 0 was end of wake
// and it was the contrary with "reverse wake",
// which is a bit unnatural, as we're accumstmoted to 0 -> 1 than to 1 -> 0
// But I think Spring inverts the role of "wake" and "reverse_wake"
emit-sfx SFXTYPE_POINTBASED | SFXTYPE_WAKE2 from trail1;
emit-sfx SFXTYPE_POINTBASED | SFXTYPE_WAKE2 from trail2;
emit-sfx SFXTYPE_POINTBASED | SFXTYPE_WAKE2 from trail3;
emit-sfx SFXTYPE_POINTBASED | SFXTYPE_WAKE2 from trail4;
sleep 200;
}
}
StopMoving()
{
signal SIG_MOVE;
moving = FALSE;
}
SweetSpot(piecenum)
{
piecenum = base;
}
Killed(severity, corpsetype)
{
explode body type BITMAPONLY | BITMAP3;
if( severity <= 25 )
{
corpsetype = 1;
return;
}
if( severity <= 50 )
{
corpsetype = 2;
return;
}
if( severity <= 99 )
{
corpsetype = 3;
return (0);
}
corpsetype = 3;
}
Also, you haven't rely specified what behavior you want, so I had to guess it. Currently:
- Wanting to fire 1 or 2 makes it surface.
- Wanting to fire 1 or 2 makes open corresponding hatch once surfaced.
- Not wanting to fire neither 1 nor 2 make it dives.
- Once 1 has depelted all ten missiles, it can't fire anymore.
- When it's dived, it slowly recharge missiles, one more every 0.66 seconds
- When it has fired the last of the ten missile, it waits 7sec then get all ten missiles back, surfaced or dived.
Essentially yes, weapon one is a 10 missile barrage that then has to wait before a fire (I would use a burst fire but that calls flares incorrectly), weapon 2 is a stockpiled weapon that is also vlaunch missile, and weapon 3 is a torpedo.. essentially..
Weapon 1 requires it to be surfaced to fire, and to open the appropriate hatch
Weapon 2 requires it to be surfaced to fire and to open the appropriate hatch
Weapon 3 can fire regardless of what is going on
Weapon 1 fires 10 missles and then sleeps for X time and can then fire again
Weapon 2 can only fire when it has stockpiled ammo..
I will check out your changes they dont look awful might make some alterations for my own understanding.. alot of my little wierd doings have to do with copy pasta and my general lack of complete scripting know how..
//I tried the stuff you setup there and It fires// thats the good news, the bad news is it yo-yo's between surface and dive infinitely even when its NOT being ordered to fire, I only want it to surface when it is told to fire weapon 1 or 2..
Weapon 1 requires it to be surfaced to fire, and to open the appropriate hatch
Weapon 2 requires it to be surfaced to fire and to open the appropriate hatch
Weapon 3 can fire regardless of what is going on
Weapon 1 fires 10 missles and then sleeps for X time and can then fire again
Weapon 2 can only fire when it has stockpiled ammo..
I will check out your changes they dont look awful might make some alterations for my own understanding.. alot of my little wierd doings have to do with copy pasta and my general lack of complete scripting know how..
//I tried the stuff you setup there and It fires// thats the good news, the bad news is it yo-yo's between surface and dive infinitely even when its NOT being ordered to fire, I only want it to surface when it is told to fire weapon 1 or 2..