Jump to content

coalition.getPlayers(coalition.side.BLUE) MultiPlayer?


Recommended Posts

Posted

I admit I have not been in .lua for a while. It seems local coalition.getPlayers(coalition.side.BLUE) works fine but online it does not work. (I know there are issues with groups)

How do scripters get player information for online use?

 

my script for reference:

--check for new players and add to table playerTbl
function newPlayers()
local _clients = coalition.getPlayers(coalition.side.BLUE) --find all player

for i = #_clients, 1, -1 do
	local _clientId = _clients[i]:getID()
	local _clientGroupId = Group.getID(Unit.getGroup(_clients[i]))
	if _clientGroupId == nil then
		_clientGroupId = _clientId
	end
	local _plrName = Unit.getPlayerName(_clients[i])
	local _clientUnitName = _clients[i]:getName()
	local _clientType = _clients[i]:getTypeName()
	local _clientUnknown = true
	local _clientCommMenu = true
		
	if _plrName ~= nil  then
		if #playerTbl ~= 0 then
			for i = #playerTbl, 1, -1 do
				if _plrName == playerTbl[i].playerName then --player is in the table
					_clientUnknown = false
					_clientCommMenu = false
					if _clientGroupId ~= playerTbl[i].playerGroupId then --player changed aircraft
						_clientCommMenu = true
						playerTbl[i].playerId = _clientId
						playerTbl[i].playerGroupId = _clientGroupId
						playerTbl[i].playerUnitName = _clientUnitName
						playerTbl[i].playerType = _clientType
						--playerTbl[i].playerPickup = 0
						--playerTbl[i].playerPassengerCount = 0
						--playerTbl[i].playerGroupFlight = 0
						
					end
				end
			end
		end
			
		if _clientUnknown then
			playerTbl[#playerTbl + 1] = {
			playerId = _clientId,
			playerGroupId = _clientGroupId,
			playerName = _plrName,
			playerUnitName = _clientUnitName,
			playerType = _clientType,
			playerPickup = 0,
			playerPassengerCount = 0,
			playerPoints = 0,
			playerGroupFlight = 0}
		end
		
		if _clientCommMenu then
			missionCommands.removeItemForGroup(_clientGroupId, nil)
			local _pilotData = {_plrName, _clientGroupId, _clientType}
			timer.scheduleFunction(syncPilot, _pilotData, timer.getTime() + 3)
		end
	else
		trigger.action.outTextForGroup(_clientGroupId, string.format("You need a player name. Please change it or you will not takoff."), 30)
		_clients[i]:destroy()
	end
end

timer.scheduleFunction(newPlayers, nil, timer.getTime() + 5)
end

 

 

Many thanks for any help.

 

 

 

:huh:

Posted (edited)

Have a look at the scoring class in moose...

 

Also, I see you do a call Unit.getPlayerName(_Clients), which to me seems to be wrong. I assume _Clients containing an array. But getPlayerName only works with one unit.

 

 

 

A valid statement would be:

 

ClientUnit:getPlayerName()...

 

 

 

Typed on my mobile...

Edited by FlightControl

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

Posted (edited)

If I quickly try to traceback what you did in moose (and got befuddled). Did you collect initial data of the player with S_EVENT_BIRTH? Because that does not seem to work on my side and is the reason of the workaround above.

 

And _clients works fine.

 

 

EDIT: It worked fine I fumbled with saving .miz file ...

Edited by piXel496
Posted
If I quickly try to traceback what you did in moose (and got befuddled). Did you collect initial data of the player with S_EVENT_BIRTH? Because that does not seem to work on my side and is the reason of the workaround above.

 

 

 

And _clients works fine.

 

 

 

 

 

EDIT: It worked fine I fumbled with saving .miz file ...

 

Yes. I collect at event birth and build a player database...

 

Sent from mTalk on Windows 10 mobile

[TABLE][sIGPIC][/sIGPIC]|

[/TABLE]

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...