Jump to content
Sign in to follow this  
SeelieKnight

Multiplayer While Loop on Players

Recommended Posts

I'm trying to spawn a while loop on each player in a multiplayer mission to monitor what equipment they have but can't figure out how this works. Right now I'm just trying to hint the name of units' helmets.

In initPlayerLocal.sqf:

[[player], "player_scripts\01_integrated_armor.sqf"] remoteExec ["BIS_fnc_execVM", 0, true];


The code in 01_integrated_armor.sqf:

_rc = _this select 0;

[_rc] spawn
{
	_rc = _this select 0;
	while {true} do
	{
		//%1 = name of unit
		//%2 = helmet unit is wearing
		//%3 = check if helmet matches unit's helmet variable
		hint format ["%1,\n%2,\n%3", _rc, headgear _rc, (headgear _rc == _rc getVariable "rc_helmet")];
		sleep 1;
	};
};


The hint is coming through, and seems like it should be working, but the part that shows which helmet the unit is wearing won't change when I swap helmets. I checked the helmet with the debug console (i.e. "headgear player") and that shows the currently worn helmet properly, and the variable name of the player is displaying correctly in the hint, so I'm not sure why this is not working. What am I missing?

Share this post


Link to post
Share on other sites

Why not have initPlayerLocal execVM the script?

The remotExec and BIS_fnc_ExecVM seem unnecessary, and the remotExec 0 seems like it would be the issue.

Share this post


Link to post
Share on other sites
16 minutes ago, opusfmspol said:

Why not have initPlayerLocal execVM the script?

The remotExec and BIS_fnc_ExecVM seem unnecessary, and the remotExec 0 seems like it would be the issue.


That's how I had it set up at first. When I was using execVM, it seemed like the scripts weren't firing at all, but it's been a little while so I can't remember perfectly. 

I do think I figured it out though. Looks like the issue was something to do with respawn. I had respawn at start, and it seems like the script continues after that, but no longer points to the same entity. The fix was to make sure that the spawned loop terminates when the player is no longer alive, then copy the code from initPlayerLocal.sqf into onPlayerRespawn.sqf.

Share this post


Link to post
Share on other sites
3 hours ago, SeelieKnight said:

it seems like the script continues after that, but no longer points to the same entity

That would be correct, player object changes to a different object on respawn.

 

No need to copy it over, the loop continues until player disconnects.

 

Just use Player command (or update the player object "_rc" each loop), and use condition that player is Alive for the info to update.

While {true} do 
{
	if (Alive Player) then 
	{
		hint . . . .
	};

	Sleep 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  

×