Jump to content
Sign in to follow this  
Shako

Listing All Players in a Map

Recommended Posts

I know it's possible, but I can't recall how to do it.

 

When in a maze, instead of saying "There are currently X players in MAP", it says "There are currently X Players in a MAP: Name1, Name2, Name3, Name4" etc.

 

Does anyone know?


logo-big.png   logo.png

                                   Sunny Go! Online                                                                    pko.host                                                 

Share this post


Link to post
Share on other sites

If you look in CA ctrl.lua at the function that is called when map is closing, there is a function DealAllActiveInMap(map,func). Make you can add something like this before announcing players: 

function GetPlayerNames (role)
	table. insert(PlayersInMap,GetChaDefaultName(role))
end

--
	PlayersInMap = {}
	DealAllActiveInMap (map,'GetPlayerNames')
	local ListPlayers = ''
	for i,v in pairs(PlayersInMap) do
		ListPlayers = string.format('%s [%s],',ListPlayers,v)
	end
	local msg = string.format('MAPNAME has [%s] players remaining: %s' , GetMapActivePlayer(map) , ListPlayers)
	Notice(msg)
--

 

 

Share this post


Link to post
Share on other sites

Hello @Shako

 

You can use GetMapCopyNextPlayerCha(map_copy) function

for example

function GetPlayerList(map)

	local players = {}
	local ply_num = GetMapCopyPlayerNum(map) 
	
	BeginGetMapCopyPlayerCha(map)
	
	for i = 0, ply_num - 1, 1 do
		
		local player = GetMapCopyNextPlayerCha(map)
		if (ValidCha(player) == 1) then
			players[i] = player
		end
		
	end
	
	return players

end	

 

  • Like 1

Share this post


Link to post
Share on other sites
On 8/12/2016 at 11:03 PM, 7n6 said:

If you look in CA ctrl.lua at the function that is called when map is closing, there is a function DealAllActiveInMap(map,func). Make you can add something like this before announcing players: 


function GetPlayerNames (role)
	table. insert(PlayersInMap,GetChaDefaultName(role))
end

--
	PlayersInMap = {}
	DealAllActiveInMap (map,'GetPlayerNames')
	local ListPlayers = ''
	for i,v in pairs(PlayersInMap) do
		ListPlayers = string.format('%s [%s],',ListPlayers,v)
	end
	local msg = string.format('MAPNAME has [%s] players remaining: %s' , GetMapActivePlayer(map) , ListPlayers)
	Notice(msg)
--

 

 

 

Nice script! Thank you! I was able to combine this script with another function on my other thread in order to create something that calls the remaining players and names every 5 seconds in the map.

 

Your script had some wrong function names in them so I fixed them for you.

 

This is my script that I made for Chaos Argent:

 

Chaos_Argent_Tick = 0

function GetPlayerNames (role)

	table.insert ( PlayersInMap , GetChaDefaultName ( role ) )

end



function map_copy_run_garner2 ( map_copy )

	local Map_Description = "Chaos Argent"

			Chaos_Argent_Tick = Chaos_Argent_Tick + 1

			PlayersInMap = {}
			DealAllActivePlayerInMap ( map_copy , 'GetPlayerNames' )

	local ListPlayers = ''

		for i,v in pairs ( PlayersInMap ) do

			ListPlayers = string.format( '%s [%s],' , ListPlayers , v )

		end

		if math.mod ( Chaos_Argent_Tick, 5 ) == 0 then
	
			local msg = string.format( "["..Map_Description.."] has [%s] players remaining:%s" , GetMapActivePlayer ( map_copy ) , ListPlayers )
			Notice ( msg )

		end

end

 

Works Perfectly! Credits of help to: @V3ct0r & @7n6

cap00000.png

Edited by Shako

logo-big.png   logo.png

                                   Sunny Go! Online                                                                    pko.host                                                 

Share this post


Link to post
Share on other sites

@7n6 on the end of the announcement though, it will have a comma "," that doesn't belong xD is there way to remove it?


logo-big.png   logo.png

                                   Sunny Go! Online                                                                    pko.host                                                 

Share this post


Link to post
Share on other sites
4 hours ago, V3ct0r said:

Hello @Shako

 

You can use GetMapCopyNextPlayerCha(map_copy) function

for example


function GetPlayerList(map)

	local players = {}
	local ply_num = GetMapCopyPlayerNum(map) 
	
	BeginGetMapCopyPlayerCha(map)
	
	for i = 0, ply_num - 1, 1 do
		
		local player = GetMapCopyNextPlayerCha(map)
		if (ValidCha(player) == 1) then
			players[i] = player
		end
		
	end
	
	return players

end	

 

 

I don't quite know how to put this into use @V3ct0r! Could you help out?

When returned "players", how do I announce them?

THX!


logo-big.png   logo.png

                                   Sunny Go! Online                                                                    pko.host                                                 

Share this post


Link to post
Share on other sites

@Shako

try put 

ListPlayers = string.sub(ListPlayers, 1, string.len(ListPlayers) - 1)

after for in pairs loop. It should delete last comma from string.

 

Also you can use my method

function map_copy_run_garner2 ( map_copy )

	Chaos_Argent_Tick = Chaos_Argent_Tick + 1

	if (math.mod(Chaos_Argent_Tick, 5) == 0) then
		
		local players = ''
		local ply_num = GetMapCopyPlayerNum(map_copy) 
		
		BeginGetMapCopyPlayerCha(map_copy)
		
		for i = 0, ply_num - 1, 1 do
			
			local player = GetMapCopyNextPlayerCha(map_copy)
			if (ValidCha(player) == 1 and Hp(player) > 0) then
				
				players = string.format('%s [%s]', players, GetChaDefaultName(player))
				if (i < ply_num - 2) then
					players = string.format('%s, ', players)
				end
				
			end
			
		end

		local msg = string.format( "[Chaos Argent] has [%s] players remaining: %s" , GetMapActivePlayer(map_copy), players)
		Notice(msg)

	end

end

but I didn't test it


Share this post


Link to post
Share on other sites

@V3ct0r I don't have time to test it right now, but looking at the script it should do the same exact thing! :)

thanks both of you for helping with the script.


logo-big.png   logo.png

                                   Sunny Go! Online                                                                    pko.host                                                 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...