Jump to content
Sign in to follow this  
noanshadow

Counter Players Inside

Recommended Posts

Hello @noanshadow!

 

Add this variable to the file variable.lua:

entrydata = entrydata or {}

 

Write the following script to the file functions.lua:

SetMapEntryEventName__Original = SetMapEntryEventName
SetMapEntryEventName = function(entry, name)
	
	-- Call the original function
	SetMapEntryEventName__Original(entry, name)
	
	-- Save the portal descriptor
	map_name, posx, posy, tmap_name = GetMapEntryPosInfo(entry)
	entrydata[tmap_name] = entry

end

function SetPortalName(map, name)
	
	if ( entrydata[map] ~= nil ) then
    
		SetMapEntryEventName__Original(entrydata[map], name)
        
	end
	
end

 

Open the file ctrl.lua of the map and write some code:

function after_enter_<map_name>(role, map_copy)
	
	SetPortalName("<map_name>", string.format("%d player(s) inside", GetMapActivePlayer(map_copy)))
	
end

function before_leave_<map_name>(role)

	SetPortalName("<map_name>", string.format("%d player(s) inside", GetMapActivePlayer(GetChaMapCopу(role)) - 1))
	
end

Where <map_name> is the name of the map, for example, garner2.

 

The solution is based on @x3w0r's example from this topic:

 

Note: not tested.

  • Like 1

Share this post


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

function after_enter_<map_name>(role, map_copy)
	
	SetPortalName("<map_name>", string.format("%d player(s) inside", GetMapActivePlayer(map_copy)))
	
end

function before_leave_<map_name>(role)

	SetPortalName("<map_name>", string.format("%d player(s) inside", GetMapActivePlayer(GetChaMapCopу(role))))
	
end

 

 

this is redundant, you only need those in functions.lua
 

local entrydata = entrydata or {}

SetMapEntryEventNameHook = SetMapEntryEventName
function SetMapEntryEventName(entry, name)
	SetMapEntryEventNameHook(entry, name)
	map_name, posx, posy, tmap_name = GetMapEntryPosInfo(entry)
	entrydata[tmap_name] = entry
end

function GetEntryDataByName(map)
	return entrydata[map]
end

function SetPortalName(map, name)
	local entry = GetEntryDataByName(map)
	if entry ~= nil then
		SetMapEntryEventName(entry, name)
	end
end

and in

map_copy_run_<map_name>
    SetPortalName("puzzleworld", "Demonic World  - Survivors: " ..
                      GetMapActivePlayer(map_copy) .. "")

the most important part is the following, you collect the entry data by calling the following code inside  function after_create_entry(entry)

 SetMapEntryEventName(entry, EntryName)

"puzzle world" is just an example, replace it with ur map name,


Kind regards, AG.

Share this post


Link to post
Share on other sites
9 hours ago, J0k3r said:

this is redundant, you only need those in functions.lua

Your code will be called every second even if the number of players have not changed. My one only when the player enters or exits the map, when it is really necessary.

  • Like 1

Share this post


Link to post
Share on other sites
9 hours ago, J0k3r said:

 

this is redundant, you only need those in functions.lua
 


local entrydata = entrydata or {}

SetMapEntryEventNameHook = SetMapEntryEventName
function SetMapEntryEventName(entry, name)
	SetMapEntryEventNameHook(entry, name)
	map_name, posx, posy, tmap_name = GetMapEntryPosInfo(entry)
	entrydata[tmap_name] = entry
end

function GetEntryDataByName(map)
	return entrydata[map]
end

function SetPortalName(map, name)
	local entry = GetEntryDataByName(map)
	if entry ~= nil then
		SetMapEntryEventName(entry, name)
	end
end

and in


map_copy_run_<map_name>

    SetPortalName("puzzleworld", "Demonic World  - Survivors: " ..
                      GetMapActivePlayer(map_copy) .. "")

the most important part is the following, you collect the entry data by calling the following code inside  function after_create_entry(entry)


 SetMapEntryEventName(entry, EntryName)

"puzzle world" is just an example, replace it with ur map name,

your code bugs the server after some time . the v3ctor ones not.

Share this post


Link to post
Share on other sites
44 minutes ago, squaller said:

your code bugs the server after some time . the v3ctor ones not.

funny enough, it is the same just the function called differently.

 

 

55 minutes ago, V3ct0r said:

Your code will be called every second even if the number of players have not changed. My one only when the player enters or exits the map, when it is really necessary.

sure, except the fact that before_leave_<map_name>() won't be called on player relog/closing the game, thus the count will be stuck until another player leaves "for real".


Kind regards, AG.

Share this post


Link to post
Share on other sites
1 hour ago, J0k3r said:

sure, except the fact that before_leave_<map_name>() won't be called on player relog/closing the game, thus the count will be stuck until another player leaves "for real".

It is called.


Share this post


Link to post
Share on other sites

Hello @squaller!

 

Can you tell how to repeat the bug?


Share this post


Link to post
Share on other sites
On 12/29/2021 at 9:04 AM, V3ct0r said:

It is called.

sure my bad, but anyways the counter doesn't decrement if the player relog/exits the game, I think it is GetMapCopy? I'm not sure haven't really checked for all the errors/flow of the code, just letting you know that ur solution doesn't work in some cases.

 

-- EDIT
however the one I posted works correctly, regardless of it being called every second or whatsoever I know performance is a thing to consider tho.

Edited by J0k3r

Kind regards, AG.

Share this post


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

sure my bad, but anyways the counter doesn't decrement if the player relog/exits the game, I think it is GetMapCopy? I'm not sure haven't really checked for all the errors/flow of the code, just letting you know that ur solution doesn't work in some cases.

 

-- EDIT
however the one I posted works correctly, regardless of it being called every second or whatsoever I know performance is a thing to consider tho.

Hello @J0k3r!

 

Yes, there was a mistake in the code here:

function before_leave_<map_name>(role)

	SetPortalName("<map_name>", string.format("%d player(s) inside", GetMapActivePlayer(GetChaMapCopу(role))))
	
end

Should be:

function before_leave_<map_name>(role)

	SetPortalName("<map_name>", string.format("%d player(s) inside", GetMapActivePlayer(GetChaMapCopу(role)) - 1))
	
end

 

  • Thanks 1

Share this post


Link to post
Share on other sites
On 1/2/2022 at 5:22 PM, V3ct0r said:

Hello @J0k3r!

 

Yes, there was a mistake in the code here:


function before_leave_<map_name>(role)

	SetPortalName("<map_name>", string.format("%d player(s) inside", GetMapActivePlayer(GetChaMapCopу(role))))
	
end

Should be:


function before_leave_<map_name>(role)

	SetPortalName("<map_name>", string.format("%d player(s) inside", GetMapActivePlayer(GetChaMapCopу(role)) - 1))
	
end

 

like having a problem with GetChaMapCopy Error Gameserver
If I delete GetChaMapCopу Gameserver no problem, how to fix it?

1.PNG

Edited by gunnapong

Share this post


Link to post
Share on other sites

Hello @gunnapong,

 

There is a weird error in GetChaMapCopy word above. Try this code:

function before_leave_<map_name>(role)

	SetPortalName("<map_name>", string.format("%d player(s) inside", GetMapActivePlayer(GetChaMapCopy(role)) - 1))
	
end

 


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...