R3vo/Sandbox – User

From Bohemia Interactive Community
< User:R3vo
Revision as of 16:56, 27 December 2023 by R3vo (talk | contribs)
Jump to navigation Jump to search

The Spearhead 1944 CDLC introduces a unique way to allow for scenario customization, the voting UI.
spe mapVote ui.jpg
Features:

  • Autogenerated UI for up to six voting options
  • Supports images, title and description
  • Customizable voting timer
  • Singleplayer and multiplayer compatible
  • Easy to set up

Configuration

Placing Map Markers

In order for the vote UI to know the locations of your voting positions, we will use markers. In our example we call them start_n where n is going to be a number from 1 to 2 to create two voting options. The number of markers defines how many voting options will be available. Up to six voting options are supported e.g. start_1, start_2, ..., start_6 Place the markers where the voting options should appear on the map.

Adding the UI Code

The code for the voting logic runs on all machines, client, hosted server and dedicated server. Thus, best place to execute it is from within the init.sqf.

init.sqf

[ "start_", {true}, // Voter Eligible [{(time > 1) || (!isNil "SPE_missionUtilityFunctions_skipVote")}, {((getClientStateNumber >= 10) || (!isNil "SPE_missionUtilityFunctions_skipVote")) && {time > 3}}] select (isMultiplayer), // Vote end condition { // completion code (hasInterface inc. JiP) }, { //completion code (server) }, {}, {//OnHover, map markers systemChat str _this; }, ["SPE_b_Icon_Axis_Armored", "SPE_b_Icon_Axis_Armored", "SPE_b_Icon_Axis_Armored", "SPE_b_Icon_Axis_Armored"], [[0.34, 0.42, 0.44, 1], [0.34, 0.42, 0.44, 1], [0.34, 0.42, 0.44, 1], [0.34, 0.42, 0.44, 1]], [ ["start_1", ["Title 1", "\WW2\SPE_Missions_p\Scenarios_p\data\Voting_DerZahnarzt_Sabotage.paa", "Description 1", "\WW2\SPE_Missions_p\Scenarios_p\data\Voting_DerZahnarzt_Sabotage.paa"]], ["start_2", ["Title 2", "\WW2\SPE_Missions_p\Scenarios_p\data\Voting_DerZahnarzt_Sabotage.paa", "Description 2", "\WW2\SPE_Missions_p\Scenarios_p\data\Voting_DerZahnarzt_Sabotage.paa"]] ], "start_1", [ [ "Option 1", "Description 1", localize "STR_SPE_Scenario_Der_Zahnarzt_Vote_Detail_Start_Option_1_Advantages", "\WW2\SPE_Missions_p\Scenarios_p\data\Voting_DerZahnarzt_Sabotage_bw.paa", "\WW2\SPE_Missions_p\Scenarios_p\data\Voting_DerZahnarzt_Sabotage.paa" ], [ "Option 2", "Description 2", localize "STR_SPE_Scenario_Der_Zahnarzt_Vote_Detail_Start_Option_1_Advantages", "\WW2\SPE_Missions_p\Scenarios_p\data\Voting_DerZahnarzt_Sabotage_bw.paa", "\WW2\SPE_Missions_p\Scenarios_p\data\Voting_DerZahnarzt_Sabotage.paa" ] ], [false], {!(isNull findDisplay 46)}, true ] spawn SPE_missionUtilityFunctions_fnc_mapVote_init;

Function Parameters

Syntax

[ _prefix, _condition, _completionCondition, _clientCode, _completionCode, _updateSelectionCode, _hoverCandidateCode, _groupIcons, _groupIconParams, _cfgOrbat, _defaultSelection, _uiData, _timer, _uiFadeOutCondition, _waitForPlayers ] call SPE_missionUtilityFunctions_fnc_mapVote_init;

Parameters

  1. _prefix: String - Prefix of all voting markers e.g. start_1, start_2, ..., start_6, optional, default "player_spawn_"
  2. _condition: Code - Condition that must be true for given player in order to see the vote, optional, default {[[true]]}
  3. _completionCondition: Code - Condition that must be true for the voting to be considered done, optional, default {[[time]] > 1}
  4. _clientCode: Code - Code that is executed on the client when the voting has finished and for JIP player, optional, default {params ["_prefix", "_marker", "_conditionResult"];}
  5. _completionCode: Code - Code that is executed on the server when the voting has finished, optional, default {params ["_prefix", "_marker"];}
  6. _updateSelectionCode: Code - Code that is executed on the client when the voting selection changes, optional, default {params ["_prefix", "_winningMarkers", "_allMarkers"];}
  7. _hoverCandidateCode: Code - Code that is executed on the client when hovering over the voting option, optional, default {params ["_marker", "_hover", "_conditionResult", ["_cleanup", false]];}
  8. _groupIcons: Array - Vote textures used for the map voting markers, optional, default ["selector_selectedFriendly", "selector_selectedEnemy", "selector_selectedFriendly", "selector_selectedEnemy"] //TODO: What is this exactly?
  9. _groupIconParams: Array - Vote colors used for the map voting markers, optional, default [[VOTE_UI_COLOUR_DEFAULT_RGBA], [VOTE_UI_COLOUR_VOTED_RGBA], [0.7, 0.7, 0.7, 0], [0.5, 1, 0.5, 0]] //TODO: What is this exactly?
  10. _cfgOrbat: Array of arrays - CfgORBAT parameters used to fill map voting markers, optional, default []

[ "start_1", //Marker indicating the voting location [ "Title 1", //Title displayed when hovering over the marker "\WW2\SPE_Missions_p\Scenarios_p\data\Voting_DerZahnarzt_Sabotage.paa", //Image shown when hovering over the marker "Description 1", //Description displayed when hovering over the marker "\WW2\SPE_Missions_p\Scenarios_p\data\Voting_DerZahnarzt_Sabotage.paa" //Image shown when hovering over the marker ] ]

  1. _defaultSelection: String - Marker name that is selected by default, optional, default ""
  2. _uiData: Array of arrays - Data to fill the UI, optional, default []

[ [ "Option 1", //Title of the voting option "Description 1", //Description of the voting option localize "STR_SPE_Scenario_Der_Zahnarzt_Vote_Detail_Start_Option_1_Advantages", //Additional text displayed of the voting option "\WW2\SPE_Missions_p\Scenarios_p\data\Voting_DerZahnarzt_Sabotage_bw.paa", //Image that is being used if this option is not selected or hovered over "\WW2\SPE_Missions_p\Scenarios_p\data\Voting_DerZahnarzt_Sabotage.paa" //Image that is being used if this option is selected or hovered over ] ]

  1. _timer: Boolean, Code, Number, String - Voting timer setting, optional, default []
    1. When Boolean - ???
    2. When Code - First number in array will be used
    3. When Number - Value is used as timer
    4. When String - A missionNamespace variable with given name is begin looked up for a valid value
  2. _uiFadeOutCondition: Code - Condition to fade out the voting UI, optional, default {missionNamespace getVariable [QGVAR(array), []] isEqualTo []}
  3. _waitForPlayers: Boolean - Should UI wait for players, default false

= Debugging

Extended logging is available if SPE_mapVote_debug is set to true. Variable should be set to true for both server and clients.

After Voting

After the voting has finished and the winner was evaluated, the result of the vote is saved into SPE_missionutilityfunctions_mapvote_start_marker. This variable holds the marker name of the voting option that has won. We can now use that result to adjust our scenario accordingly. For example we can move players around, hide certain compositions, change loadouts or enemy presence.

switch SPE_missionutilityfunctions_mapvote_start_marker do { case "start_1": {/* Do things... */}; case "start_2": {/* Do things... */}; case "start_3": {/* Do things... */}; case "start_4": {/* Do things... */}; case "start_5": {/* Do things... */}; case "start_6": {/* Do things... */}; default {/* Should never be executed... */}; };

Example Scenario

Spearhead 1944 - Map Vote UI Tutorial Scenario.zip (OneDrive)