Jump to content
fin_soldier

More players, More enemies

Recommended Posts

Hello,

 

I'm working on a 4 player coop, in which there should be more enemies depending on the amount of players.

 

Let's say for example that there's a enemy group of four, and one enemy for each 4 players.

So if there's only one player there's only one enemy in that group.

 

I tried to do something with condition of presence, but without success.

In init I executed "player1 = true" if player 1 exists, then I put in the condition of presence of the enemy "player1". Then that enemy should exist right?

 

I'm not sure if this is the right way to do this. If someone could enlighten me, I'd be very happy.

Thanks in advance!

Share this post


Link to post
Share on other sites

Hmm

Maybe try:

waitUntil { !(isNull player1) };

  • Thanks 1

Share this post


Link to post
Share on other sites

First of all, if you intend to use a waitUntil loop, I strongly suggest adding a sleep command in it to save some CPU usage. This would look like

waitUntil {
	sleep 2; // Wait 2 seconds before checking again
	!(isNull player); // Check if player exists
};

 

  • Thanks 1

Share this post


Link to post
Share on other sites
5 hours ago, Alert23 said:

Hmm

Maybe try:

waitUntil { !(isNull player1) };

 

33 minutes ago, ZaellixA said:

First of all, if you intend to use a waitUntil loop, I strongly suggest adding a sleep command in it to save some CPU usage. This would look like


waitUntil {
	sleep 2; // Wait 2 seconds before checking again
	!(isNull player); // Check if player exists
};

  

 

Both of these just say "Error Invalid number in expression" in the unit's condition of presence.

Share this post


Link to post
Share on other sites

On dedicated, player doesn't mean anything.

If you want to wait for a specific player, just use the condition:  isPlayer player1

 

 

  • Like 2

Share this post


Link to post
Share on other sites
20 minutes ago, Casio91Fin said:

Luotko vihollisen scriptinä?

 

 

En luo scriptinä, ihan perus unit placement.

Share this post


Link to post
Share on other sites

Some form of...? ( place down enemy groups as need for max players )

Spoiler

//initServer.sqf

//Wait for the mission to start
waitUntil{ time > 0 };

//Mission max player count
_maxPlayerCount = 4; //<-- Change to max player count for your mission

//Get the ratio of players to max players
_playerCountRatio = count ( allPlayers - entities "HeadlessClient_F" ) / _maxPlayerCount;

//For all groups
{
	//If the side of the group is enemy( change east to your liking ) 
	if ( side _x isEqualTo east ) then {
		
		//Get the group size minus group size times max players ratio
		_numUnitsToRemove = count units _x - floor(( count units _x ) * _playerCountRatio );
		
		//Get the units in the group( minus the leader )
		_units = units _x - [ leader _x ];
		
		//Reverse them so we remove them from the back of the formation
		reverse _units;
		
		//Select units to remove 
		_units = _units select[ 0, _numUnitsToRemove ];
				
		//Delete the units
		{
			deleteVehicle _x;
		}forEach _units;
	};
}forEach allGroups; //<-- Could change this to be more specific if needed

So if there are 4 players divided by max players = 1, no units will be deleted.

if there are 2 players divided by max players = 0.5, half of the units in each group will be deleted

if there are 3 players divided by max players = 0.75, a quarter of the units in each group will be deleted

etc

Think that works out right math wise.

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

@fin_soldier , I've made a balancing mod (in beta ATM). Because I play with a closed small group (8 members max), I have the same issue. My approach was this (before converting the code into a module):

  • Sync AI groups to be balanced to an empty logic object.
  • Used a function that has these parameters: the logic, minimum players, maximum players, delta, timeout.
    • the logic: as explained above
    • minimum players: if player count goes below this value, remove "delta" units from synced groups.
    • maximum players: if player count goes above this value, add "delta" units to synced groups.
    • delta: the amount of units to be added or subtracted when balancing.
    • timeout: number of seconds to wait until balancing.
  • The function must run server side only.

The logic init code is something like this: 

[this, 4, 6, 1, 300] call GLMFW_fnc_globalBalance;

I'm sorry that i cannot share code right now (I don't have access to my terminal ATM). 

Basically, I've got this scenario:

  1. After some time, the script will kick in and balance AI's based on players connected at that moment.
  2. If we are between min and max threshold, nothing happens.
  3. If we are below min, each synced group gets "delta" units deleted at random (if delta is 1, one unit is deleted per missing player).
  4. If we are above max, each synced group gets "delta" added units (duplicating one random group member).

I hope this gives you an approach to make your balancing script. As soon as I get home, I will share my code with you.

 

Take care and good luck.

(Please excuse my english)

 

  • Like 2

Share this post


Link to post
Share on other sites

@fin_soldier as promised: download this mod and give it a try (Systems -> GravisLudum Mission Framework -> Dynamic Balance). If you want to go deeper, decompile GL_DynamicBalance.pbo ; then take a look at fn_globalBalance.sqf and fn_adjustGroup.sqf

 

I've made the english translation (Spanish & English atm).

 

We don't have a public Git yet, but feel free to use, modify & adapt it as you see fit (we have a Creative Commons licence CC BY-NC-SA 4.0, https://creativecommons.org/licenses/by-nc-sa/4.0).

 

Good luck and happy coding!

 

  • 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

×