Request, scripts creating units

Request, scripts creating units

Requests for features in the spring code.

Moderator: Moderators

Post Reply
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Request, scripts creating units

Post by PauloMorfeo »

I bereby formaly request for the possibility for a script to create a unit, as in, make it spawn out of no where.

Imagine a coocoon spawning a unit from inside, after some time, like the Zerg in Starcrap. Many more usefull uses, too. It is eagerly needed for a thing in TLL...
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

There's currently no way to store a unit type in a variable so I don't think it's possible to implement such a function as there's no way to pass it the unit type you wish to create.
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

There must be some easy way that can be implemented...

After all, a building makes units. I don't understand the scripting system well but i'm imagining a function of the type:

Code: Select all

CreateUnit (UnitName, PosX, PosY, PosZ);
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Buildings don't create the units through script, the engine sees that the building is a factory and when a build order is placed the building gets told to open, then the unit is created and the building starts nanolathing it into existence.
User avatar
Guessmyname
Posts: 3301
Joined: 28 Apr 2005, 21:07

Post by Guessmyname »

You could use the Unit ID
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Units don't have IDs in Spring.
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

If code-wise people would give me a hand with a few things, i would give it a go at trying to implement that.

- I need to know where is the code responsible for «doing» what the scripts have.

- I need to know where i can find the code that is run whenever we use the cheat ".give unitnumber unitname".
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Scripts are handled by the COB interpreter, there should be a few files with COB in the name.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

You could build a unit at the same location and then have the "factory" destroy itself, to create "cocoons". Now that units can destroy themselves, a lot of things like that are possible.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

You mean like building a human as building (who offers a variety of units to build). Once the first unit has finished building, the building detonates itself (if that's possible; otherwise the unit has to) leaving behind a cocoon corpse model.
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

Ok, that was pretty dumb of me... I forgot that there is a middle program between the scripts and the COB interpreter, the COB compiler. I was having some trouble trying to understand the COB engine in Spring when i remembered it, i had to also mess with a COB compiler, like Scriptor, to make it also compile the new function, not just adjust the COB interpreter.

Was it not for that, it would have been a good effort. After all, the code to create units is already there (".cheat", ".give ArmCA"). But the fact is that that is over my league and i was really dumb forgeting about the compiler...

Bah!
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

I seem to have found a way to, somewhat easily, do that.

In the thread about emiting SFX through scripts:
http://taspring.clan-sy.com/phpbb/viewt ... 608#139608
PauloMorfeo wrote:Could that system be adapted to:

Code: Select all

	[SFXTypes]
	{
		explosiongenerator0=custom:EXPLOSION1;
		explosiongenerator1=custom:EXPLOSION2;
		explosiongenerator2=custom:CreateZerglings;
	}

Code: Select all

[CreateZerglings]
{
	[CreateUnit]
	{
		class = CCreateUnit;
		[properties]
 		{
			dir = dir;
			Distance=0;
 			Unit=ScZergling;
		}
	water=1;
 	air=1;
	underwater=1;
	ground=1;
	count=2;
	}
}
Making it call, into the position defined by the custom explosion generator script, the "cheat" «.give count zergling».

That would allow us to create units by scripts.
And shouldn't be very hard to implement. Code for unit creation is already there of when we ".cheat" + ".give ArmCa"...
Please, someone at least say that it has been seen, even if it is not going to be coded in a recent future.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

Abusing the particle generator to spawn stuff?... I don't know...
User avatar
MadRat
Posts: 532
Joined: 24 Oct 2006, 13:45

Post by MadRat »

You'd almost need a DeathType variable, a default of zero for spawning a wreckage whereas you could otherwise spawn off another unit. Or maybe you could spawn off multiple units within a building's footprint, like in C&C. I can see it now, a peewee dangling from a parachute pops out of every ARM aircraft destroyed mid-air.
User avatar
Neddie
Community Lead
Posts: 9406
Joined: 10 Apr 2006, 05:05

Post by Neddie »

That ability would be best implemented in Battletech. I mean, in the game universe, MechWarriors commonly eject from their Mechs... why not have an infantry unit up to start the fight up toe to toe?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

This is all possible, however... it'd require reserving yet another bunch of IDs for "FX" in memory, or (a more elegant solution) we could write up a new bytecode to be watched (a "Create"), and then have the COB interpreter check for that bytecode and execute the appropriate instructions. It'd just require replacement of one file with Scriptor, and a very minor change in the COB interpreter.

However, from there, the implementation might be a bit difficult. While I see no reason you couldn't just spawn it right at the point... you'd need to make sure it never spawned underground, etc.

Personally, this is one of those things that makes me more sure than ever that the OSRTS project is necessary.
User avatar
MadRat
Posts: 532
Joined: 24 Oct 2006, 13:45

Post by MadRat »

Wouldn't it be more efficient to be a spinoff of the death sequence from the unit and not from the cob? I'd have to assume the scripted death animation is only called after the corpse is already revealed, since the corpses seem to spring up at that time. You could drop a newly spawned unit down instead of a corpse.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

The corpse is spawned and the unit removed once the function Killed() returns. The cob actively influences the death.
Post Reply

Return to “Feature Requests”