Jump to content
Gamer-3ac24a5e7f4beb96

How to call another sqf in the init server sqf

Recommended Posts

I have an initServer sqf counting enemy kills. I would like call a separate sqf that plays a sound each time an enemy is killed. How do I correctly format the call to the sound sqf in my code shown here:

 

if (isServer) then {

    _enemies = allUnits select {!isPlayer _x && side _x == WEST};
    political_will = 100;

(format ["British Political Will: %1", political_will]) remoteExec ["hint",0,false];
    _onKilled = {
        political_will = political_will - 1;
        
        (format ["British Political Will: %1-", political_will]) remoteExec ["hint",0,false];
        
    };
    
    {_x addEventhandler ["killed",_onKilled]; false} count _enemies;
};

my sound playing sqf is called killsounds.sqf
Do I just need a line of code in the _onKilled brackets?

Share this post


Link to post
Share on other sites

Why call another script? Just add your code to the EH.

if (isServer) then {
	_enemies = allUnits select {!isPlayer _x && side _x == WEST};
	political_will = 100;
	(format ["British Political Will: %1", political_will]) remoteExec ["hint",0,false];
	_onKilled = {
		params ["_unit", "_killer", "_instigator", "_useEffects"];
		political_will = political_will - 1;
		(format ["British Political Will: %1-", political_will]) remoteExec ["hint",0,false];
		//  E.G. -- [_unit, "deathSound"] remoteExec [say3D, 0, false];
	};
	{_x addEventhandler ["killed",_onKilled]; false} count _enemies;
};

 

It's actually the recommended practice, from remoteExec:

Quote

The direct execution of call or spawn via remoteExec (or remoteExecCall) should be avoided to prevent issues in cases where the remote execution of call or spawn is blocked by CfgRemoteExec. It is instead recommended to create a function to be itself remote-executed.

 

Though it should be fine to remoteExec an execVM.

  • Like 2

Share this post


Link to post
Share on other sites

Remarks:

1- it's useless specifying : if (isServer) then {...};    in initServer.sqf !

 

2- applying the "killed" EH on each enemy like this, means you set enemies in stone: enemies are edited one, not spawned if any. Use (same way, in init.sqf) the MEH "entityKilled"  instead.

 

3- if two or more played sides, then different enemies, just add conditions and variables if needed.

example, in initServer.sqf:

WESTpolitical_will = 100;
INDEPpolitical_will = 100;
 
addMissionEventHandler ["entityKilled", {
 params ["_unit", "_killer", "_instigator", "_useEffects"];
 if (isNull _instigator) then {_instigator = UAVControl vehicle _killer select 0};  // instigator is more effective than killer
 if (isNull _instigator) then {_instigator = _killer};
  if (isPlayer _instigator && side group _unit in (_instigator call BIS_fnc_enemySides)) then {  // count only players' kills but you can remove the isPlayer condition
   call {
    if (side _instigator == INDEPENDENT) exitWith {
     INDEPpolitical_will = INDEPpolitical_will -1;
     (format ["INDEP Political Will: %1", INDEPpolitical_will]) remoteExec ["hint",INDEPENDENT]; // just hint for concerned players
    };
     if (side _instigator == WEST) exitWith {
      WESTpolitical_will = WESTpolitical_will -1;
      (format ["WEST Political Will: %1", WESTpolitical_will]) remoteExec ["hint",WEST]  // same
     };
   };
  };
}];

 

  • Like 3

Share this post


Link to post
Share on other sites

Thak you!

I have only one playable side and no spawned in enemies in the scenario.

The reason I wanted to call another sqm is that i have made one that plays one of four random sounds like this:
 

_sound = selectRandom 
  [
    "hitmetal1", // As defined by you in Description.ext
    "hitmetal2",
    "hitbody1",
    "hitbody2",
  ];

playSound _sound;

Can I put that whole chunk where you suggest I put [_unit, "deathSound"] remoteExec [say3D, 0, false];

Out of curiosity does that say 3d command make a 3d sound at the position of the player?

Share this post


Link to post
Share on other sites

There is a typo. You always need to quote command for remoteExec it.

The source of the sound is at first parameter (_unit here).

 

[_unit, "deathSound"] remoteExec ["say3D",[0,-2] select isDedicated];

  • Like 2

Share this post


Link to post
Share on other sites

Thank you pierremgi
is there a way to play the sound globally or for all of opfor? I have 8 player slots and rather than specify the sound on each enemy or each player it would be simpler to have it play for everyone any time an enemy is killed.

Share this post


Link to post
Share on other sites
3 hours ago, Gamer-3ac24a5e7f4beb96 said:

Thank you pierremgi
is there a way to play the sound globally or for all of opfor? I have 8 player slots and rather than specify the sound on each enemy or each player it would be simpler to have it play for everyone any time an enemy is killed.

Globally, that's the way I wrote (not so different from ...["say3D",0] if you read).

For EST side , as shown above ...["say3D",EAST]

Time for you to read a little bit on remoteExec before scripting at random.

But also say3D and its limitations. Not tested but not sure you don't kill the source at the same time. Test it.

  • Like 2

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

×