Jump to content

[Scripting] get moon phase?


Recommended Posts

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 by Aquaterion
Link to comment
Share on other sites

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

a variable that will be "day", "dusk", or "night".

Edited by Woodside235
Link to comment
Share on other sites

@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 listeners

But 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

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 by Aquaterion
Link to comment
Share on other sites

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 by Kzisor
Link to comment
Share on other sites

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 by Aquaterion
Link to comment
Share on other sites

 

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

Working Code:

local assets......
local function PhaseChange(inst, phase)
if phase == "night" and TheWorld.state.isfullmoon then
SetNightmareMonkey(inst)
else
SetNormalMonkey(inst)
end
 
end

...
...
local function fn()
...
...
inst:WatchWorldState("phase", PhaseChange)
...
...
end
...
return Prefab("cave/monsters/monkey", fn, assets, prefabs)

Edited by Aquaterion
Link to comment
Share on other sites

@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

@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)
  end
end
Edited by Kzisor
Link to comment
Share on other sites

 

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

I got it working with the second code I had planned but was too lazy to wait till a full moon... RIP 4 HOURS

Code:
 

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

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=364821573

It 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

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