Woodside235 Posted January 9, 2015 Share Posted January 9, 2015 I'd think this would be a really simple thing, but I can't find out how. How do I get the current phase of the moon? Link to comment Share on other sites More sharing options...
Kzisor Posted January 9, 2015 Share Posted January 9, 2015 @Woodside235, you can get the moonphase by listening for the moon phase change. local function OnMoonPhaseChange(inst, moonphase)endinst:ListenForEvent("moonphasechanged", function OnMoonPhaseChange) Link to comment Share on other sites More sharing options...
Woodside235 Posted January 9, 2015 Author Share Posted January 9, 2015 Oh, hello again @Kzisor. Can it only be gotten with events? Is there no function call that can get it? Something like GetMoonPhase() or something? I could easily set a function up myself using the events, but I am lazy. Link to comment Share on other sites More sharing options...
Aquaterion Posted January 9, 2015 Share Posted January 9, 2015 (edited) Ah that's great, I was gonna ask about moonphases, and here it is. Thanks Edit: Do you any way to change the moon state in-game, as in to test if the thing is working properly at the moonphase u wanted? Edited January 9, 2015 by Aquaterion Link to comment Share on other sites More sharing options...
Woodside235 Posted January 9, 2015 Author Share Posted January 9, 2015 @Kzisor Is there a way to check day/dusk/night with a function rather than with an event listener? Link to comment Share on other sites More sharing options...
Woodside235 Posted January 9, 2015 Author Share Posted January 9, 2015 (edited) @Kzisor Is there a way to check day/dusk/night with a function rather than with an event listener? figured this one out, haven't found one for moon phases. turns out making one isn't that easy, either. EDIT: for day/dusk/night: GLOBAL.TheWorld.state.phasea variable that will be "day", "dusk", or "night". Edited January 9, 2015 by Woodside235 Link to comment Share on other sites More sharing options...
Aquaterion Posted January 9, 2015 Share Posted January 9, 2015 @Woodside235, you can get the moonphase by listening for the moon phase change. local function OnMoonPhaseChange(inst, moonphase)endinst:ListenForEvent("moonphasechanged", function OnMoonPhaseChange) I did exactly like this but inst:ListenForEvent("moonphasechanged", OnMoonPhaseChanged)as when I put function it just doesn't work. I tried severly things to try and make it work.The Listener is not working.I'm putting the listener in "local function fn()" on a monster next to it's other listenersBut OnMoonPhaseChanged never gets called. I put a "print("MoonPhase Called") inOnMoonPhaseChanged but it never got printed while the one before did(I had one do the event when it's night rather than when it's a moon phase of some sort.Do you know what could be wrong? Link to comment Share on other sites More sharing options...
Kzisor Posted January 9, 2015 Share Posted January 9, 2015 Aquaterion, I've got no clue because that's the event being pushed. _world:PushEvent("moonphasechanged", MOON_PHASE_NAMES[_moonphase:value()] Link to comment Share on other sites More sharing options...
Aquaterion Posted January 9, 2015 Share Posted January 9, 2015 (edited) Aquaterion, I've got no clue because that's the event being pushed. _world:PushEvent("moonphasechanged", MOON_PHASE_NAMES[_moonphase:value()] Yea, I've checked that file too, I'm not sure what's wrong. Do you think that this is required at the top require "prefabutil" ? I saw it on shadow chester and he uses TheWorld.state.isfullmoon to transform. Do you know if there is TheWorld.state.isnewmoon or something? Since I wanna test if it works, I want it to be the first moon phase and I'm not sure if it's isnewmoon Edit: Just checked the worldstate file, and found this: local function OnMoonPhaseChanged(src, moonphase) SetVariable("isfullmoon", moonphase == "full")end inst:ListenForEvent("moonphasechanged", OnMoonPhaseChanged)I'm completely clueless on what i'm doing wrong now.. what I'm doing wrong anymore. Edited January 9, 2015 by Aquaterion Link to comment Share on other sites More sharing options...
Kzisor Posted January 9, 2015 Share Posted January 9, 2015 (edited) Yea, I've checked that file too, I'm not sure what's wrong. Do you think that this is required at the top require "prefabutil" ? I saw it on shadow chester and he uses TheWorld.state.isfullmoon to transform. Do you know if there is TheWorld.state.isnewmoon or something? Since I wanna test if it works, I want it to be the first moon phase and I'm not sure if it's isnewmoon The only moonphase which has a variable is full moon. You could technically alter the file to make more have variables, but listening for that event should work. May I ask if you are the host or client? Alternatively you could try changing inst to src in the OnMoonChanged function to see if that works. Check out the worldstate.lua component for details. Edited January 9, 2015 by Kzisor Link to comment Share on other sites More sharing options...
Aquaterion Posted January 9, 2015 Share Posted January 9, 2015 (edited) Well I'm making the mod myself so I would be the host yes? Edit: This is the code that involves the moonphasechange, maybe you can inspect it and see if I done anything wrong: local function OnMoonPhaseChanged(inst, moonphase) print("Checking Moon Phase...") print(moonphase) if moonphase == "new" then --Set Things to second state. print("A New Moon has been reached!") else print("There is no New Moon!") --Set Things to default state. endendinst:ListenForEvent("moonphasechanged", OnMoonPhaseChanged) Edited January 9, 2015 by Aquaterion Link to comment Share on other sites More sharing options...
Kzisor Posted January 9, 2015 Share Posted January 9, 2015 Well I'm making the mod myself so I would be the host yes? Edit: This is the code that involves the moonphasechange, maybe you can inspect it and see if I done anything wrong: local function OnMoonPhaseChanged(inst, moonphase) print("Checking Moon Phase...") print(moonphase) if moonphase == "new" then --Set Things to second state. print("A New Moon has been reached!") else print("There is no New Moon!") --Set Things to default state. endendinst:ListenForEvent("moonphasechanged", OnMoonPhaseChanged) Try changing inst to src and see if it will run properly. Link to comment Share on other sites More sharing options...
Aquaterion Posted January 9, 2015 Share Posted January 9, 2015 Try changing inst to src and see if it will run properly. Nope.. ;-; what am I doing wrong... Link to comment Share on other sites More sharing options...
Kzisor Posted January 9, 2015 Share Posted January 9, 2015 Nope.. ;-; what am I doing wrong... What is your full code? Link to comment Share on other sites More sharing options...
Aquaterion Posted January 9, 2015 Share Posted January 9, 2015 (edited) Working Code:local assets......local function PhaseChange(inst, phase)if phase == "night" and TheWorld.state.isfullmoon thenSetNightmareMonkey(inst)elseSetNormalMonkey(inst)end end......local function fn()......inst:WatchWorldState("phase", PhaseChange)......end... return Prefab("cave/monsters/monkey", fn, assets, prefabs) Edited January 9, 2015 by Aquaterion Link to comment Share on other sites More sharing options...
Kzisor Posted January 9, 2015 Share Posted January 9, 2015 (edited) @Aquaterion, change the ListenForEvent line to the following: TheWorld:ListenForEvent("moonphasechanged", OnMoonPhaseChanged) Edited January 9, 2015 by Kzisor Link to comment Share on other sites More sharing options...
Aquaterion Posted January 9, 2015 Share Posted January 9, 2015 @Aquaterion, change the ListenForEvent line to the following: TheWorld:ListenForEvent("moonphasechanged", OnMoonPhaseChanged) It gave a different error due to the fact that it no longer has inst, so it's not sending the inst over but the prints before the if moonphase = "new" appeared, so that fixed 1 thing, but broke another, where do i add inst now? Link to comment Share on other sites More sharing options...
Kzisor Posted January 9, 2015 Share Posted January 9, 2015 (edited) @Aquaterion, replace inst with self. local function OnMoonPhaseChanged(inst, moonphase) print(moonphase) print("Moon Checking Powers Activate!") if moonphase == "new" then SetNightmareMonkey(inst) print("A New Moon has been reached!") else print("There is no New Moon, or this is not working properly :(") SetNormalMonkey(inst) endend Edited January 9, 2015 by Kzisor Link to comment Share on other sites More sharing options...
Aquaterion Posted January 9, 2015 Share Posted January 9, 2015 @Aquaterion, replace inst with self. That didn't work, as i would still need to put "self" in this line somewhere: TheWorld:ListenForEvent("moonphasechanged", OnMoonPhaseChanged) Link to comment Share on other sites More sharing options...
DarkXero Posted January 9, 2015 Share Posted January 9, 2015 (edited) self.inst:ListenForEvent("moonphasechanged", function(inst, data) self:OnMoonPhaseChanged(data) end, TheWorld) Edited January 9, 2015 by DarkXero Link to comment Share on other sites More sharing options...
Aquaterion Posted January 9, 2015 Share Posted January 9, 2015 self.inst:ListenForEvent("moonphasechanged", function(inst, data) self:OnMoonPhaseChanged(data) end, TheWorld)variable 'self' is not declared Damn I was so sure It was gonna work... I've at this for over 5 hours lol.. stupid monkies Link to comment Share on other sites More sharing options...
DarkXero Posted January 9, 2015 Share Posted January 9, 2015 I ended up copying the example. My code is:inst:ListenForEvent("moonphasechanged", OnMoonPhaseChanged, TheWorld) Link to comment Share on other sites More sharing options...
Aquaterion Posted January 9, 2015 Share Posted January 9, 2015 I ended up copying the example. My code is:inst:ListenForEvent("moonphasechanged", OnMoonPhaseChanged, TheWorld) That Makes the variable in OnMoonPhaseChanged come from TheWorld, most of the time being a Forest with an ID. BLARGHHHH In game, is there anyway to change time/speed up time? I wanna try something new I wrote but it only works with fullmoons, and waiting 7 to 8 days is gonna be long.. Link to comment Share on other sites More sharing options...
Aquaterion Posted January 9, 2015 Share Posted January 9, 2015 I got it working with the second code I had planned but was too lazy to wait till a full moon... RIP 4 HOURSCode: local function PhaseChange(inst, phase) if phase == "night" and TheWorld.state.isfullmoon then SetNightmareMonkey(inst) else SetNormalMonkey(inst) endendinst:WatchWorldState("phase", PhaseChange) Link to comment Share on other sites More sharing options...
DarkXero Posted January 9, 2015 Share Posted January 9, 2015 Start server, enter LongUpdate(480*8) in the console. Also, I read the code, and there is no "new" moonphase, there is only full moon, so it won't work.What are you trying to do here? Fix Splumonkeys?Check this mod:http://steamcommunity.com/sharedfiles/filedetails/?id=364821573It has splumonkeys working. What I do for full moon nights is:local function NightCheck(inst) if TheWorld.state.isfullmoon then MyFunction(inst) endendinst:WatchWorldState("startnight", NightCheck) 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