Jump to content
Walt73

How to send hints to randomly selected players?

Recommended Posts

Hey, sorry, I'm pretty new to designing missions, so I'm not great at scripting. I'd like to make it so that, on a multiplayer server, with 5-20 players, it randomly picks one or two. The idea would be that it would flash a message on their screen, and theirs only, so that no one who is NOT picked would know about it. Does anyone know what code I should fuck with to do this? I already know how to make it output messages via Hints, I just need to know how to make it randomly pick that one or two players to do it to, without anyone else (including the host, if possible) knowing who was picked.

Share this post


Link to post
Share on other sites

You'd probably be best running this from the server, so depends on where/when you're running the script, but you just need to get a list of the players then pick two of them and send the message to them:

if (isServer) then {
 _players = call BIS_fnc_listPlayers;
 _message = "your message";
 for "_i" from 1 to 2 do {
  _player = _players deleteAt (round (random (count _players)));
  [_message] remoteExec ["hint",_player];
 };
};

Pretty quick example, but something like that should work.

  • Like 3

Share this post


Link to post
Share on other sites

Sorry to hijack this thread. But I am wondering about another use case for that random player selection. 

In my particular problem, I want to randomly select two players as hostages in a mission. The hostages have a different starting location and equipment (eg no map). They should get a different briefing, which means that the function should execute before mission start. Server is dedicated. I guess my question is two parted-

A) Would the function/script fire at the right moment if set up like this in description.ext:

class CfgFunctions 
{
	class MeM
	{
        class MyCategory 
		{
			file = "functions";
			class randomhostage {};
			preInit = 1; // or postInit ?
		};
	};
};

And run in the initserver.sqf?

 

B) Does the- 

On 2/24/2021 at 12:40 AM, beno_83au said:

_player = _players deleteAt (round (random (count _players)));

Line always select 2 unique players (does _players array update between loops)?

Share this post


Link to post
Share on other sites
8 minutes ago, Melody_Mike said:

B) Does the- 

Line always select 2 unique players (does _players array update between loops)?

 

It only selects one player from the array, so needs to be run through the from....to loop twice to get two results. The handy thing about deleteAt is that it not only removes the element at the given index, it also returns the removed element - https://community.bistudio.com/wiki/deleteAt - so you don't need to manage any of that yourself. 

Share this post


Link to post
Share on other sites

Yeah, I read the BIKI. But wasn't sure if this example applied when run in your "for" loop:

// first iteration, i=1

_arr = [1,2,3]; 
_rem = _arr deleteAt 1; 
hint str [_rem, _arr]; //[2,[1,3]]

 

// second iteration, i=2

_arr = [1,3];
_rem = _arr deleteAt 1;
hint str [_rem, _arr]; //[3,[1]]

Or whether it would keep the original _arr for both iterations. But I understand it's the above. Thanks!
 

  • 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

×