Mod Support APIs. I can't figure out what I'm doing wrong.

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

cupoma
Posts: 12
Joined: Fri, 15. Nov 24, 09:13

Mod Support APIs. I can't figure out what I'm doing wrong.

Post by cupoma »

I'm trying to create a script to add drones to the station. Through MD Interact Menu API and Simple Menu API, but it doesn't work. I cannot assign the value of the selected station to the variable and the values of the entered data are not remembered via md.Simple_Menu_API.Make_Slider
Spoiler
Show

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>

<!--<mdscript name="add drone to station" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd">-->
<mdscript name="add drone to station"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd">
    <cues>
	
		<cue name="Config">
			<actions>
				<include_actions ref="reset_drones"/>
			</actions>
		</cue>
        
		<library name="reset_drones">
			<actions>
				<set_value name="Drone.$Sort" exact="table[
					$cargo = null,
					$defense = null,
					$repair = null,
					$build = null,
					]"
				/>
			</actions>
		</library>
		
		
		<cue name="add_drones_Action" instantiate="true">
            <conditions>
                <event_cue_signalled cue="md.Interact_Menu_API.Get_Actions" />
            </conditions>
			
            <actions>
				<set_value name="$target" type="station" exact="class.station"/>
							
				<do_if value="$target.isclass.[class.station]">

                    <signal_cue_instantly 
                        cue   = "md.Interact_Menu_API.Add_Action"
                        param = "table[
                            $id         = 'Add_drones',
                            $text       = 'Добавить дроны на станцию',
                            $icon       = 'widget_arrow_right_01',
                            $section    = 'interaction',
                            $callback   = add_drones_menu,
                    ]"/>
				
				</do_if>
				
				<set_value name="$targetStation" type="station" exact="event.param.$object"/>
	
            </actions>
			
        </cue>
		
		<cue name="add_drones_menu" instantiate="true">
            <conditions>
                <event_cue_signalled/>
            </conditions>
            
			<actions>

                <signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Create_Menu"
                    param = "table[
                        $title   = 'Добавить дроны на станцию',
                        $columns = 4,
                        $width   = 300
                    ]" />

                <signal_cue_instantly cue="md.Simple_Menu_API.Add_Row" />
				
				<signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Make_Text"
                    param = "table[
                        $text		= 'Грузовые дроны',
                        $col		= 1,
                        $colSpan	= 2,
						$height		= 25,
						$y			= 5,
                        $halign		= 'right',
                        $scaling	= true
                ]" />

                <signal_cue_instantly 
                    cue   = "md.Simple_Menu_API.Make_Slider" 
                    param = "table[
						$id         = '$cargo',
						$col		= 3,
                        $colSpan	= 2,
                        $height		= 25,
						$min        = 0, 
						$minSelect  = 0, 
						$max        = 100, 
						$maxSelect  = 100, 
						$start      = 0, 
						$step       = 1,
						$callback = OnChange
                ]" />

                <signal_cue_instantly cue="md.Simple_Menu_API.Add_Row"/>
				
				<signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Make_Text"
                    param = "table[
                        $text		= 'Защитные дроны',
                        $col		= 1,
                        $colSpan	= 2,
						$height		= 25,
						$y			= 5,
                        $halign		= 'right',
                        $scaling	= true
                ]" />
				
				<signal_cue_instantly 
                    cue   = "md.Simple_Menu_API.Make_Slider" 
                    param = "table[
						$id         = '$defense',
						$col		= 3,
                        $colSpan	= 2,
                        $height		= 25,
						$min        = 0, 
						$minSelect  = 0, 
						$max        = 100, 
						$maxSelect  = 100, 
						$start      = 0, 
						$step       = 1,
						$callback = OnChange
                ]" />
				
				<signal_cue_instantly cue="md.Simple_Menu_API.Add_Row"/>
				
				<signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Make_Text"
                    param = "table[
                        $text		= 'Ремонтные дроны',
                        $col		= 1,
                        $colSpan	= 2,
						$height		= 25,
						$y			= 5,
                        $halign		= 'right',
                        $scaling	= true
                ]" />
				
				<signal_cue_instantly 
                    cue   = "md.Simple_Menu_API.Make_Slider" 
                    param = "table[
						$id         = '$repair',
						$col		= 3,
                        $colSpan	= 2,
                        $height		= 25,
						$min        = 0, 
						$minSelect  = 0, 
						$max        = 100, 
						$maxSelect  = 100, 
						$start      = 0, 
						$step       = 1,
						$callback = OnChange
                ]" />
				
				<signal_cue_instantly cue="md.Simple_Menu_API.Add_Row"/>

				<signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Make_Text"
                    param = "table[
                        $text		= 'Строительные дроны',
                        $col		= 1,
                        $colSpan	= 2,
						$height		= 25,
						$y			= 5,
                        $halign		= 'right',
                        $scaling	= true
                ]" />

				<signal_cue_instantly 
                    cue   = "md.Simple_Menu_API.Make_Slider" 
                    param = "table[
						$id         = '$build',
						$col		= 3,
                        $colSpan	= 2,
                        $height		= 25,
						$min        = 0, 
						$minSelect  = 0, 
						$max        = 100, 
						$maxSelect  = 100, 
						$start      = 0, 
						$step       = 1,
						$callback = OnChange
                ]" />				

                <signal_cue_instantly cue="md.Simple_Menu_API.Add_Row" />

                <signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Make_Button"
                    param = "table[
                        $id      = 'add_drones_button',
                        $col     = 1,
                        $colSpan = 2,
                        $scaling = true,
                        $height  = 25,
                        $onClick = add_drones,
                        $text    = table[
                            $text   = 'Добавить', 
                            $color  = 'Helper.color.white',
                            $halign = 'center'
                            ]
                        ]" />
                <signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Make_Button"
                    param = "table[
                        $col     = 3,
                        $colSpan = 2,
                        $scaling = true,
                        $height  = 25,
                        $onClick = close_add_drones_menu,
                        $text    = table[
                            $text   = 'Отмена', 
                            $color  = 'Helper.color.white',
                            $halign = 'center'
                            ]
                        ]" />
            </actions>
        </cue>
		


		<cue name="OnChange" instantiate="true">
			<conditions>
				<event_cue_signalled />
			</conditions>
			
			<actions>
				<set_value name="Drone.$Sort.{event.param.$id}" exact="event.param.$value" />
			</actions>
		</cue>
		
		<cue name="add_drones" instantiate="true" namespace="this">
			<conditions>
				<event_cue_signalled/>
			</conditions>
			<actions>
				
				<add_units object="event.param.$object" category="unitcategory.transport" mk="1" exact="$cargo" /> 
				<add_units object="$targetStation" category="unitcategory.defence" mk="1" exact="$defense" /> 
				<add_units object="$targetStation" category="unitcategory.repair" mk="1" exact="$repair" />
				<add_units object="$targetStation" category="unitcategory.build" mk="1" exact="$build" />
				
				<signal_cue_instantly cue = "close_add_drones_menu" />
				
			</actions>
		</cue>
		
		<cue name="close_add_drones_menu" instantiate="true">
            <conditions>
                <event_cue_signalled/>
            </conditions>
            <actions>
                <signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Send_Command"
                    param = "table[
                        $command = 'Close_Menu'
                    ]" />
            </actions>
        </cue>
        
    </cues>
</mdscript>
cupoma
Posts: 12
Joined: Fri, 15. Nov 24, 09:13

Re: Mod Support APIs. I can't figure out what I'm doing wrong.

Post by cupoma »

Spoiler
Show

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>

<!--<mdscript name="add drone to station" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd">-->
<mdscript name="add drone to station"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd">
    <cues>
	
		<cue name="Config">
			<actions>
				<include_actions ref="reset_drones"/>
			</actions>
		</cue>
        
		<library name="reset_drones">
			<actions>
				<set_value name="global.Drone.$Sort" exact="table[
					$cargo = null,
					$defense = null,
					$repair = null,
					$build = null
					]"
				/>
			</actions>
		</library>
		
		
		<cue name="add_drones_Action" instantiate="true" namespace="this">
            <conditions>
                <event_cue_signalled cue="md.Interact_Menu_API.Get_Actions" />
            </conditions>
			
            <actions>
				<set_value name="$target" exact="@event.param.$object.isclass.station and @event.param.$object.isplayerowned"/>
							
				<do_if value="$target">

					<set_value name="global.$targetStation" exact="@event.param.$object"/>

                    <signal_cue_instantly 
                        cue   = "md.Interact_Menu_API.Add_Action"
                        param = "table[
                            $id         = 'Add_drones',
                            $text       = 'Добавить дроны на станцию',
                            $icon       = 'widget_arrow_right_01',
                            $section    = 'interaction',
                            $callback   = add_drones_menu,
                    ]"/>
					
				
				</do_if>
				
				

            </actions>
			
        </cue>
		
		<cue name="add_drones_menu" instantiate="true">
            <conditions>
                <event_cue_signalled/>
            </conditions>
            
			<actions>
			

                <signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Create_Menu"
                    param = "table[
                        $title   = 'Добавить дроны на станцию',
                        $columns = 4,
                        $width   = 300
                    ]" />
					
					

                <signal_cue_instantly cue="md.Simple_Menu_API.Add_Row" />
				
				<signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Make_Text"
                    param = "table[
                        $text		= 'Грузовые дроны',
                        $col		= 1,
                        $colSpan	= 2,
						$height		= 25,
						$y			= 5,
                        $halign		= 'right',
                        $scaling	= true
                ]" />

                <signal_cue_instantly 
                    cue   = "md.Simple_Menu_API.Make_Slider" 
                    param = "table[
						$id         = '$cargo',
						$col		= 3,
                        $colSpan	= 2,
                        $height		= 25,
						$min        = 0, 
						$minSelect  = 0, 
						$max        = 100, 
						$maxSelect  = 100, 
						$start      = 0, 
						$step       = 1,
						$onSliderCellChanged = OnChange
                ]" />

                <signal_cue_instantly cue="md.Simple_Menu_API.Add_Row"/>
				
				<signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Make_Text"
                    param = "table[
                        $text		= 'Защитные дроны',
                        $col		= 1,
                        $colSpan	= 2,
						$height		= 25,
						$y			= 5,
                        $halign		= 'right',
                        $scaling	= true
                ]" />
				
				<signal_cue_instantly 
                    cue   = "md.Simple_Menu_API.Make_Slider" 
                    param = "table[
						$id         = '$defense',
						$col		= 3,
                        $colSpan	= 2,
                        $height		= 25,
						$min        = 0, 
						$minSelect  = 0, 
						$max        = 100, 
						$maxSelect  = 100, 
						$start      = 0, 
						$step       = 1,
						$onSliderCellChanged = OnChange
                ]" />
				
				<signal_cue_instantly cue="md.Simple_Menu_API.Add_Row"/>
				
				<signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Make_Text"
                    param = "table[
                        $text		= 'Ремонтные дроны',
                        $col		= 1,
                        $colSpan	= 2,
						$height		= 25,
						$y			= 5,
                        $halign		= 'right',
                        $scaling	= true
                ]" />
				
				<signal_cue_instantly 
                    cue   = "md.Simple_Menu_API.Make_Slider" 
                    param = "table[
						$id         = '$repair',
						$col		= 3,
                        $colSpan	= 2,
                        $height		= 25,
						$min        = 0, 
						$minSelect  = 0, 
						$max        = 100, 
						$maxSelect  = 100, 
						$start      = 0, 
						$step       = 1,
						$onSliderCellChanged = OnChange
                ]" />
				
				<signal_cue_instantly cue="md.Simple_Menu_API.Add_Row"/>

				<signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Make_Text"
                    param = "table[
                        $text		= 'Строительные дроны',
                        $col		= 1,
                        $colSpan	= 2,
						$height		= 25,
						$y			= 5,
                        $halign		= 'right',
                        $scaling	= true
                ]" />

				<signal_cue_instantly 
                    cue   = "md.Simple_Menu_API.Make_Slider" 
                    param = "table[
						$id         = '$build',
						$col		= 3,
                        $colSpan	= 2,
                        $height		= 25,
						$min        = 0, 
						$minSelect  = 0, 
						$max        = 100, 
						$maxSelect  = 100, 
						$start      = 0, 
						$step       = 1,
						$onSliderCellChanged = OnChange
                ]" />				

                <signal_cue_instantly cue="md.Simple_Menu_API.Add_Row" />

                <signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Make_Button"
                    param = "table[
                        $id      = 'add_drones_button',
                        $col     = 1,
                        $colSpan = 2,
                        $scaling = true,
                        $height  = 25,
                        $onClick = add_drones,
                        $text    = table[
                            $text   = 'Добавить', 
                            $color  = 'Helper.color.white',
                            $halign = 'center'
                            ]
                        ]" />
                <signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Make_Button"
                    param = "table[
                        $col     = 3,
                        $colSpan = 2,
                        $scaling = true,
                        $height  = 25,
                        $onClick = close_add_drones_menu,
                        $text    = table[
                            $text   = 'Отмена', 
                            $color  = 'Helper.color.white',
                            $halign = 'center'
                            ]
                        ]" />
            </actions>
        </cue>
		


		<cue name="OnChange" instantiate="true">
			<conditions>
				<event_cue_signalled />
			</conditions>
			
			<actions>

<!--			
				<set_value name="global.Drone.[event.param.$id]" exact="@event.param.$value" />
				
				<debug_text text="event.param.$id" />
				<debug_text text="event.param.$value" />
-->					<debug_text text="global.Drone.$Sort.{event.param.$id}" />
		
			</actions>
		</cue>
		
		<cue name="add_drones" instantiate="true" namespace="this">
			<conditions>
				<event_cue_signalled/>
			</conditions>
			<actions>
<!--				<debug_text text="global.Drone.$cargo" />
				<debug_text text="global.Drone.$defense" />
				<debug_text text="global.Drone.$repair" />
				<debug_text text="global.Drone.$build" />
				
				
				<add_units object="global.$targetStation" category="unitcategory.transport" mk="1" exact="global.Drone.$cargo" /> 
				<add_units object="global.$targetStation" category="unitcategory.defence" mk="1" exact="global.Drone.$defense" /> 
				<add_units object="global.$targetStation" category="unitcategory.repair" mk="1" exact="global.Drone.$repair" />
				<add_units object="global.$targetStation" category="unitcategory.build" mk="1" exact="global.Drone.$build" />
-->				
				<signal_cue_instantly cue = "close_add_drones_menu" />
				
			</actions>
		</cue>
		
		<cue name="close_add_drones_menu" instantiate="true">
            <conditions>
                <event_cue_signalled/>
            </conditions>
            <actions>
                <signal_cue_instantly
                    cue   = "md.Simple_Menu_API.Send_Command"
                    param = "table[
                        $command = 'Close_Menu'
                    ]" />
            </actions>
        </cue>
        
    </cues>
</mdscript>
I've redone the code, there's not much left, this line doesn't work

Code: Select all

<set_value name="global.Drone.[event.param.$id]" exact="@event.param.$value" />
cupoma
Posts: 12
Joined: Fri, 15. Nov 24, 09:13

Re: Mod Support APIs. I can't figure out what I'm doing wrong.

Post by cupoma »

I handled this code myself, the topic can be closed

Return to “X4: Foundations - Scripts and Modding”