Closed MildlyInterested closed 1 year ago
player addEventHandler ["Respawn", {
params ["_unit", "_corpse"];
_unit setUnitLoadout [[_corpse] call acre_api_fnc_filterUnitLoadout, false]; //copies old radios from corpse to new player?
{
private _radioType = _x;
private _radios = [_radioType, _corpse] call acre_api_fnc_getAllRadiosByType; //returns arry of unique Radio IDs from corpse
private _radioData = [];
{//interate through all radios by IDs
private _radioID = _x;
private _currentChannel = [_radioID] call acre_api_fnc_getRadioChannel; //get channel of Radio
systemChat format ["%1 was on %2", _radioID, _currentChannel]; //tell channel of radio as hint
_radioData pushBack _currentChannel; //add channel to radioData
} forEach _radios;
//now we have a array that has each radiochannel for every radio the player had in it
[{ // delay 5 sec, so unit can get unique radio
params ["_newUnit", "_radioType", "_radioData"];
private _radios = [_radioType, _newUnit] call acre_api_fnc_getAllRadiosByType;
{
private _radioID = _x;
private _channel = _radioData select _forEachIndex;
systemChat format ["Setting %1 to %2", _radioID, _channel];
[_radioID, _channel] call acre_api_fnc_setRadioChannel;
} forEach _radios;
}, [_newUnit, _radioType, _radioData], 5] call CBA_fnc_waitAndExecute;
} forEach ["ACRE_PRC152", "ACRE_PRC343"];
}];
tested like that, works in local multiplayer
TODO
player addEventHandler ["Respawn",
{
params ["_unit", "_corpse"];
_unit setUnitLoadout [[_corpse] call acre_api_fnc_filterUnitLoadout, false]; //copies old radio items and types from corpse to respawned player
{
private _radioType = _x;
private _radios = [_radioType, _corpse] call acre_api_fnc_getAllRadiosByType; //returns array of unique Radio IDs from corpse
private _radioChannel = [];
private _radioVolume = [];
private _radioSpatial = [];
{//interate through all radios by IDs
private _radioID = _x;
private _currentChannel = [_radioID] call acre_api_fnc_getRadioChannel; //get channel of Radio
private _currentVolume = [_radioID] call acre_api_fnc_getRadioVolume; //get volume of Radio
private _currentSpatial = [_radioID] call acre_api_fnc_getRadioSpatial; //get spatial of Radio
systemChat format ["Radio %1 was on channel %2 at volume %3 listening on %4", _radioID, _currentChannel, _currentVolume, _currentSpatial]; //Tell radio data as hint
_radioChannel pushBack _currentChannel; //add channel to radioData
_radioVolume pushBack _currentVolume; //add volume to radioVolume
_radioSpatial pushBack _currentSpatial; //add spatial to radioSpatial
} forEach _radios;
//now we have three arrays that has radiochannel, volume level and spatial for every radio the player had in it
[{ // delay 5 sec, so unit can get unique radio
params ["_newUnit", "_radioType", "_radioChannel", "_radioVolume", "_radioSpatial"];
private _radios = [_radioType, _newUnit] call acre_api_fnc_getAllRadiosByType;
{
private _radioID = _x;
private _channel = _radioChannel select _forEachIndex;
private _volume = _radioVolume select _forEachIndex;
private _spatial = _radioSpatial select _forEachIndex;
systemChat format ["Setting radio %1 to channel %2 at volume %3 on %4", _radioID, _channel, _volume, _spatial];
[_radioID, _channel] call acre_api_fnc_setRadioChannel;
[_radioID, _volume] call acre_api_fnc_setRadioVolume;
[_radioID, _spatial] call acre_api_fnc_setRadioSpatial;
} forEach _radios;
}, [_newUnit, _radioType, _radioChannel, _radioVolume, _radioSpatial], 5] call CBA_fnc_waitAndExecute;
} forEach ["ACRE_PRC343", "ACRE_PRC152", "ACRE_PRC117"];
0 spawn {
sleep 6;
systemChat format ["Remember to re-set PTT buttons manually!"];
};
}];
Re-sets Channel, Volume and Spatial (Left, Center, Right) on all radios after respawn, still lacking the PTT setting. Tested and works in local multiplayer.
player addEventHandler ["Respawn",
{
_newRadioList = [];
params ["_unit", "_corpse", "_newRadioList"];
_unit setUnitLoadout [[_corpse] call acre_api_fnc_filterUnitLoadout, false]; //copy old radio items from corpse to respawned player
{
private _radioType = _x;
private _radios = [_radioType, _corpse] call acre_api_fnc_getAllRadiosByType; //return array of unique Radio IDs from corpse
private _radioChannel = [];
private _radioVolume = [];
private _radioSpatial = [];
private _pttList = [];
_pttRadioList = [] call acre_api_fnc_getMultiPushToTalkAssignment; //return array of radioIDs assigned to each PTT key
{
//iterate through all radios by IDs, add their properties to arrays in a set order
private _radioID = _x;
private _currentChannel = [_radioID] call acre_api_fnc_getRadioChannel; //get channel of Radio
private _currentVolume = [_radioID] call acre_api_fnc_getRadioVolume; //get volume of Radio
private _currentSpatial = [_radioID] call acre_api_fnc_getRadioSpatial; //get spatial of Radio
switch (_radioID) do
{
//if ptt1 radio, add int 1
case (_pttRadioList select 0):
{
(_pttList pushBack 1);
};
//if ptt2 radio, add int 2
case (_pttRadioList select 1):
{
(_pttList pushBack 2);
};
//if ptt3 radio, add int 3
case (_pttRadioList select 2):
{
(_pttList pushBack 3);
};
//if radio without ptt set, add int 9
default
{
(_pttList pushBack 9);
};
};
_radioChannel pushBack _currentChannel; //add channel to radioChannel
_radioVolume pushBack _currentVolume; //add volume to radioVolume
_radioSpatial pushBack _currentSpatial; //add spatial to radioSpatial
} forEach _radios;
//now we have four arrays - radioChannel, radioVolume, radioSpatial and pttList setup for every radio the player had
[{
params ["_newUnit", "_radioType", "_radioChannel", "_radioVolume", "_radioSpatial", "_pttList", "_newRadioList"];
private _radios = [_radioType, _newUnit] call acre_api_fnc_getAllRadiosByType;
{
//iterate through all NEW radios by IDs, add properties in the order set above
private _radioID = _x;
private _channel = _radioChannel select _forEachIndex;
private _volume = _radioVolume select _forEachIndex;
private _spatial = _radioSpatial select _forEachIndex;
private _pttKey = _pttList select _forEachIndex;
if (_pttKey == 1) then {_newRadioList set [0, _radioID]}; //assign new radio to PTT slot 1
if (_pttKey == 2) then {_newRadioList set [1, _radioID]}; //assign new radio to PTT slot 2
if (_pttKey == 3) then {_newRadioList set [2, _radioID]}; //assign new radio to PTT slot 3
[_radioID, _channel] call acre_api_fnc_setRadioChannel;
[_radioID, _volume] call acre_api_fnc_setRadioVolume;
[_radioID, _spatial] call acre_api_fnc_setRadioSpatial;
} forEach _radios;
}, [_newUnit, _radioType, _radioChannel, _radioVolume, _radioSpatial, _pttList, _newRadioList], 3] call CBA_fnc_waitAndExecute; //delay 3 secs for new radio IDs
} forEach ["ACRE_PRC77", "ACRE_PRC117F", "ACRE_PRC148", "ACRE_PRC152", "ACRE_PRC343", "ACRE_SEM52SL", "ACRE_SEM70", "ACRE_BF888S"]; // for each available ACRE RADIO
[{
params ["_newRadioList"];
//assign the radio IDs of those with assigned PTTs
private _ptt1 = _newRadioList select 0;
private _ptt2 = _newRadioList select 1;
private _ptt3 = _newRadioList select 2;
_pttNewRadioList = [ [_ptt1, _ptt2, _ptt3] ] call acre_api_fnc_setMultiPushToTalkAssignment; //assign new radios to old PTT setup
systemChat format ["Your radio settings have been restored."];
}, [_newRadioList], 5] call CBA_fnc_waitAndExecute; //delay 5 secs to allow above block to complete
}];
Done. Add above script code to initPLayerLocal.sqf. All ACRE2 settings are retained after respawn.
// Re-set radio settings on respawn START
player addEventHandler ["Respawn",
{
_newRadioList set [0, 1];
_newRadioList set [1, 1];
_newRadioList set [2, 1];
params ["_unit", "_corpse", "_newRadioList"];
_unit setUnitLoadout [[_corpse] call acre_api_fnc_filterUnitLoadout, false]; //copy old radio items from corpse to respawned player
{
private _radioType = _x;
private _radios = [_radioType, _corpse] call acre_api_fnc_getAllRadiosByType; //return array of unique Radio IDs from corpse
private _radioChannel = [];
private _radioVolume = [];
private _radioSpatial = [];
private _pttList = [];
_pttRadioList = [] call acre_api_fnc_getMultiPushToTalkAssignment; //return array of radioIDs assigned to each PTT key
{
//iterate through all radios by IDs, add their properties to arrays in a set order
private _radioID = _x;
private _currentChannel = [_radioID] call acre_api_fnc_getRadioChannel; //get channel of Radio
private _currentVolume = [_radioID] call acre_api_fnc_getRadioVolume; //get volume of Radio
private _currentSpatial = [_radioID] call acre_api_fnc_getRadioSpatial; //get spatial of Radio
switch (_radioID) do
{
//if ptt1 radio, add int 1
case (_pttRadioList select 0):
{
(_pttList pushBack 1);
};
//if ptt2 radio, add int 2
case (_pttRadioList select 1):
{
(_pttList pushBack 2);
};
//if ptt3 radio, add int 3
case (_pttRadioList select 2):
{
(_pttList pushBack 3);
};
//if radio without ptt set, add int 9
default
{
(_pttList pushBack 9);
};
};
_radioChannel pushBack _currentChannel; //add channel to radioChannel
_radioVolume pushBack _currentVolume; //add volume to radioVolume
_radioSpatial pushBack _currentSpatial; //add spatial to radioSpatial
} forEach _radios;
//now we have four arrays - radioChannel, radioVolume, radioSpatial and pttList setup for every radio the player had
[{
params ["_newUnit", "_radioType", "_radioChannel", "_radioVolume", "_radioSpatial", "_pttList", "_newRadioList"];
private _radios = [_radioType, _newUnit] call acre_api_fnc_getAllRadiosByType;
{
//iterate through all NEW radios by IDs, add properties in the order set above
private _radioID = _x;
private _channel = _radioChannel select _forEachIndex;
private _volume = _radioVolume select _forEachIndex;
private _spatial = _radioSpatial select _forEachIndex;
private _pttKey = _pttList select _forEachIndex;
if (_pttKey == 1) then {_newRadioList set [0, _radioID]}; //assign new radio to PTT slot 1
if (_pttKey == 2) then {_newRadioList set [1, _radioID]}; //assign new radio to PTT slot 2
if (_pttKey == 3) then {_newRadioList set [2, _radioID]}; //assign new radio to PTT slot 3
[_radioID, _channel] call acre_api_fnc_setRadioChannel;
[_radioID, _volume] call acre_api_fnc_setRadioVolume;
[_radioID, _spatial] call acre_api_fnc_setRadioSpatial;
} forEach _radios;
}, [_newUnit, _radioType, _radioChannel, _radioVolume, _radioSpatial, _pttList, _newRadioList], 3] call CBA_fnc_waitAndExecute; //delay 3 secs for new radio IDs
} forEach ["ACRE_PRC77", "ACRE_PRC117F", "ACRE_PRC148", "ACRE_PRC152", "ACRE_PRC343", "ACRE_SEM52SL", "ACRE_SEM70", "ACRE_BF888S"]; // for each available ACRE RADIO
[{
params ["_newRadioList"];
//assign the radio IDs of those with assigned PTTs
private _ptt1 = _newRadioList select 0;
private _ptt2 = _newRadioList select 1;
private _ptt3 = _newRadioList select 2;
_pttNewRadioList = [ [_ptt1, _ptt2, _ptt3] ] call acre_api_fnc_setMultiPushToTalkAssignment; //assign new radios to old PTT setup
systemChat format ["Your radio settings have been restored."];
}, [_newRadioList], 5] call CBA_fnc_waitAndExecute; //delay 5 secs to allow above block to complete
}];
// Re-set radio settings on respawn END
This code seems to remove the "Error Zero Divisor" when respawning and only carrying one, or no radios. Changed _newRadioList = []; to _newRadioList set [0, 1]; _newRadioList set [1, 1]; _newRadioList set [2, 1];
in the start of the code.
_newRadioList params [
"_ptt1",
["_ptt2", ""],
["_ptt3", ""]
];
by veteran29 https://discord.com/channels/976165959041679380/976228128156446731/1029520540144255046
PabstMirror in Slack
used by Alablm (Slack)
relevant discussion in ACRE2 Slack: https://ace3public.slack.com/archives/C02012P6T52/p1636353132028800