Jump to content
Sign in to follow this  
Brostrom.A | Evul

Mission scripts on dedicated server and online gaming

Recommended Posts

Hello I've trying to make a script that actually work on a dedicated server but the script does not launch.

 

Is there a way to make a script look if it is a dedicated server and then add a loadout to a unit without running the risk of not launching it or re adding the gear each time people join?

 

Here is the script i'm working on:

 

it suppose to have more then one kind of unit type.

 

initUnit.sqf

// null = [this, "MILITARY"] execVM 'Terrorists\initUnit.sqf';
// null = [this, "POLICE"] execVM 'Terrorists\initUnit.sqf';

if (! isServer) exitWith {};

_unit = _this select 0;
_type = _this select 1;

switch(_type) do {
	case "MILITARY" : {
		[_unit] execVM 'Terrorists\initUnit_MILITARY.sqf';
	};
	case "POLICE" : {
		[_unit] execVM 'Terrorists\initUnit_POLICE.sqf';
	};
};
 

initUnit_MILITARY.sqf

if (! isServer) exitWith {};

_unit = _this select 0;

if (typeOf _unit == 'I_Soldier_SL_F' ) then {
	null = [_unit] execVM 'Terrorists\Units\GEAR_TO_SL.sqf';
};
GEAR_TO_SL.sqf

waitUntil {!isNull player};
_unit = _this select 0;

removeAllWeapons _unit;
removeAllItems _unit;
removeAllAssignedItems _unit;
removeUniform _unit;
removeVest _unit;
removeBackpack _unit;
removeHeadgear _unit;
removeGoggles _unit;

_unit addHeadgear "H_HelmetB";
_unit addGoggles "G_Tactical_Black";

_unit forceAddUniform "U_B_CTRG_1";
	_unit addItemToUniform "ACE_MapTools";
	_unit addItemToUniform "ACE_EarBuds";
	_unit addItemToUniform "ACE_Morphine";
	for "_i" from 1 to 2 do {_unit addItemToUniform "ACE_CableTie";};
	for "_i" from 1 to 2 do {_unit addItemToUniform "ACE_fieldDressing";};
	for "_i" from 1 to 2 do {_unit addItemToUniform "Chemlight_red";};
	for "_i" from 1 to 2 do {_unit addItemToUniform "Chemlight_blue";};
	for "_i" from 1 to 2 do {_unit addItemToUniform "Chemlight_green";};


_unit addVest "V_PlateCarrier1_blk";
	_unit addItemToVest "SmokeShell";
	_unit addItemToVest "SmokeShellGreen";
	for "_i" from 1 to 2 do {_unit addItemToVest "HandGrenade";};
	for "_i" from 1 to 8 do {_unit addItemToVest "20Rnd_762x51_Mag";};
	for "_i" from 1 to 2 do {_unit addItemToVest "rhs_mag_9x19_17";};

_unit addWeapon "srifle_DMR_03_F";
_unit addPrimaryWeaponItem "optic_Hamr";
_unit addPrimaryWeaponItem "acc_pointer_IR";

_unit addWeapon "rhs_weap_pya";
_unit addWeapon "Laserdesignator";
	_unit addItemToUniform "Laserbatteries";

_unit linkItem "ItemMap";
_unit linkItem "ItemCompass";
_unit linkItem "ItemWatch";
_unit linkItem "tf_anprc154";
_unit linkItem "ItemcTab";
_unit linkItem "rhsusf_ANPVS_14";

_unit setObjectTextureGlobal [0, "Terrorists\data\uniform\CAV_U_TerrorUniform1_TO.paa"]; 

Share this post


Link to post
Share on other sites

How are you calling the script?
 
Word of advice, always 'private' your local vars, e.g.:

if (!isServer) exitWith {};
 
params ["_unit","_type"];
 
switch (_type) do {
	case "MILITARY" : {[_unit] execVM 'Terrorists\initUnit_MILITARY.sqf';};
	case "POLICE" : {[_unit] execVM 'Terrorists\initUnit_POLICE.sqf';};
};

The GEAR_TO_SL.sqf  script is executed by the server but the script itself checks for player. 

Share this post


Link to post
Share on other sites

They are called (currently) in the init line of the soldier

null = [this, "MILITARY"] execVM 'Terrorists\initUnit.sqf';

So should i change GEAR_TO_SL or should i change the other scripts?
 
EDIT:
I have made a trigger that launches the script now and change all the scripts so it uses:

waitUntil {!isNull player};

This resulted in the uniform to be changed but no other stuff in the GEAR_TO_SL.sqf was touched meaning that no equipment except for the uniform is changed.
 
EDIT2:
I have had a little bit of a progress using the trigger script activation:

waitUntil {!isNull player};
_unit = _this select 0;

removeAllWeapons _unit;
removeAllItems _unit;
removeAllAssignedItems _unit;
removeUniform _unit;
removeVest _unit;
removeBackpackGlobal _unit;
removeHeadgear _unit;
removeGoggles _unit;

_unit addHeadgear "H_HelmetB";
_unit addGoggles "rhs_googles_clear";

_unit forceAddUniform "U_B_CTRG_1";
_unit setObjectTextureGlobal [0, "Terrorists\data\uniform\CAV_U_TerrorUniform1_TO.paa"]; 

    _unit addItemToUniform "ACE_MapTools";
    _unit addItemToUniform "ACE_EarPlugs";
    _unit addItemToUniform "ACE_Morphine";
    {_unit addItemToUniform "ACE_CableTie"} foreach [1];
    {_unit addItem "ACE_fieldDressing"} foreach [1,2];
    {_unit addMagazineGlobal "Chemlight_red"} foreach [1,2];
    {_unit addMagazineGlobal "Chemlight_green"} foreach [1,2];
    
_unit addVest "V_PlateCarrier1_blk";
    _unit addItemToVest "SmokeShell";
    _unit addItemToVest "SmokeShellGreen";
    {_unit addMagazineGlobal "20Rnd_762x51_Mag"} foreach [1,2,3,4,5,6,7,8];
    {_unit addMagazineGlobal "rhs_mag_9x19_17"} foreach [1,2];
    {_unit addMagazineGlobal "HandGrenade"} foreach [1,2];

    
_unit addWeaponGlobal "srifle_DMR_03_F";
_unit addPrimaryWeaponItem "optic_ACO_grn";
_unit addPrimaryWeaponItem "acc_pointer_IR";

_unit addWeaponGlobal "rhs_weap_pya";

_unit linkItem "ItemMap";
_unit linkItem "ItemCompass";
_unit linkItem "ItemWatch";
_unit linkItem "tf_anprc154";
_unit linkItem "ItemAndroid";
_unit linkItem "rhsusf_ANPVS_14";

The thing not being changed now is the weapons. They are note removed and they are not added. :(

EDIT3:

And now im totaly stuck on the weapon change part :/

 

This is the trigger onact i currently use:

{_handle = [_x, "MILITARY"] execVM 'Terrorists\initUnit.sqf';} foreach thislist

Share this post


Link to post
Share on other sites

The weapon switches and switches back to there default one :/

// null = [this] execVM "Terrorists\Units\CAV_TO_R.sqf";

waitUntil {!isNull player};
_unit = _this select 0;

removeAllWeapons _unit;
removeAllItems _unit;
removeAllAssignedItems _unit;
removeUniform _unit;
removeVest _unit;
removeBackpackGlobal _unit;
removeHeadgear _unit;
removeGoggles _unit;

_unit addHeadgear "H_HelmetB";
_unit addGoggles "rhs_googles_clear";

_unit forceAddUniform "U_B_CTRG_1";
_unit setObjectTextureGlobal [0, "Terrorists\data\uniform\CAV_U_TerrorUniform1_TO.paa"];
    _unit addItemToUniform "ACE_MapTools";
    _unit addItemToUniform "ACE_EarPlugs";
    _unit addItemToUniform "ACE_Morphine";
    {_unit addItemToUniform "ACE_CableTie"} foreach [1];
    {_unit addItem "ACE_fieldDressing"} foreach [1,2];
    {_unit addMagazineGlobal "Chemlight_red"} foreach [1,2];
    {_unit addMagazineGlobal "Chemlight_green"} foreach [1,2];
    
_unit addVest "V_PlateCarrier1_blk";
    _unit addItemToVest "SmokeShell";
    _unit addItemToVest "SmokeShellGreen";
    //{_unit addMagazineGlobal "20Rnd_762x51_Mag"} foreach [1,2,3,4,5,6,7,8];
    {_unit addMagazineGlobal "rhs_mag_9x19_17"} foreach [1,2];
    {_unit addMagazineGlobal "HandGrenade"} foreach [1,2];
    
//_unit addWeaponGlobal "srifle_DMR_03_F";
[_unit, "srifle_DMR_03_F", 1, "20Rnd_762x51_Mag"] call BIS_fnc_addWeapon;
_unit addPrimaryWeaponItem "optic_ACO_grn";
_unit addPrimaryWeaponItem "acc_pointer_IR";

_unit addWeaponGlobal "rhs_weap_pya";

_unit linkItem "ItemMap";
_unit linkItem "ItemCompass";
_unit linkItem "ItemWatch";
_unit linkItem "tf_anprc154";
_unit linkItem "ItemAndroid";
_unit linkItem "rhsusf_ANPVS_14";

Share this post


Link to post
Share on other sites

Try replace this 

null = [this, "MILITARY"] execVM 'Terrorists\initUnit.sqf';

with 
 

0 = [this, "MILITARY"] call compilefinal preprocessfilelinenumbers 'Terrorists\initUnit.sqf';

execvm shouldnt be used in unit init since it runs script throught scheduler.

 

Also replace 

waitUntil {!isNull player};

in loadout file with 

if (!local(_this select 0)) exitwith {};

Or you will have problems in multiplayer. And loadout script should not have any sleeps and waituntils 

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×