Advertisement
Guest User

Sickboy

a guest
Mar 10th, 2008
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. /* D_sys_network - s\init.sqf - by Sickboy (sb_at_6thSense.eu)
  2.  * --------------------------------------------------------------
  3.  * Enables network engine support to execute code over the network
  4.  * or make a global say command
  5.  *
  6.  * Notes:
  7.  * - This init.sqf might be executed through a global init script instead of individual XEH Init EH.
  8.  * - Net Engine can be expanded to create individual channels per player, allowing for specific net messaging etc. etc.
  9.  * - PublicVariableEventHandlers do not 'fire' on the computer where you PV the variable. As such we execute the functions also on the computer who calls
  10.  *
  11.  * Examples:
  12.  * - If you want a unit1,unit2, unit3 to say something on every computer:
  13.  * [ [unit1, unit2, unit3], "TestSound" ] call D_NET_fSay;
  14.  * unit1, 2 and 3 would say "TestSound" (if it existed :p)
  15.  *
  16.  * - To execute sth on server:
  17.  * [ 0, { superDebugMode = true } ] call D_NET_fSend;
  18.  *
  19.  * - To execute sth on all clients:
  20.  * [ -1, { superDebugMode = true; player sideChat "Woah Sweet!!" }] call D_NET_fSend;
  21.  *
  22.  * - To execute sth on all clients, unit1, unit2, unit3 write something
  23.  * [ -1, { superDebugMode = true; { _x sideChat "Woah Sweet!!" } forEach _this }, [unit1, unit2, unit3]] call D_NET_fSend;
  24.  *
  25.  *
  26. */
  27.  
  28. // Announce the initialization of the script
  29. D_sys_network = false;
  30.  
  31.  
  32. // Say Engine
  33. D_NET_fSay = { D_PUB_SAY = _this; publicVariable "D_PUB_SAY"; {_x say (_this select 1)} forEach (_this select 0) };
  34. "D_PUB_SAY" addPublicVariableEventHandler { private ["_ar"]; _ar =_this select 1; {_x say (_ar select 1)} forEach (_ar select 0) };
  35.  
  36.  
  37. // Net Engine
  38. D_NET_fSend = { D_PUB_CMD = _this; publicVariable "D_PUB_CMD"; _this call D_NET_fExec };
  39. D_NET_fExec =
  40. {
  41.     private ["_chan", "_cmd", "_objAr", "_ex"];
  42.     _chan = _this select 0;
  43.     _cmd = _this select 1;
  44.     if (count _this > 2) then { _objAr = _this select 2 } else { _objAr = [] };
  45.  
  46.     switch _chan do
  47.     {
  48.         case 0: { if (isServer) then { _ex = true } };
  49.         case -1: { if (player == player) then { _ex = true } };
  50.         case -2: { _ex = true };
  51.         default { _ex = false };
  52.     };
  53.     if (_ex) then { _objAr spawn _cmd };
  54. };
  55.  
  56. "D_PUB_CMD" addPublicVariableEventHandler { (_this select 1) call D_NET_fExec };
  57.  
  58.  
  59. // Announce the completion of the initialization of the script
  60. D_sys_network = true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement