Daan sent me a PM indicating he was trying to just compile some of my code from P.U.R.E., and was mystified about all of the includes I use, etc.
Daan, here... use this stuff, instead. It's simple, it'll work, and it's a lot less work than backtracking through all the stuff I do in P.U.R.E., which I probably shouldn't have pointed you towards, given that it's not exactly newbie-friendly and well-commented yet...
To help you along, here is a complete scripted solution for a simple, 2-gun fighter, using a unified aiming arc. This would be suitable for, say, a fighter, like the fighters in Battlestar Galactica, where we don't care about moving parts, etc. It also includes code for a flare to be displayed, and for an explosion FX script to be run upon death (which I personally prefer, because then you can randomize the outcomes, but you armchair-coder people, feel free to whine, this was free advice, after all):
Hereby released, into Public Domain:
BOS CODE
This is really all the animation code you need, for something small that's tiny on-screen, and aims when its weapon's vector roughly matches a target. Oh, sure, you
can make this fancier. But you don't have to, and this will work, right out of the box.
Code: Select all
//MyFighter Script, written by Argh. Public Domain.
/*These defines basically just assign a number value to a string- whenever we use "GUNFLARE_FLASH", for example, the compiled version just reads "1024". Technically, you don't even have to bother with this, but I find it makes scripts a lot easier to read, which is important when maintaining them...*/
#define GUNFLARE_FLASH 1024
#define EXPLOSION_FX 1024+1
/* Here are all the pieces in the .S3O. Note that all pieces in the .S3O need to have the same names exactly- case must be the same (I always use lower-case).*/
piece base, flare_r, flare_l;
/* Here's our single static variable, used to keep track of which gun we're firing.*/
static-var gun;
AimFromWeapon1(piecenum)
{
base; /*We just use the base here, because the weapon never really aims, it just returns (1) if the aiming-arc is satisfied. If using a turret or whatever, then you'd need to use something different here.*/
return (0);
}
/*AimWeaponX(), where X = the weapon's number in the FBI, is how you call aiming conditions. When the weapon's vector == the vector required by the target - the value of Tolerance in the weapon's TDF, the weapon will fire, in theory.*/
AimWeapon1(heading,pitch)
{
//Immediately return (1) to open fire, no motion is required
return (1);
}
/*ShotX() is something KDR_11k added to the last version of Spring. Very, very, very useful. Basically, ShotX() is called right after AimWeaponX() returns TRUE. It allows for stuff like global variables to be changed, so that weapons can change their firing-point in the middle of firing- previously impossible, due to Spring's weird volley code. Very useful, and while you don't have to do this in ShotX(), I suggest it. Also note that I'm doing the emit-sfx here, instead of doing it in FireWeapon(). I found that doing it here works just as well, and means that I can almost skip using FireWeapon entirely, for multi-point weapon systems.*/
Shot1(piecenum)
{
if (gun == 0)
{
emit-sfx GUNFLARE_FLASH from flare_r;
} else
{
emit-sfx GUNFLARE_FLASH from flare_l;
}
gun = !gun;
//Variable "gun" equals the logical-NOT of value of gun, i.e., either 1 or 0
}
/*QueryWeaponX() is what point the weapon actually comes out of. It does not care whether this is "right" or not, so it had better be "right" by the time it gets here!*/
QueryWeapon1(piecenum)
{
if (gun == 0)
{
piecenum = flare_r;
} else
{
piecenum = flare_l;
}
}
/*FireWeaponX() is normally where we show stuff like flares, do animations, etc. I have found that there aren't many advantages to doing it here instead of ShotX(), frankly.*/
FireWeapon1()
{
return (0);
/* Always include a return (0) here, or for some strange reason, Spring will run the Killed() script...*/
}
/*Create() is what happens when the Unit is put into the gameworld. You can do lots of amazing stuff here- everything from move all of the pieces to preset positions (I do this a lot in P.U.R.E.) to starting scripts that have to run all of the time, until your Unit dies, to hiding stuff you need to include in the model, like flares, but which can work even if it's invisible, like flares.*/
Create()
{
hide flare_r;
hide flare_l;
}
/*Killed starts when Spring is informed that a Unit has less than 0 health remaining. Killed scripts can call other scripts, to perform animations or do other tasks, but eventually all scripts need to return to the Killed() script, which needs to return (somevalue), which literally returns a value to Spring, which it can use to determine what Corpse should be shown. Or the Unit needs to be removed from the gameworld via LUA, but that goes well outside the scope of this simple code example.*/
Killed()
{
hide base;
emit-sfx EXPLOSION_FX from base;
return (0);
}
FBI
This is a sample FBI for our simple fighter, just showing structure and a few basic tricks, including customized flight code parameters (
safe ones, you can actually hack more of the flight code, if you're willing to put up with borked results).
Hereby released into Public Domain:
Code: Select all
[UNITINFO]
{
//Internal settings
Name=MyFighter;
UnitName=MyFighter;
ObjectName=MyFighter.s3o;
Description=: A sample fighter.;
BuildPic=MyFighter.JPG;
Category=EVERYTHING;//Only needed if you need to call it by aiming conditions
//Unit limitations and properties
MaxDamage=2000;
SightDistance=512;
SoundCategory=MyFighter;
FootprintX=3;
FootprintZ=3;
//Energy and metal related
BuildTime=1;
BuildCostEnergy=1;
BuildCostMetal=1;
//Abilities
CanGuard=1;
ArmorType=default;//CHANGE TO APPROPRIATE CATEGORY
//Abilities new to Spring
iconType=MyFighter;//CHANGE TO MATCH ICONTYPE
shownanoframe=1;
nanocolor=0 0.7 1.0;// SEE WIKI
//Weapons and related
ExplodeAs=NOWEAPON;//SEE "NOWEAPON" IN KDR_11k's WEAPON CATEGORY DOCUMENTATION IN MODS THREAD
SelfDestructAs=NOWEAPON;
SelfDestructCountdown=1;
Weapon1=MYFIGHTER_GUN;
weaponmaindir1=0 0 1;//FORWARD ARC
maxangledif1=90;//90 DEGREE ARC FORWARD
OnlyTargetCategory1=EVERYTHING;
///////////////////////////////////////////////////////////FLIGHT CODE
collisionSphereScale=1.0;
Upright=0;
floater=0;
canSubmerge=0;
mass=100;
CanMove=1;
CanFly=1;
loopbackAttack=1;
HoverAttack=0;
BrakeRate=0.6;
Acceleration=4;
MaxVelocity=17;
turnRate=450;
CruiseAlt=500;
wantedHeight=500;
maxHeightDif=400;
[SFXTypes]
{
explosiongenerator0=custom:GUNFLARE_FLASH;
explosiongenerator1=custom:EXPLOSION_FX;
}
Now, you just need to have stuff all named appropriately, and to make some simple FX scripts for the gunflare and the explosion, and you're good to go.
Daan also asked about how I did the "rocket exhaust" flares, in P.U.R.E..
Tell ya what, Daan: get one of your fighters working, using this script and FBI, make a gunflare flash and an explosion, and I'll post the code for doing that, and explain how it works.
It's not complicated or anything, there are at least a dozen people here who know how to do this simple stuff. I just want you to put the work into making this work before I hand you more stuff- you have to walk before you can run, ok? Doing a simple script with a few FX is just a starting-place, for a project like yours- you're not really going to be doing a lot of fancy BOS animations, I'd think, given your content, so you need to sit down and learn how to work with Custom Explosion Generator code, to make it look really pretty- and just copy-pasting from other people's projects, while it'll help get you started, won't really help you get to where you want, and I don't have the time to help you a lot, if you won't help yourself
So, get this stuff working, including some CEGs (that'll be the hardest part, probably)... then I'll show you how to do the rocket FX.
[EDIT]Tidied a few things that weren't done completely efficiently (removed two IFs, replace by ELSE, found a minor typo), added a lot more explanation.