Controlled spawning(Noob scripting question)

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
CloneSargaent
Posts: 68
Joined: Wed, 16. Jul 14, 19:27
x4

Controlled spawning(Noob scripting question)

Post by CloneSargaent » Thu, 31. Aug 17, 01:18

I want to spawn a specific number of Xenon ships and specific number of ships for each class. For example 6 m6s, 4 m7s, 2 m2s, and 1 m1. But I don't know how to (or if I could) set up an array to do this. I should try using tokens like how MBRR and IR 2.0 uses them? Or would it be better typing up loops for each ship? For TC scripting not AP scripting.

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Thu, 31. Aug 17, 05:33

Code: Select all

$mainType = [SSTYPE_SHIP]
$subTypes = get number of subtypes of maintype $mainType

$allTypes = array alloc: size=0

while $subTypes
  dec $subTypes
  $shipType = get ware from maintype $mainType and subtype $subTypes
  $typeRace = get maker race: shiptype=$shipType
  $typeClass = get class of type: subtype= $shipType

  if ($typeRace == $race OR $race == null) AND ($typeClass == $class OR $class == null)
    append $shipType to array $allTypes
  end
end
This script takes two optional arguments: $race and $class.

CloneSargaent
Posts: 68
Joined: Wed, 16. Jul 14, 19:27
x4

Post by CloneSargaent » Thu, 31. Aug 17, 23:56

Code: Select all

  $typeClass = get class of type: subtype= $shipType
X-Studio Complier says:

IDS_GENERATION_COMMAND_SYNTAX_INVALID: Unrecognised or incompatible script command on line 1 : ' $typeClass = get class of type: subtype= $shipType'

IDS_GENERATION_COMMAND_SYNTAX_NOT_FOUND: Cannot find a corresponding X³ Terran Conflict command syntax entry from the hash 'getclassoftype:subtype='

Sorry if wasn't noticeable in my first post but my script I'm writing is for TC not AP. So AP commands/syntax won't work.

User avatar
Jack08
Posts: 2993
Joined: Sun, 25. Dec 05, 10:42
x3tc

Post by Jack08 » Fri, 1. Sep 17, 01:02

That command is actually an LU command, so it wouldn't even work in base AP unfortunately.

I have bad news, unfortunately, this an rather annoying problem in the base game, there is no easy way to select a ship type, most scripts from the TC erra usually maintain a white-list of ship types for classes/races, or a blacklist vise versa...

A simpler, tho less efficient solution, could be to search the universe using find commands with the Random flag, specifying race and class, and then hope for valid results, or iterating over every ship in the universe at startup time and building a cached array from that data in a setup script. These methods are spotty sometimes.

The only garanteed way to make sure you have iterated every ship in TShips, would be to do something similar to what Joubarbe posted, but you would have to actually spawn the ship, in order to get the information you need, and even then, because of the horrible state of TShips in vanilla/most mods, you cant even trust that something with a valid maker race, is even a valid ship.... Or it could outright crash the game in case of invalid data.

If your looking for a specific example of this ship-spawning messiness, download IR2.0 and look at xtl.lib.ship.choose

-----
EDIT:

if you only ever want to spawn xenon ships just maintain an manually defined 2-d array of them (Array[Class][Types]), its not too much work and the best/simplest/easiest option.
[ external image ]
"One sure mark of a fool is to dismiss anything that falls outside his experience as being impossible."
―Farengar Secret-Fire

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Fri, 1. Sep 17, 03:42

My bad, I forgot how great these new commands are :)

What about "get ship type array: maker race=$race class=$class"?

Cycrow in his Cheat package uses that code:

Code: Select all

$aShipTypes = array alloc: size=0
for each $race in array $aRaces using counter $count
  $shipTypes = get ship type array: maker race=$race class=$class
  if size of array $shipTypes
    $size = size of array $shipTypes
    $main.size = size of array $aShipTypes
    $resize = $size + $main.size
    resize array $aShipTypes to $resize
    copy array $shipTypes index 0 ... $size into array $aShipTypes at index $main.size
  end
end

* remove bad variants
for each $ship.type in array $aShipTypes using counter $count
  $variant = get ship variation: subtype=$ship.type
  if $variant >= 16 AND $variant <= 19
    remove element from array $aShipTypes at index $count
  end
end
(lib.cycrow.getshiptypefromclass)

CloneSargaent
Posts: 68
Joined: Wed, 16. Jul 14, 19:27
x4

Post by CloneSargaent » Mon, 4. Sep 17, 03:14

Sorry for the late reply, I will give the code Joubarbe posted above a try before attempt to make my own 2-d array like Jack08 suggested. I have another question; before I posted this topic I started making script that should spawn a J(or 2 depending on the station) and a large group of fighters in its hanger. Have not tested but I want know if my code is good or is there more efficient way of doing it? Also want ask how to setup a respawn timer or do need write in something to make script restart after the ships die?

Code: Select all

$Sector = find station: sector=[SECTOR] class or type=$Station race=[Xenon] flags=0 refobj=$Value maxdist=0 maxnum=0 refpos=$Array
if $Station == {Xenon Station (DOCK_X_EQUIP)}
$Ship = create ship: type={Xenon J} owner=[Xenon] addto=$Station x=null y=null z=null
$Max = $Ship-> get max upgrades for upgrade {Rudder Optimisation}
= $Ship-> install $Max units of {Rudder Optimisation}
$Maxtype = $Ship-> get max. shield type that can be installed
$Installed = $Ship-> get amount of ware $Maxtype in cargo bay
$Maxshields = $Ship-> get number of shield bays
$Maxshields = $Maxshields - $Installed
$Installed = $Ship-> install $Maxshields units of $Maxtype
$Ship-> add default items to ship
$Ship-> set race logic control enabled to [FALSE]

$fighters = 0
while $fighters <= 40
$Ship = create ship: type={Xenon L} owner=[Xenon] addto=$Ship x=null y=null z=null
$Maxtype = $Ship-> get max. shield type that can be installed
$Installed = $Ship-> get amount of ware $Maxtype in cargo bay
$Maxshields = $Ship-> get number of shield bays
$Maxshields = $Maxshields - $Installed
$Installed = $Ship-> install $Maxshields units of $Maxtype
$Ship-> add default items to ship
$Ship-> set race logic control enabled to [FALSE]
inc $fighters
end
end

do if $Station == {Xenon Shipyard}
$Numberofships = 0
while $Numberofships < 2
$Ship = create ship: type={Xenon J} owner=[Xenon] addto=$Station x=null y=null z=null
$Max = $Ship-> get max upgrades for upgrade {Rudder Optimisation}
= $Ship-> install $Max units of {Rudder Optimisation}
$Maxtype = $Ship-> get max. shield type that can be installed
$Installed = $Ship-> get amount of ware $Maxtype in cargo bay
$Maxshields = $Ship-> get number of shield bays
$Maxshields = $Maxshields - $Installed
$Installed = $Ship-> install $Maxshields units of $Maxtype
$Ship-> add default items to ship
$Ship-> set race logic control enabled to [FALSE]
inc $Numberofships

$fighters = 0
while $fighters <= 40
$Ship = create ship: type={Xenon LX} owner=[Xenon] addto=$Ship x=null y=null z=null
$Maxtype = $Ship-> get max. shield type that can be installed
$Installed = $Ship-> get amount of ware $Maxtype in cargo bay
$Maxshields = $Ship-> get number of shield bays
$Maxshields = $Maxshields - $Installed
$Installed = $Ship-> install $Maxshields units of $Maxtype
$Ship-> add default items to ship
$Ship-> set race logic control enabled to [FALSE]
inc $fighters
end
end

$Max = $Ship-> get max upgrades for upgrade {Engine Tuning}
= $Ship-> install $Max units of {Engine Tuning}
$Max = $Ship-> get max upgrades for upgrade {Rudder Optimisation}
= $Ship-> install $Max units of {Rudder Optimisation}
$Max = $Ship-> get max upgrades for upgrade {Cargo Bay Extension}
= $Ship-> install $Max units of {Cargo Bay Extension}
$Installed = $Ship-> add -99 units of {Fighter Drone}
$Installed = $Ship-> add -99 units of {Fighter Drone MKII}
$Installed = $Ship-> add -99 units of {Wasp Missile}
$Installed = $Ship-> add -99 units of {Tornado Missile}
$Installed = $Ship-> add -99 units of {Typhoon Missile}
$Installed = $Ship-> add -99 units of {Wraith Missile}
$Installed = $Ship-> add -99 units of {Poltergeist Missile}
$Installed = $Ship-> add -99 units of {Flail Barrage Missile}
$Installed = $Ship-> add -99 units of {Ghoul Missile}
$Ship-> set local variable: name='ImprovedXenon.DefShip' value=[TRUE]

START $Ship-> call script '!ship.cmd.defend.station.pl.pck' : argument1=$Station

* Respawn time
if [SIGNAL_KILLED]
= wait 600000 ms
end

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Mon, 4. Sep 17, 08:31

Code: Select all

* Respawn time 
if [SIGNAL_KILLED] 
  = wait 600000 ms 
end
This doesn't do anything. Your script in its current state is a one-time procedure. You need to put all your code into a loop and check a timer. Something like this:

Code: Select all

while 1
  $playtime = playing time
  $time = [THIS] -> get local variable: name='timerName'
  if ($playtime - $time) >= 600 // This is in seconds.
    [THIS] -> set local variable: name='timerName' value=$playtime
    // Do your stuff here, so that every 600 seconds, your ships spawn.
  end
  = wait 1000ms
end
You can also check if $Ship-> exists in that block.

Code: Select all

START $Ship-> call script '!ship.cmd.defend.station.pl.pck' : argument1=$Station 
Don't put the file extension. X-Studio will automatically add the parameters if the script is found.

Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22228
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow » Mon, 18. Sep 17, 16:08

In AP, there is the command, $class = get ship class from subtype: $shiptype

Post Reply

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”