Ability to change permissions for offline players

closes #365
This commit is contained in:
Wyqer 2018-04-07 10:39:40 +02:00
parent 7b65c5332a
commit 7b736a9aca
No known key found for this signature in database
GPG Key ID: 2D3FEE0019ED51F5
5 changed files with 109 additions and 105 deletions

View File

@ -1,9 +1,8 @@
waitUntil { !isNil "GRLIB_permissions" };
waitUntil {!isNil "GRLIB_permissions"};
private [ "_dialog", "_nextplayer", "_players_array", "_displayname", "_idx", "_control", "_player_uid", "_player_idx", "_player_uids", "_player_permissions", "_modify_permissions" ];
_players_array = [];
_dialog = createDialog "liberation_permissions";
private _players_array = [];
private _uids_array = ["Default"];
private _dialog = createDialog "liberation_permissions";
permission_playerid = -1;
permission_toset = -1;
save_changes = 0;
@ -12,12 +11,7 @@ color_authorized = [0,0.9,0,1];
color_denied = [0.9,0,0,1];
fontsize = 0.017 * safezoneH;
_modify_permissions = [];
{
_player_uid = _x select 0;
_player_permissions = [] + ( _x select 1 );
_modify_permissions pushback [ _player_uid, _player_permissions ];
} foreach GRLIB_permissions;
private _modify_permissions = +GRLIB_permissions;
disableSerialization;
@ -26,14 +20,14 @@ waitUntil { dialog };
permission_create_activetext = compileFinal '
params [ "_idx", "_column", "_permission", "_text", "_tooltip" ];
params ["_idx", "_column", "_permission", "_text", "_tooltip"];
_control = (findDisplay 5118) ctrlCreate [ "RscActiveText", ((10 * _idx) + 111) + _column, (findDisplay 5118) displayCtrl 9969 ];
_control ctrlSetPosition [ 0.072 * _column * safeZoneW, (_idx * 0.025) * safezoneH, 0.072 * safeZoneW, 0.025 * safezoneH];
private _control = (findDisplay 5118) ctrlCreate ["RscActiveText", ((10 * _idx) + 111) + _column, (findDisplay 5118) displayCtrl 9969];
_control ctrlSetPosition [0.072 * _column * safeZoneW, (_idx * 0.025) * safezoneH, 0.072 * safeZoneW, 0.025 * safezoneH];
_control ctrlSetText _text;
_control ctrlSetFontHeight fontsize;
_control ctrlSetTooltip _tooltip;
buttonSetAction [ ((10 * _idx) + 111) + _column, format [ "permission_playerid = %1; permission_toset = %2;", _idx, _permission ] ];
buttonSetAction [((10 * _idx) + 111) + _column, format ["permission_playerid = %1; permission_toset = %2;", _idx, _permission]];
_control ctrlSetTextColor color_denied;
_control ctrlSetActiveColor color_denied;
_control ctrlCommit 0;
@ -42,123 +36,133 @@ permission_create_activetext = compileFinal '
_players_array pushback [ "Default", localize "STR_DEFAULT", 0];
_idx = 2;
_players_array pushback ["Default", localize "STR_DEFAULT", 0];
private _idx = 2;
{
if ( !( (name _x) in [ "HC1", "HC2", "HC3" ] ) ) then {
_nextplayer = _x;
if (!((name _x) in ["HC1", "HC2", "HC3"])) then {
private _nextplayer = _x;
_displayname = "";
private _displayname = "";
if(count (squadParams _nextplayer) != 0) then {
_displayname = "[" + ((squadParams _nextplayer select 0) select 0) + "] ";
};
_displayname = _displayname + name _nextplayer;
_players_array pushback [ getPlayerUID _nextplayer, _displayname, _idx ];
_players_array pushback [getPlayerUID _nextplayer, _displayname, _idx];
_uids_array pushBack getPlayerUID _nextplayer;
_idx = _idx + 1;
};
} foreach allPlayers;
_idx = _idx + 1;
{
_nextplayer = _x;
_idx = _nextplayer select 2;
if !((_x select 0) in _uids_array) then {
_players_array pushBack [_x select 0, _x select 1, _idx];
_idx = _idx + 1;
}
} forEach _modify_permissions;
if ( _idx % 2 == 0 ) then {
{
private _nextplayer = _x;
private _idx = _nextplayer select 2;
_control = (findDisplay 5118) ctrlCreate [ "RscBackground", -1, (findDisplay 5118) displayCtrl 9969 ];
_control ctrlSetPosition [ 0, (_idx * 0.025) * safezoneH, 0.595 * safeZoneW, 0.025 * safezoneH];
if (_idx % 2 == 0) then {
private _control = (findDisplay 5118) ctrlCreate ["RscBackground", -1, (findDisplay 5118) displayCtrl 9969];
_control ctrlSetPosition [0, (_idx * 0.025) * safezoneH, 0.595 * safeZoneW, 0.025 * safezoneH];
_control ctrlSetBackgroundColor [0.75,1,0.75,0.12];
_control ctrlCommit 0;
};
_control = (findDisplay 5118) ctrlCreate [ "RscText", (10 * _idx), (findDisplay 5118) displayCtrl 9969 ];
_control ctrlSetPosition [ 0, (_idx * 0.025) * safezoneH, 0.072 * safeZoneW, 0.025 * safezoneH];
private _control = (findDisplay 5118) ctrlCreate ["RscText", (10 * _idx), (findDisplay 5118) displayCtrl 9969];
_control ctrlSetPosition [0, (_idx * 0.025) * safezoneH, 0.072 * safeZoneW, 0.025 * safezoneH];
_control ctrlSetText (_nextplayer select 1);
_control ctrlSetFontHeight fontsize;
_control ctrlCommit 0;
[ _idx, 1, 0, localize "STR_PERMISSIONS_LIGHT", localize "STR_PERMISSIONS_TOOLTIP_LIGHT" ] call permission_create_activetext;
[ _idx, 2, 1, localize "STR_PERMISSIONS_ARMORED", localize "STR_PERMISSIONS_TOOLTIP_ARMORED" ] call permission_create_activetext;
[ _idx, 3, 2, localize "STR_PERMISSIONS_AIR", localize "STR_PERMISSIONS_TOOLTIP_AIR" ] call permission_create_activetext;
[ _idx, 4, 3, localize "STR_PERMISSIONS_CONSTRUCTION", localize "STR_PERMISSIONS_TOOLTIP_CONSTRUCTION" ] call permission_create_activetext;
[ _idx, 5, 4, localize "STR_PERMISSIONS_RECYCLING", localize "STR_PERMISSIONS_TOOLTIP_RECYCLING" ] call permission_create_activetext;
[ _idx, 6, 5, localize "STR_PERMISSIONS_MISC", localize "STR_PERMISSIONS_TOOLTIP_MISC" ] call permission_create_activetext;
[_idx, 1, 0, localize "STR_PERMISSIONS_LIGHT", localize "STR_PERMISSIONS_TOOLTIP_LIGHT"] call permission_create_activetext;
[_idx, 2, 1, localize "STR_PERMISSIONS_ARMORED", localize "STR_PERMISSIONS_TOOLTIP_ARMORED"] call permission_create_activetext;
[_idx, 3, 2, localize "STR_PERMISSIONS_AIR", localize "STR_PERMISSIONS_TOOLTIP_AIR"] call permission_create_activetext;
[_idx, 4, 3, localize "STR_PERMISSIONS_CONSTRUCTION", localize "STR_PERMISSIONS_TOOLTIP_CONSTRUCTION"] call permission_create_activetext;
[_idx, 5, 4, localize "STR_PERMISSIONS_RECYCLING", localize "STR_PERMISSIONS_TOOLTIP_RECYCLING"] call permission_create_activetext;
[_idx, 6, 5, localize "STR_PERMISSIONS_MISC", localize "STR_PERMISSIONS_TOOLTIP_MISC"] call permission_create_activetext;
_control = (findDisplay 5118) ctrlCreate [ "RscButton", ((10 * _idx) + 111) + 7, (findDisplay 5118) displayCtrl 9969 ];
_control ctrlSetPosition [ ((0.075 * 7) - 0.02) * safeZoneW, ((_idx * 0.025) * safezoneH) + 0.0025, (0.035 * safeZoneW), 0.022 * safezoneH];
_control = (findDisplay 5118) ctrlCreate ["RscButton", ((10 * _idx) + 111) + 7, (findDisplay 5118) displayCtrl 9969];
_control ctrlSetPosition [((0.075 * 7) - 0.02) * safeZoneW, ((_idx * 0.025) * safezoneH) + 0.0025, (0.035 * safeZoneW), 0.022 * safezoneH];
_control ctrlSetText (localize "STR_PERMISSIONS_ALL");
_control ctrlSetFontHeight fontsize;
_control ctrlSetTooltip (localize "STR_PERMISSIONS_TOOLTIP_ALL");
buttonSetAction [ ((10 * _idx) + 111) + 7, format [ "permission_playerid = %1; permission_toset = 666;", _idx ] ];
buttonSetAction [ ((10 * _idx) + 111) + 7, format ["permission_playerid = %1; permission_toset = 666;", _idx]];
_control ctrlCommit 0;
_control = (findDisplay 5118) ctrlCreate [ "RscButton", ((10 * _idx) + 111) + 8, (findDisplay 5118) displayCtrl 9969 ];
_control ctrlSetPosition [ ((0.075 * 7) + 0.02) * safeZoneW, (_idx * 0.025) * safezoneH + 0.0025, 0.035 * safeZoneW, 0.022 * safezoneH];
_control = (findDisplay 5118) ctrlCreate ["RscButton", ((10 * _idx) + 111) + 8, (findDisplay 5118) displayCtrl 9969];
_control ctrlSetPosition [((0.075 * 7) + 0.02) * safeZoneW, (_idx * 0.025) * safezoneH + 0.0025, 0.035 * safeZoneW, 0.022 * safezoneH];
_control ctrlSetText (localize "STR_PERMISSIONS_NONE");
_control ctrlSetFontHeight fontsize;
_control ctrlSetTooltip (localize "STR_PERMISSIONS_TOOLTIP_NONE");
buttonSetAction [ ((10 * _idx) + 111) + 8, format [ "permission_playerid = %1; permission_toset = 999;", _idx ] ];
buttonSetAction [((10 * _idx) + 111) + 8, format ["permission_playerid = %1; permission_toset = 999;", _idx]];
_control ctrlCommit 0;
} foreach _players_array;
while { dialog && alive player } do {
while {dialog && alive player} do {
if ( permission_playerid != -1 || permission_toset != -1 ) then {
if (permission_playerid != -1 || permission_toset != -1) then {
_player_uid = "";
private _player_uid = "";
private _player_name = "";
{
if ( _x select 2 == permission_playerid ) exitWith { _player_uid = _x select 0 };
if (_x select 2 == permission_playerid) exitWith {_player_uid = _x select 0; _player_name = _x select 1;};
} foreach _players_array;
if ( _player_uid != "" ) then {
if (_player_uid != "") then {
_player_idx = -1;
_player_uids = [];
private _player_idx = -1;
private _player_uids = [];
private _player_permissions = [];
{
_player_uids pushback (_x select 0);
} foreach _modify_permissions;
_player_idx = _player_uids find _player_uid;
if ( permission_toset == 666 ) then {
_player_permissions = [ true, true, true, true, true, true ];
if (permission_toset == 666) then {
_player_permissions = [true, true, true, true, true, true];
};
if ( permission_toset == 999 ) then {
_player_permissions = [ false, false, false, false, false, false ];
if (permission_toset == 999) then {
_player_permissions = [false, false, false, false, false, false];
};
if ( _player_idx == -1 ) then {
if (_player_idx == -1) then {
if ( permission_toset != 666 && permission_toset != 999 ) then {
_player_permissions = [ false, false, false, false, false, false ];
_player_permissions set [ permission_toset, true ];
if (permission_toset != 666 && permission_toset != 999) then {
_player_permissions = [false, false, false, false, false, false];
_player_permissions set [permission_toset, true];
};
_modify_permissions pushback [ _player_uid, _player_permissions ];
_modify_permissions pushback [_player_uid, _player_name, _player_permissions];
} else {
if ( permission_toset != 666 && permission_toset != 999 ) then {
if (permission_toset != 666 && permission_toset != 999) then {
_player_permissions = (_modify_permissions select _player_idx) select 1;
_player_permissions = (_modify_permissions select _player_idx) select 2;
_idx = 0;
private _idx = 0;
{
if ( permission_toset == _idx ) exitWith {
if ( _player_permissions select _idx ) then {
_player_permissions set [ _idx, false ];
if (permission_toset == _idx) exitWith {
if (_player_permissions select _idx) then {
_player_permissions set [_idx, false];
} else {
_player_permissions set [ _idx, true ];
_player_permissions set [_idx, true];
};
};
_idx = _idx + 1;
} foreach _player_permissions;
};
_modify_permissions set [ _player_idx, [ _player_uid, _player_permissions ] ];
_modify_permissions set [_player_idx, [_player_uid, _player_name, _player_permissions]];
};
};
@ -167,32 +171,32 @@ while { dialog && alive player } do {
};
{
_nextplayer = _x;
private _nextplayer = _x;
{
if ( _nextplayer select 0 == _x select 0 ) exitWith {
_idx = _nextplayer select 2;
_player_permissions = (_x select 1);
if (_nextplayer select 0 == _x select 0) exitWith {
private _idx = _nextplayer select 2;
private _player_permissions = _x select 2;
{
_control = ((findDisplay 5118) displayCtrl ((10 * _idx) + _x + 111));
if ( _player_permissions select (_x - 1)) then {
private _control = ((findDisplay 5118) displayCtrl ((10 * _idx) + _x + 111));
if (_player_permissions select (_x - 1)) then {
_control ctrlSetTextColor color_authorized;
_control ctrlSetActiveColor color_authorized;
} else {
_control ctrlSetTextColor color_denied;
_control ctrlSetActiveColor color_denied;
};
} foreach [ 1, 2, 3, 4, 5, 6 ];
} foreach [1, 2, 3, 4, 5, 6];
};
} foreach _modify_permissions;
} foreach _players_array;
if ( save_changes == 1 ) then {
GRLIB_permissions = _modify_permissions;
if (save_changes == 1) then {
GRLIB_permissions = +_modify_permissions;
publicVariable "GRLIB_permissions";
closeDialog 0;
};
waitUntil { !dialog || !(alive player) || permission_playerid != -1 || permission_toset != -1 || save_changes != 0 };
};
waitUntil {!dialog || !(alive player) || permission_playerid != -1 || permission_toset != -1 || save_changes != 0};
};

View File

@ -1,33 +1,31 @@
if ( !GRLIB_permissions_param ) exitWith {};
if (!GRLIB_permissions_param) exitWith {};
private [ "_default_permissions", "_all_players_uids", "_old_count" ];
waitUntil {!isNil "GRLIB_permissions"};
waitUntil {!isNil "save_is_loaded"};
waitUntil { !(isNil "GRLIB_permissions") };
waitUntil { !isNil "save_is_loaded" };
while {true} do {
while { true } do {
private _default_permissions = [];
{if ((_x select 0) == "Default") exitWith {_default_permissions = (_x select 2);}} foreach GRLIB_permissions;
_default_permissions = [];
{ if ( ( _x select 0 ) == "Default" ) exitWith { _default_permissions = (_x select 1); } } foreach GRLIB_permissions;
if (count _default_permissions > 0) then {
private _all_players_uids = [];
{if ((_x select 0) != "Default") then {_all_players_uids pushback (_x select 0)}} foreach GRLIB_permissions;
if ( count _default_permissions > 0 ) then {
_all_players_uids = [];
{ if ( ( _x select 0 ) != "Default" ) then { _all_players_uids pushback (_x select 0) } } foreach GRLIB_permissions;
_old_count = count GRLIB_permissions;
private _old_count = count GRLIB_permissions;
{
if ( !( (name _x) in [ "HC1", "HC2", "HC3" ] ) ) then {
if ( !((getPlayerUID _x) in _all_players_uids) ) then {
GRLIB_permissions pushback [ (getPlayerUID _x), _default_permissions ];
if (!((name _x) in ["HC1", "HC2", "HC3"])) then {
if (!((getPlayerUID _x) in _all_players_uids)) then {
GRLIB_permissions pushback [(getPlayerUID _x), (name _x), _default_permissions];
};
};
} foreach allPlayers;
if ( _old_count != count GRLIB_permissions ) then {
if (_old_count != count GRLIB_permissions) then {
publicVariable "GRLIB_permissions"
};
};
sleep 10;
};
};

View File

@ -138,6 +138,8 @@ if (!isNil "greuh_liberation_savegame") then {
if (count greuh_liberation_savegame > 11) then {
GRLIB_permissions = greuh_liberation_savegame select 11;
// Compatibility with prior version (reset once for reassign)
if (count (GRLIB_permissions select 0) < 3) then {GRLIB_permissions = [];};
};
if (count greuh_liberation_savegame > 12) then {

View File

@ -1,26 +1,25 @@
params [ "_source", "_permission" ];
private [ "_uidvar", "_ret" ];
params ["_source", "_permission"];
if ( isNil "GRLIB_last_permission_check_time" ) then { GRLIB_last_permission_check_time = -1000; };
if ( isNil "GRLIB_permissions_cache" ) then { GRLIB_permissions_cache = []; };
if (isNil "GRLIB_last_permission_check_time") then {GRLIB_last_permission_check_time = -1000;};
if (isNil "GRLIB_permissions_cache") then {GRLIB_permissions_cache = [];};
_ret = false;
private _ret = false;
if ( !GRLIB_permissions_param ) then {
if (!GRLIB_permissions_param) then {
_ret = true;
} else {
if ( !(isNil "GRLIB_permissions") && !(isNull _source) ) then {
if (!(isNil "GRLIB_permissions") && !(isNull _source)) then {
if ( time > GRLIB_last_permission_check_time + 10 ) then {
if ( time > GRLIB_last_permission_check_time + 10) then {
GRLIB_last_permission_check_time = time;
_uidvar = getPlayerUID _source;
{ if ( _uidvar == _x select 0 ) exitWith { GRLIB_permissions_cache = [] + (_x select 1) }; } foreach GRLIB_permissions;
private _uidvar = getPlayerUID _source;
{if (_uidvar == _x select 0) exitWith {GRLIB_permissions_cache = [] + (_x select 2)};} foreach GRLIB_permissions;
};
if ( count GRLIB_permissions_cache > _permission ) then {
if (count GRLIB_permissions_cache > _permission) then {
_ret = GRLIB_permissions_cache select _permission;
};
};
};
_ret
_ret

View File

@ -170,6 +170,7 @@ class Missions
* Tweaked: All `createGroup` now with activated `deleteWhenEmpty`.
* Tweaked: All `BIS_fnc_relPos` replaced with `getPos`.
* Tweaked: Guerilla forces event chances, strength gain values and unit amounts.
* Tweaked: The Commander / Admin can now change the permissions of offline players.
* Fixed: Placement of buildings after save/load. Thanks to [Cre8or](https://github.com/Cre8or)
* Fixed: Sometimes helicopters exploded when spawning on the deck of the USS Freedom.
* Fixed: Players couldn't ziptie the civilian informant, if playing with ACE.