Jump to content
Sign in to follow this  
Bnae

Working on MP mission

Recommended Posts

This is only check who is executing the script.

 

If everyone incl. server executing a script, you can define

which part of script will be executed where.

 

i.e init.sqf

//++++execute everywhere++++//
blah blah blah
blah blah blah
//++++++++++++++++++++++//
if (isServer) then {

  //*********run on dedicated server or player host only**********//
  blah blah
 []execVM "runmeonlyonserver.sqf";

};

//++++execute everywhere++++//
blah blah blah
blah blah blah
//++++++++++++++++++++++//

if (hasInterface) then {
    //--------run on all player clients only incl. player host-------//
blah blah
 []execVM "runmeonlyonclients.sqf";
};

Share this post


Link to post
Share on other sites

 

This is only check who is executing the script.

 

If everyone incl. server executing a script, you can define

which part of script will be executed where.

 

i.e init.sqf

//++++execute everywhere++++//
blah blah blah
blah blah blah
//++++++++++++++++++++++//
if (isServer) then {

  //*********run on dedicated server or player host only**********//
  blah blah
 []execVM "runmeonlyonserver.sqf";

};

//++++execute everywhere++++//
blah blah blah
blah blah blah
//++++++++++++++++++++++//

if (hasInterface) then {
    //--------run on all player clients only incl. player host-------//
blah blah
 []execVM "runmeonlyonclients.sqf";
};

 

Thanks for clearing that for me.

Share this post


Link to post
Share on other sites
private ["_unit","_enemy"];
killCounter = 0;
publicVariable "killCounter";
updateCounter = {
 
	killCounter = killCounter +1;
 
	if(killCounter == 2) then {
		removeAllWeapons _unit;
	};
 
};
publicVariable "updateCounter";

enemyKilleder = {
 
	_enemy = _this select 0;
	_unit = _this select 1;
	
	if(_unit == player) then {
		call updateCounter;
	};
};

{
	if(side _x == EAST) then {
		_x addEventHandler ["killed", { _this call enemyKilleder } ];
	};
} foreach allUnits;
publicVariable "enemykilleder";

Cannot make it run on clients PC.

Only working for me as a host.

 

I also tried addPublicVariableEventHandler but it wasn't success

Share this post


Link to post
Share on other sites

You need to include in your post additional information about how this file is executed, from where, by who.

Until than its strangely difficult to help.

Share this post


Link to post
Share on other sites

I think you are messing in the wrong way.

 

Basics:

 

KILLED eventhandler will run only on the client where the killed unit is local,this means, when you die, the script will execute only in your pc, when your friend dies, the script will execute in your Friends pc. For "all pcs script exec" then is the MPKILLED EH.

 

So, for example if your script has something like "If _killedUnit == player" please note in a dedicted server will not work, as in a dedi, there is no player.

 

More, variables. Take in count if variables are not MP global, then that kill count will have a different value in your pc, in your Friends etc..

 

And last, as the script runs locally where the killed unit is, if you want to do something to the KILLER, it won't be local to the machine (your friends unit is local to your friends pc, not to yours) so any command like, exactly, removeAllweapons which in wiki states the unit must be local to make the command work. Is it? No. So no weapon removal. You have to execute the command with the remoteExec command or easier, execute the whole script in your friends pc no matter it's you who died (see below)

 

In few words:

 

Killed EH:

 

Script execution local to the killed unit.

Killer, if is player, will never be local.

removeAllWeapons must be remoteExe'ed to have effect on the killer, as executing on the killed PC will have no effect.

 

So, he solution for the approach you want is to use MPKilled EH. Using a simple Killed is more complicated and a mess if you are begining on the wonderful MP scripting world.

Share this post


Link to post
Share on other sites

May I ask where you initialise that script ? init.sqf, initServer.sqf or initPlayerLocal.sqf? In addition, is the killCounter variable supposed to be equal on all clients at all time ?

Share this post


Link to post
Share on other sites

May I ask where you initialise that script ? init.sqf, initServer.sqf or initPlayerLocal.sqf? In addition, is the killCounter variable supposed to be equal on all clients at all time ?

 

init.sqf

 

This is getting all too complicated mainly because of my bad English skills.

 

The basic idea is that everyone should have their own counter.

If i kill enemies = i lose my gun.

If other client kills enemies = he loses his gun.

 

I'm going to use this as "Rearm". If you get 10 kills your gear is going to update.

	if(_unit == player) then {
		call updateCounter;
	};
};

{
	if(side _x == EAST) then {
		_x addMPEventHandler ["MPkilled", { _this call enemyKilleder } ];
	};

So the if (_unit == player) needs to be changed?

 

And the remoteExec is completely new command for me.

Share this post


Link to post
Share on other sites

I'd use the MpeventHandler and in addition check if the unit local to where the eventHandler should trigger.

enemyKilleder =
{
    _enemy = _this select 0;
    _unit = _this select 1;
    
    if(isPlayer _unit && local _unit) then
    {
        call updateCounter;
    };
};

That should basically prevent the MpEventHandler from executing the script everywhere. Another thing to take in mind is Join in Progress. If you use the init.sqf, the counter will be reset everytime a new player joins.

Share this post


Link to post
Share on other sites

I'd use the MpeventHandler and in addition check if the unit local to where the eventHandler should trigger.

enemyKilleder =
{
    _enemy = _this select 0;
    _unit = _this select 1;
    
    if(isPlayer _unit && local _unit) then
    {
        call updateCounter;
    };
};

That should basically prevent the MpEventHandler from executing the script everywhere. Another thing to take in mind is Join in Progress. If you use the init.sqf, the counter will be reset everytime a new player joins.

 

Finally it's working! You're my hero!

 

Now i'm going to fix the removeAllWeapons part and it should be ready.

  • Like 1

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  

×