[Script Request - Mayhem] Fleet command for multiple "flagging for tug"

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
aurelcourt
Posts: 267
Joined: Fri, 20. Oct 17, 09:20
x4

[Script Request - Mayhem] Fleet command for multiple "flagging for tug"

Post by aurelcourt » Sat, 27. Jul 19, 20:54

Hello,

Following the many improvements of the fleet system in Mayhem, I'm looking for someone who could create a "simple" script for me (as my coding knowledge is level 4 on a scale of 100, and the few times I tried something with Xstudio, it was a failure !! :roll: )

--- Fleet : Flag damaged fighters for Tug ---

1) RP purpose : after a fight, call the tug to gather all damaged fighters home for repairs. (because I don't like the idea of fighters with a jump drive !).

2) Description :

- command selected from a Fleet Leader command console, under "Fleet" (added below "Call to Arms" and the other existing commands)

- checks all fighters in this fleet
- if their hull <100% then run the "Flag for Tug" (LitCube"s) command on each of them

---------
That's all !

Thanks in advance to the person who could create this for me :-)

Best regards,
Aurélien

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

Re: [Script Request - Mayhem] Fleet command for multiple "flagging for tug"

Post by Joubarbe » Sat, 27. Jul 19, 21:39

Hint 1: "Mayhem.Fleet.Repair".
Hint 2: "Cmd.Tug.Flag".
Hint 3: You cannot add more commands to the fleet menu.

aurelcourt
Posts: 267
Joined: Fri, 20. Oct 17, 09:20
x4

Re: [Script Request - Mayhem] Fleet command for multiple "flagging for tug"

Post by aurelcourt » Sat, 27. Jul 19, 22:15

Thanks for that !

Could this possibly work? (with a hotkey defined -----------> how can I add that to the command menu of a ship instead?)
$currentsector = [PLAYERSHIP]-> get sector
$allships = $currentsector-> get player owned ship array from sector
$fighters = array alloc: size=0

for each $ship1 in array $allships
$class = $ship1-> get object class
do if $class == [Fighter]
insert $ship1 into array $fighters at index 0
end

for each $ship2 in array $fighters
$hull = $ship2-> get hull percent
do if $hull < 100
=[THIS] -> call script 'Cmd.Tug.Flag' : Ship=$ship2
end

return null




?
First ever try to write a script :-)


>EDIT : doesn't work :-p

aurelcourt
Posts: 267
Joined: Fri, 20. Oct 17, 09:20
x4

Re: [Script Request - Mayhem] Fleet command for multiple "flagging for tug"

Post by aurelcourt » Sun, 28. Jul 19, 01:53

Tried this as well :

----------------------------
$currentsector = [PLAYERSHIP]-> get sector
$allships = $currentsector-> get player owned ship array from sector

for each $ship in array $allships
$class = $ship-> get object class
if $class == [Fighter]
=$ship-> call script 'Cmd.Tug.Flag': [THIS]= $ship
end
end

return null

----------------

but won't work either... anywone could explain to me what I'm doing wrong? Sorry if it's obvious...

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

Re: [Script Request - Mayhem] Fleet command for multiple "flagging for tug"

Post by Joubarbe » Sun, 28. Jul 19, 02:36

Don't use direct comparisons with classes (a ship can have multiple classes).

Code: Select all

$isInFleet = $ship -> is in fleet
$hullPercent = $ship -> get hull percent
if $isInFleet AND $hullPercent < 100
  do if $ship -> is of class [Fighter]
    START [NULL] -> call script 'Lib.Cmd.Tug.Flag': Ship=$ship
end

aurelcourt
Posts: 267
Joined: Fri, 20. Oct 17, 09:20
x4

Re: [Script Request - Mayhem] Fleet command for multiple "flagging for tug"

Post by aurelcourt » Sun, 28. Jul 19, 13:48

That works thanks a lot ! :-)

- For the direct comparison, you meant mine would always return FALSE? (eg: if ship = fighter + small ship, then ship == fighter is always FALSE ?)

- How do you know how to use the script properly? You wrote is as "START [NULL] ........" why this typo?

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

Re: [Script Request - Mayhem] Fleet command for multiple "flagging for tug"

Post by Joubarbe » Sun, 28. Jul 19, 14:40

Comparing two object classes gives unexpected results.

You should read the MSCI handbook and read some tutos. START is a vast subject. In a nutshell: in X3, you run scripts either on objects (START $ship), or globally (START [NULL]), and in the former, you have to choose on what tasks you want to run your script. See the X-Studio tooltip for the "begin task" command for more info on that subject.

aurelcourt
Posts: 267
Joined: Fri, 20. Oct 17, 09:20
x4

Re: [Script Request - Mayhem] Fleet command for multiple "flagging for tug"

Post by aurelcourt » Sun, 28. Jul 19, 19:31

Thanks very much !

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

Re: [Script Request - Mayhem] Fleet command for multiple "flagging for tug"

Post by Cycrow » Mon, 29. Jul 19, 10:51

Object classes are in a Hierarchy, so using get object class will only return the actual class of the object and not all the others it belongs too.

The command, is of class, will check against the whole hierarchy.

For example, an M5 would be:

M5
Fighter
Little Ship
Moveable Ship
Ship
Object

aurelcourt
Posts: 267
Joined: Fri, 20. Oct 17, 09:20
x4

Re: [Script Request - Mayhem] Fleet command for multiple "flagging for tug"

Post by aurelcourt » Wed, 7. Aug 19, 12:09

Thanks for that, makes sense.

Trying to refine the script slowly, so far I have this :

Code: Select all


$sector = [PLAYERSHIP]-> get sector
$ships = get ship array: of race [Player] class/type=[Fighter]

for each $ship in array $ships

	$isInFleet = $ship-> is in fleet
	$hullPercent = $ship-> get hull percent
	
		if $isInFleet AND $hullPercent < 100
			$ship-> remove from fleet
			$ship-> set homebase to null
			START [NULL]-> call script 'Lib.Cmd.Tug.Flag' : Ship=$ship
			$ship-> set command: [COMMAND_MOVE_POS]  target=$sector target2=0 par1=0 par2=0
		end
end


return null


1/ Am I gonna get nothing in my array with the

Code: Select all

get ship array: of race [Player] class/type=[Fighter]
or will it indeed take the fighters (even if they are also small ships etc...)

2/ Is my last line the correct way to order that ship to move to sector center?

3/ When I run it (with hotkey), it only works for ONE ship in the sector, I have to press it multiple times to get all damaged fighters flagged... any idea why the FOR EACH loop doesn't apply for all ships?


Thanks again in advance for your tips :-)

Post Reply

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