Player_SCFramework.SQF 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. Player_SCFramework.SQF
  3. Player-side global variables, functions, and eventhandlers for BDC's Client ID's Framework
  4. Written for A3 by ^bdc May 2017
  5. */
  6. if (!hasInterface || isServer) exitWith {}; // player clients only
  7. SCFramework_ClientID = nil; // This global variable may be referenced by any other script if needed for owner/clientID purposes
  8. // Eventhandler that sent from server when initial eventhandler below is called by player client machine
  9. "SCFramework_PlayerSendClientID" addPublicVariableEventHandler {
  10. _Array = _this select 1;
  11. _SentUID = _Array select 0;
  12. _SentClientID = _Array select 1;
  13. if (getPlayerUID player == _SentUID) then {
  14. SCFramework_ClientID = _SentClientID; // This global variable may be referenced by any other script if needed
  15. diag_log format["(SCFramework) Response received from server. My Client ID: %1",SCFramework_ClientID];
  16. };
  17. };
  18. // Response from server for on-the-fly ServerFPSReport
  19. "SCFramework_ServerFPSResponse" addPublicVariableEventHandler {
  20. if (ServerFPSReport_Enabled) then {
  21. _Array = _this select 1;
  22. ServerFPSReport_Received = ServerFPSReport_Received + [_Array];
  23. };
  24. };
  25. // Display event handler that captures keystroke to fire up ServerFPSReport
  26. BDC_SCFramework_ServerFPSReportKeystroke = {
  27. // Passed Args
  28. _dikCode = _this select 1;
  29. _shiftState = _this select 2;
  30. _ctrlState = _this select 3;
  31. _altState = _this select 4;
  32. _handled = false;
  33. // Server FPS Report (Configured keystroke) (SCFramework)
  34. if (_dikCode == (BDC_SCFramework_ServerFPSReport_KeyCodes select 0) && !_shiftState && !_ctrlState && !_altState) then {
  35. if (ServerFPSReport_Enabled) then {
  36. hintSilent "";
  37. ServerFPSReport_Enabled = false;
  38. cutText ["Server FPS Reporting DISABLED.", "PLAIN DOWN"];
  39. } else {
  40. ServerFPSReport_Enabled = true;
  41. [] spawn SCFramework_DisplayFPSReport;
  42. cutText ["Server FPS Reporting ENABLED.", "PLAIN DOWN"];
  43. };
  44. _handled = true;
  45. };
  46. if (_dikCode == (0x3C) && !_shiftState && !_ctrlState && !_altState) then {
  47. if (BDC_SCFramework_HCOffloading_AutomaticOffLoading_TransferZeusOperatorAI_Enable) then {
  48. BDC_SCFramework_HCOffloading_AutomaticOffLoading_TransferZeusOperatorAI_Enable = false;
  49. cutText ["Automatic Transferrence of Zeus-spawned AI DISABLED.", "PLAIN DOWN"];
  50. } else {
  51. BDC_SCFramework_HCOffloading_AutomaticOffLoading_TransferZeusOperatorAI_Enable = true;
  52. cutText ["Automatic Transferrence of Zeus-spawned AI ENABLED.", "PLAIN DOWN"];
  53. if (!BDC_SCFramework_TransferZeusOwnedAI_InitialEnable) then {
  54. BDC_SCFramework_TransferZeusOwnedAI_InitialEnable = true;
  55. [] spawn BDC_SCFramework_TransferZeusOwnedAI;
  56. };
  57. };
  58. };
  59. //diag_log format["keystroke EH TEST - dikcode %1 shiftstate %2 ctrlstate %3 altstate %4 handled %5",_dikCode,_shiftState,_ctrlState,_altSTate,_handled];
  60. _handled
  61. };
  62. diag_log format["(SCFramework) Player Client: Global variables reset and eventhandlers/functions loaded."];
  63. BDC_SCFramework_TransferZeusOwnedAI = {
  64. // Check if Zeus operator owns spawned-in AI
  65. diag_log format["(SCFramework) Starting TransferZeusOwnedAI monitor."];
  66. while {true} do {
  67. _PlayerGroup = group player;
  68. {
  69. _Group = _x;
  70. _ZeusFlagged = false;
  71. _ZeusFlagged = _Group getVariable ["ZeusFlagged",false];
  72. if (local _Group && (_PlayerGroup != _Group) && (!_ZeusFlagged) && BDC_SCFramework_HCOffloading_AutomaticOffLoading_TransferZeusOperatorAI_Enable) then { // We'll skip checking the group that we're in; otherwise it'll spam the server
  73. if (count units _Group > 0) then {
  74. if (BDC_SCFramework_HCOffloading_AutomaticOffLoading_TransferZeusOperatorAI_FlagOffloadedGroups) then {
  75. _Group setVariable ["ZeusFlagged",true,true]; // If enabled, only allow this group to automatically move to server once if it is moved back to a Zeus Op
  76. };
  77. SCFramework_ResetGroupOwnership = _Group;
  78. publicVariableServer "SCFramework_ResetGroupOwnership";
  79. if (BDC_SCFramework_DetailedLogging) then {
  80. diag_log format["(SCFramework) Transferring locally-owned AI group %1 to server.",_Group];
  81. };
  82. };
  83. };
  84. } forEach allGroups;
  85. sleep BDC_SCFramework_HCOffloading_AutomaticOffLoading_TransferZeusOperatorAI_Frequency;
  86. };
  87. };
  88. // Check if admin for Server FPS report
  89. waitUntil {!isNull player};
  90. sleep 3;
  91. if ((getPlayerUID player) in BDC_SCFramework_ServerFPSReport_AdminUIDList) then {
  92. Fnc_ServerFPSReport = compile preProcessFileLineNumbers "SCFramework\Fnc_ServerFPSReport.SQF";
  93. [] spawn Fnc_ServerFPSReport;
  94. player addEventHandler ["Respawn",{ [] spawn Fnc_ServerFPSReport; }];
  95. BDC_SCFramework_ServerFPSReport_KeyboardPress = (findDisplay 46) displayAddEventHandler ["KeyDown","_this call BDC_SCFramework_ServerFPSReportKeystroke"];
  96. diag_log format["(SCFramework) Admin eventhandlers added. Press the F1 key to access the Server FPS report."];
  97. };
  98. // Automatic transfer of Zeus-owned AI
  99. if (BDC_SCFramework_HCOffloading_AutomaticOffLoading_TransferZeusOperatorAI_Enable) then {
  100. [] spawn BDC_SCFramework_TransferZeusOwnedAI;
  101. BDC_SCFramework_TransferZeusOwnedAI_InitialEnable = true;
  102. } else {
  103. BDC_SCFramework_TransferZeusOwnedAI_InitialEnable = false;
  104. };