Is it possible to modify preexisting commands?
Moderators: Moderators for English X Forum, Scripting / Modding Moderators
Is it possible to modify preexisting commands?
In particular, I want to remove the "Auto Docking" feature from the "Protect me" command. How would one go about implementing such a change?
I don't really know about Protect me specifically, but I can tell you that most if not all of these commands can be modified and tweaked. I think a better strategy might be to replace that command for all player assets and redirect the command to a different script.
Maybe something like:
1. Backup your save games.
2. Download X-Studio
3. Configure X-Studio for your flavor of game (TC/AP whatever).
4. Create a new script in the scripts folder (or addon/scripts folder) lets call it: setup.shirudo.protect.xml
5. Create a new script call it plugin.shirudo.protect.command.xml
Test it to make sure you receive the subtitle message hello world when you order your ship to protect you, if you do then you've successfully overridden the protect command for your assets. Then start adding your own logic to your customized protect command.
Maybe something like:
1. Backup your save games.
2. Download X-Studio
3. Configure X-Studio for your flavor of game (TC/AP whatever).
4. Create a new script in the scripts folder (or addon/scripts folder) lets call it: setup.shirudo.protect.xml
Code: Select all
$key = [COMMAND_PROTECT]
set script command upgrade: command=$key upgrade={Fight Command Software Mk1}
global script map: set: key=$key, class=[Ship], race=[Player], script='plugin.shirudo.protect.command', prio=0
Code: Select all
* your ai logic here
display subtitle text: text='Hello World' duration 10000 ms
Well the thing is all ship movement scripts eventually boil down to one of the flight commands... In the case of protect that would probably be 'escort ship':
So your protect command could really just be a block code like:
And your script would probably function like the vanilla protect (though without support for formations which you would need to add). The problem is that vanilla escort isn't ideal for you so maybe you need more complex like:
From there you just keep adding conditions and such to tweak the behavior. For example, if you resume following the player the moment they undock then you may fly headlong into a station, so maybe you wait 10-20 seconds after undock before calling escort ship. You could add other conditions in addition to docked to maybe check the distance to keep the ship from getting too close to the player or whatever.
My guess is that vanilla protect probably calls !move.follow.template which is a generic follow script that you yourself could also call. In fact it is usually best to call built in scripts whenever possible, but in your case you probably need to change the logic at the lowest level so I think your better off not copying too much vanilla code so that you can fine tune the behavior.
So your protect command could really just be a block code like:
Code: Select all
while [TRUE]
=[THIS]->escort ship [PLAYERSHIP]
end
Code: Select all
while [TRUE]
if [PLAYERSHIP]-> is docked
* do something different, call a patrol script, make it follow a wingmate, whatever.
= wait randomly from 800 to 1200 ms
else
= [THIS] -> escort ship [PLAYERSHIP] : timeout=3000 ms
end
end
My guess is that vanilla protect probably calls !move.follow.template which is a generic follow script that you yourself could also call. In fact it is usually best to call built in scripts whenever possible, but in your case you probably need to change the logic at the lowest level so I think your better off not copying too much vanilla code so that you can fine tune the behavior.
Last edited by zanzal on Fri, 31. Jan 14, 09:29, edited 2 times in total.
- Serial Kicked
- Posts: 3823
- Joined: Fri, 12. Aug 05, 20:46
If it helps, that's my custom protect script. It's based on the vanilla script (which you can't see in the editor, you'll have to use IE to see it from the folder) and avoid docking at the thing it's trying to protect
It's very basic but it works and can use the jumpdrive when needed
edit: // you'll have to replace the call to anarkis.lib.cmd.jumpnearobject by a call to the default jump script or command, though.
Code: Select all
argument
1: protect , Var/Ship/Station , 'protect target'
001 [THIS] -> set command: COMMAND_PROTECT target=$protect target2=[FALSE] par1=null par2=null
002 $flag = [Find.Nearest] | [Find.Enemy]
003
004 skip if not [THIS] -> is docked
005 @ |= [THIS] -> call script '!move.undock' :
006
007 while $protect -> exists
008 @ |= wait 100 ms
009 |$distance = get distance between [THIS] and $protect
010 |$protect.sector = $protect -> get sector
011 |if $protect.sector == [SECTOR]
012 ||if $distance > 5000
013 @ |||= [THIS] -> call script '!move.movetoobject' : Target=$protect Range=4500
014 ||end
015 |else if [OWNER] != Player
016 ||= [THIS] -> add 80 units of Energy Cells
017 @ ||= [THIS] -> call script 'anarkis.lib.cmd.jumpnearobject' : destination=$protect
018 |else
019 @ ||= [THIS] -> call script 'anarkis.lib.cmd.jumpnearobject' : destination=$protect
020 |end
021 |$enemy = find ship: sector=[SECTOR] class or type=Moveable Ship race=null flags=$flag refobj=$protect maxdist=10000 maxnum=1 refpos=null
022 |if $enemy -> exists
023 @ ||= [THIS] -> call script '!fight.attack.object' : the victim=$enemy follow in new sector=[FALSE] Only attack shields=[FALSE]
024 |else
025 @ ||= [THIS] -> call script '!move.idle.timeout' : timeout in sec=10 wait while docked=[FALSE]
026 |end
027 end
028
029 return null
edit: // you'll have to replace the call to anarkis.lib.cmd.jumpnearobject by a call to the default jump script or command, though.
X3:TC/AP Pirate Guild 3 - Yaki Armada 2 - Anarkis Defense System
Anarkis Gaming HQ
Independent Game Development
X3 Scripting and Modding Station
Anarkis Gaming HQ
Independent Game Development
X3 Scripting and Modding Station