Mario384 Posted May 27, 2016 Share Posted May 27, 2016 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 More sharing options...
Aquaterion Posted May 27, 2016 Share Posted May 27, 2016 (edited) 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 May 27, 2016 by Aquaterion Link to comment Share on other sites More sharing options...
Mario384 Posted May 27, 2016 Author Share Posted May 27, 2016 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 More sharing options...
Aquaterion Posted May 27, 2016 Share Posted May 27, 2016 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 More sharing options...
Mario384 Posted May 27, 2016 Author Share Posted May 27, 2016 Well, it works, somewhat. Even if there no alive players, the function still runs. Also "survivial" is the proper term. Link to comment Share on other sites More sharing options...
Muche Posted May 27, 2016 Share Posted May 27, 2016 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 More sharing options...
Aquaterion Posted May 27, 2016 Share Posted May 27, 2016 (edited) 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 May 27, 2016 by Aquaterion Link to comment Share on other sites More sharing options...
Muche Posted May 27, 2016 Share Posted May 27, 2016 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 More sharing options...
Aquaterion Posted May 27, 2016 Share Posted May 27, 2016 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 More sharing options...
Mario384 Posted May 27, 2016 Author Share Posted May 27, 2016 Neither solution works. The first never activates, and the second crashes because isworldresetting is not declared. Link to comment Share on other sites More sharing options...
Aquaterion Posted May 27, 2016 Share Posted May 27, 2016 (edited) 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 May 27, 2016 by Aquaterion Link to comment Share on other sites More sharing options...
Mario384 Posted May 27, 2016 Author Share Posted May 27, 2016 2 minutes ago, Aquaterion said: his solution i believe you gotta put outside, as in not inside a function what Link to comment Share on other sites More sharing options...
Aquaterion Posted May 27, 2016 Share Posted May 27, 2016 1 minute ago, Mario384 said: what Link to comment Share on other sites More sharing options...
Mario384 Posted May 27, 2016 Author Share Posted May 27, 2016 (edited) 8 minutes ago, Aquaterion said: Yes, I understand, but TheWorld also isn't defined, and also crashes. Edited May 27, 2016 by Mario384 Link to comment Share on other sites More sharing options...
Aquaterion Posted May 27, 2016 Share Posted May 27, 2016 2 minutes ago, Mario384 said: Yes, I understand, but TheWorld also isn't defined, and also crashes. is this in modmain? you might need GLOBAL.TheWorld instead of TheWorld Link to comment Share on other sites More sharing options...
Mario384 Posted May 27, 2016 Author Share Posted May 27, 2016 2 minutes ago, Aquaterion said: is this in modmain? you might need GLOBAL.TheWorld instead of TheWorld In my case, it is actually in spiderden.lua. Link to comment Share on other sites More sharing options...
Aquaterion Posted May 27, 2016 Share Posted May 27, 2016 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 More sharing options...
Mario384 Posted May 27, 2016 Author Share Posted May 27, 2016 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 More sharing options...
Aquaterion Posted May 27, 2016 Share Posted May 27, 2016 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 More sharing options...
Mario384 Posted May 27, 2016 Author Share Posted May 27, 2016 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 More sharing options...
Aquaterion Posted May 27, 2016 Share Posted May 27, 2016 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 More sharing options...
Muche Posted May 27, 2016 Share Posted May 27, 2016 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 More sharing options...
Mario384 Posted May 27, 2016 Author Share Posted May 27, 2016 Possession Mod.zip Link to comment Share on other sites More sharing options...
Aquaterion Posted May 27, 2016 Share Posted May 27, 2016 21 minutes ago, Mario384 said: Possession Mod.zip u didn't change isworldresetting to inst.isworldresetting in the actually OnHaunt function like i told you to Link to comment Share on other sites More sharing options...
Mario384 Posted May 27, 2016 Author Share Posted May 27, 2016 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now