Jump to content

Can't Check If The World Is Resetting


Recommended Posts

Basically, I currently have this in my code in a prefab.

 

local function OnHaunt(inst, haunter)
    if math.random() <= TUNING.HAUNT_CHANCE_HALF and TheNet:SetIsWorldResetting(false) then

    haunter:AddTag("possessinginplace")
    haunter:DoTaskInTime(5, makespiderpossessed)
    haunter:PushEvent("respawnfromghost")
    
    end

    return false
end

 

However, it never seems to work.  Even if the world isn't resetting, it won't run.  Any idea why this won't work?

Link to comment
Share on other sites

Well the "TheNet:SetIsWorldResetting(false)" is a SET, so I don't think it will ever return true, not sure what you could use, but I guess you could check if the gamemode is survival and if the alive player count is 0?

Edited by Aquaterion
Link to comment
Share on other sites

1 hour ago, Aquaterion said:

Well the "TheNet:SetIsWorldResetting(false)" is a SET, so I don't think it will ever return true, not sure what you could use, but I guess you could check if the gamemode is survival and if the alive player count is 0?

 

I tried doing that, but I couldn't figure out how.

Link to comment
Share on other sites

local gamemode = TheNet:GetServerGameMode() --to get gamemode

local pcount = 0
for _,p in pairs(AllPlayers) do
	if not p:HasTag("playerghost") then -- to get amount of non ghost players
		pcount = pcount + 1
	end
end

im not sure what exactly GetServerGameMode returns, if its a string with gamemode name of some id, might require some checkin but other than that it would go something like;

 local function OnHaunt(inst, haunter)
    if math.random() <= TUNING.HAUNT_CHANCE_HALF and pcount == 0 and gamemode == "survival" then

    haunter:AddTag("possessinginplace")
    haunter:DoTaskInTime(5, makespiderpossessed)
    haunter:PushEvent("respawnfromghost")
    
    end

    return false
end 

 

Link to comment
Share on other sites

gamemodes.lua also defines GetResetTime:

local gamemode = TheNet:GetServerGameMode()
local resettime = GetResetTime(gamemode) -- table (with settings) if current gamemode will reset on all ghosts (e.g. survival mode), nil otherwise

components/worldreset.lua is pushing some events that could be used to detect resetting:

local isworldresetting = false
TheWorld:ListenForEvent("showworldreset", function() isworldresetting = true end)
TheWorld:ListenForEvent("hideworldreset", function() isworldresetting = false end)

 

Link to comment
Share on other sites

5 minutes ago, Mario384 said:

Well, it works, somewhat.  Even if there no alive players, the function still runs.  Also "survivial" is the proper term.

oh I understood it wrong, the playercount is the other way around

local function OnHaunt(inst, haunter)
    if math.random() <= TUNING.HAUNT_CHANCE_HALF and (pcount > 0 or gamemode ~= "survival") then

    haunter:AddTag("possessinginplace")
    haunter:DoTaskInTime(5, makespiderpossessed)
    haunter:PushEvent("respawnfromghost")
    
    end

    return false
end 

this should check if there is atleast 1 player or if its not survival

2 minutes ago, Muche said:

 

components/worldreset.lua is pushing some events that could be used to detect resetting:

 


local isworldresetting = false
TheWorld:ListenForEvent("showworldreset", function() isworldresetting = true end)
TheWorld:ListenForEvent("hideworldreset", function() isworldresetting = false end)

 

Yea I saw those listeners, but im not sure how you could do an action that checks if an event was pushed.

Edited by Aquaterion
Link to comment
Share on other sites

4 minutes ago, Aquaterion said:

Yea I saw those listeners, but im not sure how you could do an action that checks if an event was pushed.

I was thinking something like (together with listeners above):

local function OnHaunt(inst, haunter)
    if math.random() <= TUNING.HAUNT_CHANCE_HALF and not isworldresetting then
        haunter:AddTag("possessinginplace")
        haunter:DoTaskInTime(5, makespiderpossessed)
        haunter:PushEvent("respawnfromghost")
    end
    return false
end

 

Link to comment
Share on other sites

9 minutes ago, Muche said:

I was thinking something like (together with listeners above):


local function OnHaunt(inst, haunter)
    if math.random() <= TUNING.HAUNT_CHANCE_HALF and not isworldresetting then
        haunter:AddTag("possessinginplace")
        haunter:DoTaskInTime(5, makespiderpossessed)
        haunter:PushEvent("respawnfromghost")
    end
    return false
end

 

oh I see now I get it

Link to comment
Share on other sites

36 minutes ago, Mario384 said:

Neither solution works.  The first never activates, and the second crashes because isworldresetting is not declared.

his solution i believe you gotta put outside, as in not inside a function. as for mine, you sure u doing pcount correctly?

Edited by Aquaterion
Link to comment
Share on other sites

ok try putting it in the main fn like this:

inst.isworldresetting = false
TheWorld:ListenForEvent("showworldreset", function() inst.isworldresetting = true end)
TheWorld:ListenForEvent("hideworldreset", function() inst.isworldresetting = false end)

and change the isworldresetting in the onhaunt to inst.isworldresetting

Link to comment
Share on other sites

12 minutes ago, Aquaterion said:

ok try putting it in the main fn like this:


inst.isworldresetting = false
TheWorld:ListenForEvent("showworldreset", function() inst.isworldresetting = true end)
TheWorld:ListenForEvent("hideworldreset", function() inst.isworldresetting = false end)

and change the isworldresetting in the onhaunt to inst.isworldresetting

Just tried it, but it still runs the function even when then timer is running.

Link to comment
Share on other sites

5 minutes ago, Mario384 said:

Just tried it, but it still runs the function even when then timer is running.

yea doesnt seem like it works but I tried my version and it did work

local function OnHaunt(inst)
    if math.random() <= TUNING.HAUNT_CHANCE_HALF then
	
		local gamemode = TheNet:GetServerGameMode() --to get gamemode

		local pcount = 0
		for _,p in pairs(AllPlayers) do
			if not p:HasTag("playerghost") then -- to get amount of non ghost players
				pcount = pcount + 1
			end
		end
		
		if pcount > 0 or gamemode ~= "survival" then
			--if not resetting
		end
--......

this is the spider den's already existing OnHaunt, with the added code you wanted and it WORKED fine.

Link to comment
Share on other sites

8 minutes ago, Aquaterion said:

yea doesnt seem like it works but I tried my version and it did work


local function OnHaunt(inst)
    if math.random() <= TUNING.HAUNT_CHANCE_HALF then
	
		local gamemode = TheNet:GetServerGameMode() --to get gamemode

		local pcount = 0
		for _,p in pairs(AllPlayers) do
			if not p:HasTag("playerghost") then -- to get amount of non ghost players
				pcount = pcount + 1
			end
		end
		
		if pcount > 0 or gamemode ~= "survival" then
			--if not resetting
		end
--......

this is the spider den's already existing OnHaunt, with the added code you wanted and it WORKED fine.

Maybe it didn't work for me because I was using c_spawn ("wilson") to test it?  Does it have to be a real player?

Link to comment
Share on other sites

2 minutes ago, Mario384 said:

Maybe it didn't work for me because I was using c_spawn ("wilson") to test it?  Does it have to be a real player?

might be, I tested it by doing;

TheInput:GetWorldEntityUnderMouse().components.hauntable:DoHaunt(ThePlayer) on the spiderden, that way I was still alive, but still something haunted it

Link to comment
Share on other sites

45 minutes ago, Mario384 said:

Just tried it, but it still runs the function even when then timer is running.

Could you post your file? I just tried putting some debug prints into existing spiderden prefab and it worked fine.

local function OnHaunt(inst)
    print(string.format("[spiderden|OnHaunt] inst.isworldresetting=%s", tostring(inst.isworldresetting)))
...


in MakeSpiderDenFn:
        inst.isworldresetting = false
        TheWorld:ListenForEvent("showworldreset", function()
            print("[spiderden|showworldreset]")
            inst.isworldresetting = true
        end)
        TheWorld:ListenForEvent("hideworldreset", function()
            print("[spiderden|hideworldreset]")
            inst.isworldresetting = false
        end)

log:

[00:11:21]: [spiderden|showworldreset]	
[00:11:27]: [spiderden|OnHaunt] inst.isworldresetting=true	
[00:11:35]: [spiderden|OnHaunt] inst.isworldresetting=true	

 

Link to comment
Share on other sites

28 minutes ago, Aquaterion said:

u didn't change isworldresetting to inst.isworldresetting in the actually OnHaunt function like i told you to

Ah, that did it!  Thank you both very much for your help!

Link to comment
Share on other sites

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
 Share

×
  • Create New...