Announcement

Collapse
No announcement yet.

Mission Template & Functions for newer mission makers

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mission Template & Functions for newer mission makers

    I'm pretty new to scripting & I like to make myself go through the motions of learning so I've made a template of functions here to use in multiplayer missions. Credit is due to shay_gman as I learned this from the MCC Sandbox. I was looking for a way of getting things like global hints & globalExecute available to our mission makers without having clients using the cba_fnc_globalExecute and thus CBA required on all clients.

    I will give the TEMPLATE HERE.

    In the next few days I'll put up some documentation on how to use this in the following posts. (I'll be moving on to learning the F2 Framework next now that I understand the MP environment much better.)

    Here is the script for creating the actual functions.

    Code:
    //TG functions for MP
    //compiled by Unkl for TacticalGamer.com
    //add following to your init.sqf...
    //null = []execVM "TG\TG_functions.sqf";  //initialize TG functions for TacticalGamer.com MP missions 
    //only working from within scripts - unknown how to use on triggers in editor atm - Sept 
    
    /*
    *****************************************************************************************************************************************
    **  TG_fnc_controlChat to send chat across MP                                                                                          **
    **  Usage:                                                                                                                             **
    **  [[[netid _unit,_unit],_text,_local], "TG_fnc_controlChat", true, false] spawn BIS_fnc_MP;                                          **
    **  where _unit is the object that is broadcasting in globalChat                                                                       **
    **  where _text is the message to broadcast                                                                                            **
    **  where _local is boolean: false is all clients and server, true is only to the local originating machine                            **
    **  Credit for grabbing this code from MCC Sandbox by shay_gman                                                                        **
    *****************************************************************************************************************************************
    */
    TG_fnc_controlChat = 
    {
    	private ["_unit","_text","_local"];
    	_unit = if (((_this select 0) select 0) == "") then {(_this select 0) select 1} else {objectFromNetID ((_this select 0) select 0)};
    	_text = _this select 1;
    	_local = _this select 2;
    	if (_local && !(local _unit) || (isDedicated)) exitWith {};
    	_unit globalChat _text;
    };
    
    /*
    ***************************************************************************************************************
    **  TG_fnc_gobalExecute to execute code from any source on either a) all clients, b) server only, or c) all  **
    **  Usage:                                                                                                   **
    **  [[target,code], "TG_fnc_globalExecute", true, false] spawn BIS_fnc_MP;                                   **
    **  where target = 0 is clients only, where target = 1 is server only, and where target = 2 is all           **
    **  where code = the code you want to execute                                                                **
    **  where the boolean values control: true makes this BIS function fire on all computers,                    **
    **                                    false makes it not persitent for all jips                              **
    **                                    LEAVE THESE AS THEY ARE                                                **
    **  Credit to getting this basic idea from MCC Sandbox. - Unkl                                               **
    ***************************************************************************************************************
    */
    TG_fnc_globalExecute = 
    {
    	private ["_target","_code"];
    	
    	_target = _this select 0;
    	_code = _this select 1;
    	
    	switch (_target) do
    	{
    		case 0:  //clients
    		{
    			if !(isServer) then {call _code};
    		};
    		
    		case 1:  //server only
    		{
    			if (isServer) then {call _code};
    		};
    		
    		case 2:  //all
    		{
    			call _code;
    		};
    	};
    };
    
    /*
    ********************************************************************************************************
    **  TG_fnc_globalHint to display a hint on all computers                                              **
    **  Usage:                                                                                            **
    **  [[hint], "TG_fnc_globalHint", true, true] spawn BIS_fnc_MP;                                       **
    **  where hint is the message you want delivered to all computers                                     **
    **  Credit to idea from MCC Sandbox - Unkl                                                            **
    ********************************************************************************************************
    */
    TG_fnc_globalHint =
    {
    	private ["_mssg"];
    	
    	_mssg = _this select 0;
    	hint _mssg;
    };
    
    /*
    **********************************************************************************************************************
    **  TG_fnc_globalSay3D to have any unit say a sound defined in your description.ext config in 3D space              **
    **  Usage:                                                                                                          **
    **  [[[netid _unit,_unit], _sound], "TG_fnc_globalSay3D", true, false] spawn BIS_fnc_MP;                            **
    **  where _unit is the objects sound source (not sure why there is the condition to use netid)                      **
    **  where _sound is the sound you want to play as defined in the description.ext                                    **
    **  Credit to grabbing this code from MCC Sandbox by shay_gman                                                      **
    **********************************************************************************************************************
    */
    TG_fnc_globalSay3D =
    {
    	private ["_object","_sound"];
    	
    	_sound = _this select 1;
    	_object = if(((_this select 0) select 0) == "") then {(_this select 0) select 1} else {objectFromNetID ((_this select 0) select 0)};
    	_object say3D _sound;
    };
    
    /*
    **********************************************************************************************************************************************
    ** TG_fnc_moveToPos to move an object to a new location                                                                                     **
    **  Usage:                                                                                                                                  **
    **  [[[netid _unit,_unit],_pos], "TG_fnc_moveToPos", true, false] spawn BIS_fnc_MP;                                                         **
    **  where _unit is the object to move                                                                                                       **
    **  where _pos is the array of the position [x,y,z]                                                                                         **
    **  Credit for grabbing code from MCC Sandbox by shay_gman                                                                                  **
    **********************************************************************************************************************************************
    */
    TG_fnc_moveToPos = 
    {
    	private ["_unit","_pos"];
    	
    	_unit = if (((_this select 0) select 0) == "") then {(_this select 0) select 1} else {objectFromNetID ((_this select 0) select 0)};
    	_pos = _this select 1;
    	_unit setpos _pos;
    };
    HERE is my test mission with the script "test.sqf" that you can see how I tested the usage if you like. (Thanks to Chichco, JohnFlenaly & Yink for testing with me)
    |TG-189th| Unkl
    ArmA 3 Game Officer
    Dean of Tactical Gamer University
    189th Infantry Brigade Member
    SUBMIT A RIBBON NOMINATION OR CONTACT AN ARMA ADMIN
    "We quickly advance in the opposite direction and take cover in a house on the SW side of town." - BadStache

  • #2
    Re: Mission Template & Functions for newer mission makers

    TG_fnc_globalHint

    In this example lets say an event local to our client should make a hint show up for all players. Lets say we have a script running on all clients that checks if the player gets close the stinky garbage bin he's been told to find. Once "player distance stinkyGarbage < 5" or...

    Code:
    _run = true;
    while {_run} do
      if (player distance stinkyGarbage < 5) then
      {
        [[format ["%1 has just located the stinky garbage we've been looking for.", name player]], "TG_fnc_globalHint", true, true] spawn BIS_fnc_MP;
        _run = false;
      };
      sleep 1;
    };
    Line 5 above would produce a hint that reads "|TG-189th| Unkl has just located the stinky garbage we've been looking for." and broadcast it to all the connected clients and the server. Additionally, with the coloured "true" this makes the hint persistent so it will show for players who join after the event has fired. Of course it might be overwritten and they may not see it. However, it is possible to do so. It is also advisable to only make the BIS_fnc_MP persistent only if you must. Unnecessary use of this as persistent will lag up the server as you get jips.
    |TG-189th| Unkl
    ArmA 3 Game Officer
    Dean of Tactical Gamer University
    189th Infantry Brigade Member
    SUBMIT A RIBBON NOMINATION OR CONTACT AN ARMA ADMIN
    "We quickly advance in the opposite direction and take cover in a house on the SW side of town." - BadStache

    Comment

    Connect

    Collapse

    TeamSpeak 3 Server

    Collapse

    Advertisement

    Collapse

    Twitter Feed

    Collapse

    Working...
    X