Jump to content
thy_

How to make my playable area lighter for server?

Recommended Posts

Hey,

 

I help some help to improve this:

 

The script does: for dedicated and hosted servers, a multiplayer playable area control based on a trigger area (with Y, X, Z) dropped through Eden Editor, where, if some player leaves that area, that specific player is punished immediately and, if there is a vehicle with them, the vehicle must be destroyed too.

 

Improvement desired: as the script is loaded by description.ext | cfgFunctions and the script checks all players alive (they are able to respawn) as long the match goes, the desire is to improve those lines, remembering my dedicated server runs, sometimes, til 30 players. 
Ps.: for now, the target is just human players, not considering AI units out there.

 

image.png

 

Here we go:

 

 

fn_PAC_init.sqf:

if (!isServer) exitWith {};

private ["_playersAlive", "_isPlayableArea"];

[] spawn 
{
	while { true } do 
	{
		_playersAlive = (allPlayers - (entities "HeadlessClient_F")) select {alive _x};
		
		{ // forEach
			_isPlayableArea = _x inArea PAC_playableAreaControl;  // Eden trigger
			
			if !(_isPlayableArea) then
			{
				[_x, 1] call THY_PAC_fnc_setDamage;
			};
		
		} forEach _playersAlive;
		sleep 5;
	};
};

 

fn_PAC_globalFunctions.sqf:

THY_PAC_fnc_setDamage = 
{
	params ["_target", "_damage"];
	
	["You left the playable zone!"] remoteExec ["systemChat", _target];
	sleep 0.1;
	if !(isNull objectParent _target) then  // checking if the player is in vehicle
	{
		vehicle _target setDamage [_damage, false];
	};
	_target setDamage _damage;
};

 

On Eden Editor:

Dropped a trigger and name it as "PAC_playableAreaControl".

 

 

Share your thoughts, it will be very much appreciated. 

 

thy

 

Share this post


Link to post
Share on other sites

I think this would work (untested).

You are currently checking on each player if all other players are alive when you can just check locally for that said player.

 

onPlayerRespawn.sqf

params ["_newUnit", "_oldUnit", "_respawn", "_respawnDelay"];
while {alive _newUnit} do{
	sleep 5;
	if !(_newUnit inArea PAC_playableAreaControl) then{
		systemChat "You left the playable zone!";
		sleep 0.1;
		_newUnit setDamage [1, false];
		if !(isNull objectParent _newUnit) then{  // checking if the player is in vehicle
			(vehicle _newUnit) setDamage [1, false];
		};    
	};
};
  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

I totally agree. Its not neccessary to do this server side. Also to break the loop on death and to restart it on respawn is a smart solution which avoids a dirty infinite loop.

  • Thanks 1

Share this post


Link to post
Share on other sites

RCA3's solution means players are respawning at start. If not, think about initPlayerLocal.sqf then onPlayerRespawn.sqf or respawn EHs.

  • Like 1
  • Thanks 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

×