Jump to content

Recommended Posts

 

I need to check the number of live players, that is, I need to run the code, provided that only 1 player is alive, for example, let's take "print (He is alive)".
I tried to find the code to regenerate the world with dead players, but I could not find it, I will be glad to help.
Thank you ^_^

:wilson_blush:

 

Link to comment
https://forums.kleientertainment.com/forums/topic/136778-is-he-alive/
Share on other sites

You can check the living players by looping through the table AllPlayers and checking if they have the tag "playerghost" to see if they are dead.

You can regenerate the world by using the functions shown in console_commands.lua

-- Permanently delete all game worlds in a server cluster, regenerates new worlds afterwards
-- NOTE: This will not work properly for any shard that is offline or in a loading state
function c_regenerateworld()
    if TheWorld ~= nil and TheWorld.ismastersim then
        TheNet:SendWorldResetRequestToServer()
    end
end

 

I think something like this should work:

local function ResetWorld()
	if #GLOBAL.AllPlayers <= 1 then 
		if GLOBAL.TheWorld ~= nil and GLOBAL.TheWorld.ismastersim then
			GLOBAL.TheNet:SendWorldResetRequestToServer()
		end
	end
end

This needs to be executed on the server, otherwise it won't work.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...