Jump to content
Sign in to follow this  
spetsnazcu

INIT.sqf to start more than 1 thing

Recommended Posts

The mission is a multiplayer for 8 players, 4 bluefor and 4 opfor.

I would like all 8 playable units to be able to access the briefing, and when respawn, to keep their ammo.

Okay, so aparently, the INIT is only starting the first command it is given and not the ones after it.

So in my example its not starting the briefing, unless if I put it before the other code for retaining weapons. But then if I do put the briefing first, the code for retaining weapons won't work...arg...

Can someone check it for me please? Thanks for your assistance advanced.

Here's the code in my init.sqf

while {true} do {

waitUntil {!(alive player)};

// Save the weapon config of the player when he die.

PlayerWeapons = weapons player;
PlayerMagazines = magazines player;

waitUntil {alive player};

// Give back the weapons the player had when he died.

removeAllWeapons player;

{player addMagazine _x;} forEach PlayerMagazines;

{player addWeapon _x;} forEach PlayerWeapons;

player selectweapon (primaryWeapon player);

};
};
};
};

////
execVM "briefing.sqf";
};
};
};

///


waitUntil {!isNil {BIS_ACM getVariable "initDone"}};
waitUntil {BIS_ACM getVariable "initDone"};
[1, BIS_ACM] call BIS_ACM_setIntensityFunc;

//////

waitUntil {!isNil {BIS_ACM1 getVariable "initDone"}};
waitUntil {BIS_ACM1 getVariable "initDone"};
[1, BIS_ACM1] call BIS_ACM_setIntensityFunc;

//////

waitUntil {!isNil {BIS_ACM2 getVariable "initDone"}};
waitUntil {BIS_ACM2 getVariable "initDone"};
[1, BIS_ACM2] call BIS_ACM_setIntensityFunc;

//////

waitUntil {!isNil {BIS_ACM3 getVariable "initDone"}};
waitUntil {BIS_ACM3 getVariable "initDone"};
[1, BIS_ACM3] call BIS_ACM_setIntensityFunc;

//////

waitUntil {!isNil {BIS_ACMcdf getVariable "initDone"}};
waitUntil {BIS_ACMcdf getVariable "initDone"};
[1, BIS_ACMcdf] call BIS_ACM_setIntensityFunc;
[bIS_ACM, 300, 500] call BIS_ACM_setSpawnDistanceFunc;

Edited by spetsnazcu
clarify things

Share this post


Link to post
Share on other sites

How should it start the briefing script if it is waiting forever for the player to die?

And where do all those }; come from?

Share this post


Link to post
Share on other sites
How should it start the briefing script if it is waiting forever for the player to die?

And where do all those }; come from?

lol funny that you pointed that out, and you're right, however, when i switch it around the other thing doesnt start.

Share this post


Link to post
Share on other sites

Never ever use the init.sqf for such things. Create a separate script which you may launch from the init.sqf.

The init.sqf is meant to set variables, start scripts and other init things (therefor init.sqf) that has to be done right at start. But as soon something needs to be looped, make an exclusive script for that and don't do it in init.sqf.

Share this post


Link to post
Share on other sites

init.sqf

execVM "briefing.sqf";

[] spawn {
waitUntil {!isNil {BIS_ACM getVariable "initDone"}};
waitUntil {BIS_ACM getVariable "initDone"};
[1, BIS_ACM] call BIS_ACM_setIntensityFunc;

waitUntil {!isNil {BIS_ACM1 getVariable "initDone"}};
waitUntil {BIS_ACM1 getVariable "initDone"};
[1, BIS_ACM1] call BIS_ACM_setIntensityFunc;

waitUntil {!isNil {BIS_ACM2 getVariable "initDone"}};
waitUntil {BIS_ACM2 getVariable "initDone"};
[1, BIS_ACM2] call BIS_ACM_setIntensityFunc;

waitUntil {!isNil {BIS_ACM3 getVariable "initDone"}};
waitUntil {BIS_ACM3 getVariable "initDone"};
[1, BIS_ACM3] call BIS_ACM_setIntensityFunc;

waitUntil {!isNil {BIS_ACMcdf getVariable "initDone"}};
waitUntil {BIS_ACMcdf getVariable "initDone"};
[1, BIS_ACMcdf] call BIS_ACM_setIntensityFunc;

[bIS_ACM, 300, 500] call BIS_ACM_setSpawnDistanceFunc;
};

player addEventHandler ["killed", {_this execVM "resLoadout.sqf"}];

spawn is not necessary, but can be used it it takes too long for ACM modules to initialize

resLoadout.sqf

_unit = _this select 0;
if(player == _unit) then {
SPZ_PlayerWeapons = weapons player;
SPZ_PlayerMagazines = magazines player;
//removeAllWeapons player; //possibly remove weapons from dead body?

waitUntil {alive player};

// Give back the weapons the player had when he died.

removeAllWeapons player;

{player addMagazine _x;} forEach PlayerMagazines;

{player addWeapon _x;} forEach PlayerWeapons;

if (primaryWeapon player != "") then {
	player selectWeapon (primaryWeapon player);
	_muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles"); // Fix for weapons with grenade launcher
	player selectWeapon (_muzzles select 0);
};
};

Share this post


Link to post
Share on other sites

okay, it all works great, however, only for the unit set as PLAYER, when i test it as another PLAYABLE unit, it doesn't work

Share this post


Link to post
Share on other sites

No, not really. I didn't name the unit "player". I had a feeling with that code that it was required.

The mission is a multiplayer for 8 players, 4 bluefor and 4 opfor.

I would like all 8 playable units to be able to access the briefing, and when respawn, to keep their ammo.

thanks for you patience guys lol

Share this post


Link to post
Share on other sites

I assume you mean that you are using group respawn.

waitUntil{alive player};

{_x addEventHandler ["killed", {_this execVM "resLoadout.sqf"}];} forEach units group player;

If not, then there is no reason that the script should not work in MP games.

< player > is local to each person's computer that joins and executes the code the same as the first player.

How did you test it?

Share this post


Link to post
Share on other sites

Yea it makes sence what you said.

So I've rethought and redone the whole thing and now it works.

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  

×