How do you script a ship in a wing to attack

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
kaistern
Posts: 443
Joined: Mon, 30. Jun 14, 13:29
x3ap

How do you script a ship in a wing to attack

Post by kaistern » Tue, 11. Nov 14, 02:48

I am trying to write a script to give orders to a ship in a wing

Code: Select all

$target = get player tracking aim
$flag = get global variable: name='qw_flag'
$Wing = get predefined wing: wing=$flag
$wing.ships = get flight wing ship array: wing=$Wing
$ship = $wing.ships[0]
if $target-> is [PLAYERSHIP] a enemy
$ship = [THIS]-> call script '!wing.ship.attack.pck' :
else if $target-> is [PLAYERSHIP] a friend
$ship = [THIS]-> call script '!ship.cmd.protect.std' : target=$target stopifleaderdocked=[FALSE]
else
$ship = [THIS]-> call script '!ship.cmd.protect.std' : target=[PLAYERSHIP] stopifleaderdocked=[FALSE]
end
return null
where qw_flag equals blue wing

but nothing happens. I think the problem is in scripts i am calling (maybe). I also tried writing a script to test the protect script it was some thing like

Code: Select all

$target = get player tracking aim
$target= [THIS]-> call script '!ship.cmd.protect.std' : target=[playership] stopifleaderdocked=[FALSE]
and nothing happened. I tried numerous different attack/fight script but none of them worked and im stumped... any ideas? Running LU BTW[/code]
[ external image ]
Running LU 1.4.7 + XM-O 1.0 + Quick Wings 1.0
Rise of Phanon DiD LUV
Wrath of the Hive DiD XM-O
Try my script: Quick Wings for better wing control in LU!

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

Post by Cycrow » Tue, 11. Nov 14, 10:18

The problem is that you are not calling the scripts on the correct object.

in your second example, you need to run the protect script on the target object.

$target -> call script '!ship.cmd.protect.std'

This then runs the scripts, !ship.cmd.protect.std, on the object stored in $target.

[THIS] is the point to the object the script is being run on, in the case of global scripts, [THIS] will be null.
scripts run from hotkeys will be global and therfore dont have [THIS]
So all the scripts you are calling are being called as global scripts, which is not what you want

It will also be an idea to check that the target object is actually valid, as you wont always have a tracking aim (the ship you are currently targetting)

so use something like

Code: Select all

$target = get player tracking aim
skip if $target -> exists
   return null

kaistern
Posts: 443
Joined: Mon, 30. Jun 14, 13:29
x3ap

Post by kaistern » Tue, 11. Nov 14, 11:46

now I feel like a dumbass lol well at least now I know what [this] means :D

THANKS!!!!!
[ external image ]
Running LU 1.4.7 + XM-O 1.0 + Quick Wings 1.0
Rise of Phanon DiD LUV
Wrath of the Hive DiD XM-O
Try my script: Quick Wings for better wing control in LU!

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

Post by Joubarbe » Tue, 11. Nov 14, 12:41

A few problems in your script :

1/ The scripts you're calling either don't exist, or are not relevant. You want !wing.cmd.attack.std and !wing.cmd.protect.std.

2/ These scripts don't return anything, so you just have to write :

Code: Select all

 = [THIS] -> call script !wing.cmd.protect.std : target=$target stopifleaderdocked=[FALSE]
3/ But if you do this, your current script would have to wait the end of the command to continue, meaning that you're going to end with a lot of unfinished global tasks when you press a hotkey.

I won't go into details (read the MSCI Handbook, section 7), but you need to do that :

Code: Select all

START [THIS] -> call script !wing.cmd.protect.std : target=$target stopifleaderdocked=[FALSE]
That way, the script you call will be launched on another process (that's more complex than that) and your main script will continue and return null, as planned.

4/ You're going to have more problems, but we'll deal with that later :) You should continue to ask your questions on your other thread.

Post Reply

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