EnglishGermanFrenchRussianItalianSpanish
Log inRegister
 
Controlled spawning(Noob scripting question)
Post new topic Reply to topic
View previous topic :: View next topic
Author Message
CloneSargaent





Joined: 16 Jul 2014
Posts: 37 on topic

Thank you for registering your game
PostPosted: Thu, 31. Aug 17, 01:18    Post subject: Controlled spawning(Noob scripting question) Reply with quote Print

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.

Back to top
View user's profile Send private message
Joubarbe





Joined: 31 Oct 2006
Posts: 2635 on topic
Location: France
Thank you for registering your game
PostPosted: Thu, 31. Aug 17, 05:33    Post subject: Reply with quote Print

Code:

$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.


_________________
Mayhem - Satellites Monitoring - Internal Distribution Network - ADS (Joubarbian Edition) - Bounty Board - The Joubarbian Toolkit - EasyConnect
Back to top
View user's profile Send private message
CloneSargaent





Joined: 16 Jul 2014
Posts: 37 on topic

Thank you for registering your game
PostPosted: Thu, 31. Aug 17, 23:56    Post subject: Reply with quote Print

Code:
  $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.

Back to top
View user's profile Send private message
Jack08





Joined: 25 Dec 2005
Posts: 2956 on topic
Location: Australia
Thank you for registering your game
PostPosted: Fri, 1. Sep 17, 01:02    Post subject: Reply with quote Print

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.


_________________

"One sure mark of a fool is to dismiss anything that falls outside his experience as being impossible."
―Farengar Secret-Fire
Back to top
View user's profile Send private message
Joubarbe





Joined: 31 Oct 2006
Posts: 2635 on topic
Location: France
Thank you for registering your game
PostPosted: Fri, 1. Sep 17, 03:42    Post subject: Reply with quote Print

My bad, I forgot how great these new commands are Smile

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

Cycrow in his Cheat package uses that code:

Code:

$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)


_________________
Mayhem - Satellites Monitoring - Internal Distribution Network - ADS (Joubarbian Edition) - Bounty Board - The Joubarbian Toolkit - EasyConnect
Back to top
View user's profile Send private message
CloneSargaent





Joined: 16 Jul 2014
Posts: 37 on topic

Thank you for registering your game
PostPosted: Mon, 4. Sep 17, 03:14    Post subject: Reply with quote Print

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:
$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


Back to top
View user's profile Send private message
Joubarbe





Joined: 31 Oct 2006
Posts: 2635 on topic
Location: France
Thank you for registering your game
PostPosted: Mon, 4. Sep 17, 08:31    Post subject: Reply with quote Print

Code:

* 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:

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:

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.


_________________
Mayhem - Satellites Monitoring - Internal Distribution Network - ADS (Joubarbian Edition) - Bounty Board - The Joubarbian Toolkit - EasyConnect
Back to top
View user's profile Send private message
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)



Joined: 15 Nov 2004
Posts: 20463 on topic
Location: London
Thank you for registering your game
PostPosted: Mon, 18. Sep 17, 16:08    Post subject: Reply with quote Print

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


_________________
My Scripts | MY X3TC Scripts | X3 Plugin Manager | Custom Gui
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic Reply to topic
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum
Control Panel
Login Data
The time now is Sun, 19. Nov 17, 18:03

All times are GMT + 2 Hours


Board Security

Copyright © EGOSOFT 1989-2017
Powered by phpBB © 2001, 2005 phpBB Group
Template created by Avatar & BurnIt!
Debug: page generation = 0.56826 seconds, sql queries = 22