I'm new to this forum, relatively new to X games, and I have never written a video game mod or script before. I have dabbled in small edits to existing mods for games before, but that's the most.
That being said, my programming and troubleshooting knowledge is quite good since I deal with reading and troubleshooting code for my job, and it interests me--so I should understand what your saying and can usually work through code fairly well.
I am using SirNukes Mod Support APIs, and his Hotkey Collection as a starting point, with the python pipe server.
The intent of my hotkeys is fairly simple (at least I thought) for now--I want to make at least two hotkeys. One which triggers a fleet attack command on my target,
Some possibly useful information:
- I am running X4 on Steam
- I could not get anything to work when I was editing the steam 01.dat file, so I pulled the source code from git and am editting the SN_Hotkeys.xml file
- All other hotkeys work
Code: Select all
<cue name="Attack_Target" instantiate="true" namespace="this">
<conditions>
<event_cue_signalled/>
<!-- Verify the player has a target selected. -->
<check_value value="player.target"/>
<!-- Verify the player is piloting a ship.-->
<!-- TODO: check this in hotkey api instead (space/flying context).-->
<check_value value="player.occupiedship"/>
</conditions>
<actions>
<!-- Debug message. -->
<raise_lua_event name="'directChatMessageReceived'" param="'KeyCapture;Starting event_attack_started'"/>
<debug_text text="'KeyCapture Triggered order.player.attack'" filter="general"/>
<run_script name="'order.player.attack'">
<param name="primarytarget" value="player.target " />
<param name="allowothertargets" value="false" />
<param name="squad_attack" value="true" />
</run_script>
</actions>
</cue>
Code: Select all
<start_attack object="player.occupiedship" target="player.target " />
<run_script name="'order.fight.attack.object'">
<param name="primarytarget" value="player.target " />
<param name="allowothertargets" value="false" />
<param name="squad_attack" value="true" />
</run_script>
<stop_attack object="player.occupiedship" target="player.target " />
Code: Select all
<?xml version="1.0" encoding="utf-8" ?>
<mdscript name="SN_Hotkey_Collection"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--
Create some extra key-press activated commands.
Acts as an example of using the hotkey api, as well as hopefully
being useful.
Ideas:
disable_collisions_between : turn on/off collision with player and target
zoom: zoom in using fov adjustment (needs care to avoid fov getting stuck)
-->
<cues>
<!-- Register the main lua file. -->
<cue name="Load_Lua_Files" instantiate="true">
<conditions>
<event_ui_triggered screen="'Lua_Loader'" control="'Ready'" />
</conditions>
<actions>
<raise_lua_event name="'Lua_Loader.Load'"
param="'extensions.sn_hotkey_collection.lua.Hotkeys'"/>
</actions>
</cue>
<!--
Text storage cue, for easier lookup in general.
Members are descriptive names of the text strings, prefixed with $.
-->
<cue name="Text"/>
<library name="Load_Text">
<actions>
<set_value exact="{68537, 4000}" name="Text.$kc_target_follow_name" />
<set_value exact="{68537, 4001}" name="Text.$kc_target_follow_mouseover" />
<set_value exact="{68537, 4002}" name="Text.$kc_eject_illegals_name" />
<set_value exact="{68537, 4003}" name="Text.$kc_eject_illegals_mouseover" />
<set_value exact="{68537, 4004}" name="Text.$kc_toggle_seta_name" />
<set_value exact="{68537, 4005}" name="Text.$kc_toggle_seta_mouseover" />
<set_value exact="{68537, 4006}" name="Text.$kc_zoom_in_name" />
<set_value exact="{68537, 4007}" name="Text.$kc_zoom_in_mouseover" />
<set_value exact="{68537, 4008}" name="Text.$kc_attack_target_name" />
<set_value exact="{68537, 4009}" name="Text.$kc_attack_target_mouseover" />
<set_value exact="{68537, 4100}" name="Text.$kc_tracker_mine_name" />
<set_value exact="{68537, 4101}" name="Text.$kc_mine_name" />
<set_value exact="{68537, 4102}" name="Text.$kc_launch_satellite_name" />
<set_value exact="{68537, 4103}" name="Text.$kc_launch_adv_satellite_name" />
<set_value exact="{68537, 4104}" name="Text.$kc_laser_tower_mk1_name" />
<set_value exact="{68537, 4105}" name="Text.$kc_laser_tower_mk2_name" />
<set_value exact="{68537, 4106}" name="Text.$kc_resource_probe_name" />
<set_value exact="{68537, 4107}" name="Text.$kc_nav_beacon_name" />
<set_value exact="{68537, 4108}" name="Text.$kc_friend_foe_mine_name" />
<set_value exact="{68537, 4109}" name="Text.$kc_cluster_mine_name" />
<set_value exact="{68537, 4120}" name="Text.$kc_launch_consumable_mouseover" />
<set_value exact="{68537, 4121}" name="Text.$notification_launch_success" />
<set_value exact="{68537, 4122}" name="Text.$notification_launch_failure" />
</actions>
</library>
<!-- Register keys with the hotkey api. -->
<cue name="Register_Keys" instantiate="true">
<conditions>
<event_cue_signalled cue="md.Hotkey_API.Reloaded" />
</conditions>
<actions>
<!--Load any text.-->
<include_actions ref="Load_Text"/>
<!-- Register actions. -->
<signal_cue_instantly cue="md.Hotkey_API.Register_Action" param="table[
$id = 'kc_target_follow',
$onPress = Target_Follow,
$name = Text.$kc_target_follow_name,
$description = Text.$kc_target_follow_mouseover,
$contexts = ['flying'],
]"/>
<signal_cue_instantly cue="md.Hotkey_API.Register_Action" param="table[
$id = 'kc_attack_target',
$onPress = Attack_Target,
$name = Text.$kc_attack_target_name,
$description = Text.$kc_attack_target_mouseover,
$contexts = ['flying'],
]"/>
<signal_cue_instantly cue="md.Hotkey_API.Register_Action" param="table[
$id = 'kc_eject_illegals',
$onPress = Eject_Illegals,
$name = Text.$kc_eject_illegals_name,
$description = Text.$kc_eject_illegals_mouseover,
$contexts = ['flying'],
]"/>
<!-- Doesnt work when not in pilot seat.-->
<signal_cue_instantly cue="md.Hotkey_API.Register_Action" param="table[
$id = 'kc_toggle_seta',
$onPress = Toggle_Seta,
$name = Text.$kc_toggle_seta_name,
$description = Text.$kc_toggle_seta_mouseover,
$contexts = ['flying','menus'],
]"/>
<!--
Object launching hotkeys; all reuse Launch_Consumable.
Echo holds the macro, and an int for the object type.
TODO: maybe allow onRepeat with a manual timer to limit frequency.
(Could even put this repeat rate in the options.)
-->
<signal_cue_instantly cue="md.Hotkey_API.Register_Action" param="table[
$id = 'kc_launch_satellite',
$onPress = Launch_Consumable,
$name = Text.$kc_launch_satellite_name,
$description = Text.$kc_launch_consumable_mouseover,
$contexts = ['flying'],
$echo = [macro.eq_arg_satellite_01_macro, 0],
]"/>
<signal_cue_instantly cue="md.Hotkey_API.Register_Action" param="table[
$id = 'kc_launch_adv_satellite',
$onPress = Launch_Consumable,
$name = Text.$kc_launch_adv_satellite_name,
$description = Text.$kc_launch_consumable_mouseover,
$contexts = ['flying'],
$echo = [macro.eq_arg_satellite_02_macro, 0],
]"/>
<signal_cue_instantly cue="md.Hotkey_API.Register_Action" param="table[
$id = 'kc_launch_nav_beacon',
$onPress = Launch_Consumable,
$name = Text.$kc_nav_beacon_name,
$description = Text.$kc_launch_consumable_mouseover,
$contexts = ['flying'],
$echo = [macro.env_deco_nav_beacon_t1_macro, 4],
]"/>
<signal_cue_instantly cue="md.Hotkey_API.Register_Action" param="table[
$id = 'kc_launch_resource_probe',
$onPress = Launch_Consumable,
$name = Text.$kc_resource_probe_name,
$description = Text.$kc_launch_consumable_mouseover,
$contexts = ['flying'],
$echo = [macro.eq_arg_resourceprobe_01_macro, 3],
]"/>
<signal_cue_instantly cue="md.Hotkey_API.Register_Action" param="table[
$id = 'kc_launch_laser_tower_mk1',
$onPress = Launch_Consumable,
$name = Text.$kc_laser_tower_mk1_name,
$description = Text.$kc_launch_consumable_mouseover,
$contexts = ['flying'],
$echo = [macro.ship_gen_xs_lasertower_01_a_macro, 2],
]"/>
<signal_cue_instantly cue="md.Hotkey_API.Register_Action" param="table[
$id = 'kc_launch_laser_tower_mk2',
$onPress = Launch_Consumable,
$name = Text.$kc_laser_tower_mk2_name,
$description = Text.$kc_launch_consumable_mouseover,
$contexts = ['flying'],
$echo = [macro.ship_gen_s_lasertower_01_a_macro, 2],
]"/>
<signal_cue_instantly cue="md.Hotkey_API.Register_Action" param="table[
$id = 'kc_launch_mine',
$onPress = Launch_Consumable,
$name = Text.$kc_mine_name,
$description = Text.$kc_launch_consumable_mouseover,
$contexts = ['flying'],
$echo = [macro.weapon_gen_mine_01_macro, 1],
]"/>
<signal_cue_instantly cue="md.Hotkey_API.Register_Action" param="table[
$id = 'kc_launch_tracker_mine',
$onPress = Launch_Consumable,
$name = Text.$kc_tracker_mine_name,
$description = Text.$kc_launch_consumable_mouseover,
$contexts = ['flying'],
$echo = [macro.weapon_gen_mine_02_a_macro, 1],
]"/>
<signal_cue_instantly cue="md.Hotkey_API.Register_Action" param="table[
$id = 'kc_launch_friend_foe_mine',
$onPress = Launch_Consumable,
$name = Text.$kc_friend_foe_mine_name,
$description = Text.$kc_launch_consumable_mouseover,
$contexts = ['flying'],
$echo = [macro.weapon_gen_mine_03_macro, 1],
]"/>
<signal_cue_instantly cue="md.Hotkey_API.Register_Action" param="table[
$id = 'kc_zoom_in',
$onPress = Zoom_In,
$onRepeat = Zoom_In,
$onRelease = Zoom_In,
$name = Text.$kc_zoom_in_name,
$description = Text.$kc_zoom_in_mouseover,
$contexts = ['flying'],
]"/>
<!--Debug keys. TODO: move elsewhere.
<signal_cue_instantly cue="md.Hotkey_API.Register_Action" param="table[
$id = 'kc_print_combined_skill',
$onPress = Print_Combined_Skill,
$name = 'Print Combined Skill',
$category = 'Debug',
$description = 'Prints the combined skill of the current target',
$contexts = ['flying','walking'],
]"/>-->
</actions>
</cue>
<!-- Auto-follow target ship. -->
<cue name="Target_Follow" instantiate="true" namespace="this">
<conditions>
<event_cue_signalled/>
<!-- Verify the player has a target selected. -->
<check_value value="player.target"/>
<!-- Verify the player is piloting a ship.-->
<!-- TODO: check this in hotkey api instead (space/flying context).-->
<check_value value="player.occupiedship"/>
</conditions>
<actions>
<!-- Debug message. -->
<!--<raise_lua_event name="'directChatMessageReceived'" param="'KeyCapture;Starting Target_Follow'"/>-->
<!--<debug_text text="'KeyCapture Triggered Target_Follow'" filter="general"/>-->
<!-- Cancel autopilot if the target is already the current dest.-->
<do_if value="player.target == player.autopilottarget">
<stop_player_autopilot />
<show_notification text="{10002, 921}" comment="Autopilot Disengaged"/>
</do_if>
<!-- Start autopiloting to target. Should continuously follow. -->
<do_else>
<start_player_autopilot destination="player.target"/>
<!-- This already puts up a notification on its own. -->
</do_else>
</actions>
</cue>
<!-- Auto-follow target ship. -->
<cue name="Attack_Target" instantiate="true" namespace="this">
<conditions>
<event_cue_signalled/>
<!-- Verify the player has a target selected. -->
<check_value value="player.target"/>
<!-- Verify the player is piloting a ship.-->
<!-- TODO: check this in hotkey api instead (space/flying context).-->
<check_value value="player.occupiedship"/>
</conditions>
<actions>
<!-- Debug message. -->
<raise_lua_event name="'directChatMessageReceived'" param="'KeyCapture;Starting event_attack_started'"/>
<debug_text text="'KeyCapture Triggered order.player.attack'" filter="general"/>
<run_script name="'order.player.attack'">
<param name="primarytarget" value="player.target " />
<param name="allowothertargets" value="false" />
<param name="squad_attack" value="true" />
</run_script>
</actions>
</cue>
<!-- Drop illegal wares. -->
<cue name="Eject_Illegals" instantiate="true" namespace="this">
<conditions>
<event_cue_signalled/>
<!-- Verify the player is piloting a ship.-->
<check_value value="player.occupiedship"/>
</conditions>
<actions>
<!-- Debug message. -->
<!--<raise_lua_event name="'directChatMessageReceived'" param="'KeyCapture;Ejecting_Illegals'"/>-->
<!--<debug_text text="'KeyCapture Triggered Ejecting_Illegals'" filter="general"/>-->
<set_value name="$faction" exact="player.zone.policefaction"/>
<drop_illegal_cargo groupname="$boxes" object="player.occupiedship" faction="$faction"/>
<drop_illegal_inventory groupname="$boxes" object="player.entity" faction="$faction"/>
<do_if value="$boxes.count != 0">
<show_notification text="'Ejected Illegal Wares'"/>
</do_if>
<do_else>
<show_notification text="'No Illegal Wares'"/>
</do_else>
</actions>
</cue>
<cue name="Launch_Consumable" instantiate="true" namespace="this">
<conditions>
<event_cue_signalled/>
<!-- Verify the player is piloting a ship.-->
<check_value value="player.occupiedship"/>
</conditions>
<actions>
<!--Consumable macro is in echo.-->
<set_value name="$macro" exact="event.param.$echo.{1}"/>
<set_value name="$type" exact="event.param.$echo.{2}"/>
<do_if value="player.occupiedship.ammostorage.{$macro}.count gt 0">
<!--Need to select a command based on macro type.-->
<do_if value="$type == 0">
<launch_satellite object="player.occupiedship" macro="$macro"/>
</do_if>
<do_elseif value="$type == 1">
<launch_mine object="player.occupiedship" macro="$macro"/>
</do_elseif>
<do_elseif value="$type == 2">
<launch_lasertower object="player.occupiedship" macro="$macro"/>
</do_elseif>
<do_elseif value="$type == 3">
<launch_resourceprobe object="player.occupiedship" macro="$macro"/>
</do_elseif>
<do_elseif value="$type == 4">
<launch_navbeacon object="player.occupiedship" macro="$macro"/>
</do_elseif>
<show_notification text="Text.$notification_launch_success.[$macro.name]"/>
</do_if>
<do_else>
<show_notification text="Text.$notification_launch_failure.[$macro.name]"/>
</do_else>
</actions>
</cue>
<!--For the current target, return the combined skill value.-->
<cue name="Print_Combined_Skill" instantiate="true" namespace="this">
<conditions>
<event_cue_signalled/>
<!-- Verify the player has a target selected. -->
<check_value value="player.target"/>
</conditions>
<actions>
<show_notification text="'Skill: '+player.target.combinedskill"/>
</actions>
</cue>
<cue name="Toggle_Seta" instantiate="true" namespace="this">
<conditions>
<event_cue_signalled/>
</conditions>
<actions>
<toggle_timewarp/>
</actions>
</cue>
<!--
Zoom logic will be handled mostly by lua.
This will pass over the event data.
-->
<cue name="Zoom_In" instantiate="true" namespace="this">
<conditions>
<event_cue_signalled/>
</conditions>
<actions>
<raise_lua_event name="'SN_Hotkeys.zoom_in'" param="event.param.$event"/>
</actions>
</cue>
</cues>
</mdscript>
- Am I using going about this correctly, and it's just not working?
- Tips on debugging
- Any knowledge on how to trigger an attack properly
- Is there anyway to see the members/variables of player from the code?