Solarus-Games English Forum

Community => Your scripts => Topic started by: Diarandor on November 10, 2017, 09:40:39 AM

Title: New rain script
Post by: Diarandor on November 10, 2017, 09:40:39 AM
You can download from here an updated version of my rain script:
https://github.com/solarus-games/children-of-solarus/tree/master/data/scripts/weather

This new version does not use custom entities anymore. It draws all rain drops on a surface, and only 1 single sprite is used for all the rain. There is also the storm mode, which is more spectacular. And the best of all is that the transition between the 3 modes ("rain", "storm" and nil) is smooth.
Title: Re: New rain script
Post by: Diarandor on November 11, 2017, 07:21:03 AM
Just a testing video:
https://youtu.be/Fbd4etGLC74

The script allows to modify the rain mode of the current map, and also to attach a rain mode to certain world (the rain is automatically started when the hero enters that world). Note that there may be future changes and improvements for the code of the script.

Planned features:
-We will have a snow script too, maybe for next winter holidays. ;D
-I am considering to make a "frog" mode where it rains with frogs too. Maybe for April.
Title: Re: New rain script
Post by: Diarandor on November 11, 2017, 03:36:29 PM
Some issues have been fixed for the rain script. I think it works fine now.
Title: Re: New rain script
Post by: oclero on November 11, 2017, 05:25:41 PM
This looks awesome !

Some suggestions :
- use (semi-transparent?) white rain drops instead of blue ones. Water isn't blue. This is a misconception. In reality, water reflects the colour of the environment. So the only place where you'll find "blue water" is blue is in swimming pools  ;)
- For lightning strokes, I suggest you to use white instead of yellow, or a very pale yellow, close to white. Then draw this surface with a special blend mode like "add" (not multiply), to change colors while keeping shapes.
- Using semi-transparent dark grey/blue as a surface, in "multiply" mode. Make the transparency vary a bit, to simulte a dark cloudy atmsophere.
Title: Re: New rain script
Post by: Diarandor on November 12, 2017, 11:07:59 AM
Quote from: Neovyse on November 11, 2017, 05:25:41 PM
This looks awesome !

Some suggestions :
- use (semi-transparent?) white rain drops instead of blue ones. Water isn't blue. This is a misconception. In reality, water reflects the colour of the environment. So the only place where you'll find "blue water" is blue is in swimming pools  ;)
- For lightning strokes, I suggest you to use white instead of yellow, or a very pale yellow, close to white. Then draw this surface with a special blend mode like "add" (not multiply), to change colors while keeping shapes.
- Using semi-transparent dark grey/blue as a surface, in "multiply" mode. Make the transparency vary a bit, to simulte a dark cloudy atmsophere.

@Neovyse: Thanks a lot for the feedback! I have updated the files to add all your suggestions.
-Water and lightnings are now white, and water has more transparency.
-Storms add a dark surface drawn with "multiply" blend mode. Smooth transition when it appears/disappears.
-The "add" blend mode for lightnings make them look great (much better now!).

One of the annoying parts was to make the smooth transition for the darkness surface for storms, because the "multiply" blend mode does not use the alpha channel, which means that using opacity/transparency on the surface was useless. >:( But I made it in a different way, just by scaling the (r, g, b) coordinates (the color {(255, 255, 255)} seems to be transparent for "multiply" blend mode.)
Title: Re: New rain script
Post by: MetalZelda on November 12, 2017, 07:10:34 PM
Oh wow, definately gonna use it for my project, this is gonna serve environment purpose I've tough some time ago
Wonder if other effects can be achieved just by modifying your script (snow)

Gonna look around if this script can fit in my Day / Night script
Title: Re: New rain script
Post by: Diarandor on November 12, 2017, 08:37:17 PM
Yes, snow should not be harder than this. But better to make it in a different script because the rain script is already very complex due to the smooth transition between different rain modes (the rain drop number and their properties, and the darkness value, vary very smoothly). If you can wait for Christmas holidays, I will probably make the snow script for then.
Title: Re: New rain script
Post by: MetalZelda on November 14, 2017, 04:26:24 PM
Quote from: Diarandor on November 12, 2017, 08:37:17 PM
Yes, snow should not be harder than this. But better to make it in a different script because the rain script is already very complex due to the smooth transition between different rain modes (the rain drop number and their properties, and the darkness value, vary very smoothly). If you can wait for Christmas holidays, I will probably make the snow script for then.

Snow can be easy to make, just by editing the rain script, it tooks me around 5 minutes to make sprites and edit stuffs and the result is ok (if you take out the green terrain which don't fit the snow weather)
The snow effect is better with the drop deviation variable

Great thing is, it is really easy to include the weather script with my day / night cycle, I don't see any problem so far

(https://i.imgur.com/3lA492E.png)
Title: Re: New rain script
Post by: Diarandor on November 15, 2017, 12:27:04 PM
Keep track of the last changes (and future ones) here:
https://github.com/solarus-games/children-of-solarus/issues/60
Title: Re: New rain script
Post by: Diarandor on November 15, 2017, 02:00:55 PM
Testing the new scrolling between maps feature:
https://youtu.be/ZU-7zRnUJcw
Title: Re: New rain script
Post by: Diarandor on November 15, 2017, 03:49:05 PM
I think all problems are now fixed. And more customization has been added. Current version may be the last one.
Title: Re: New rain script
Post by: Diarandor on November 16, 2017, 03:11:26 PM
Ahoy there @everybody! There is already a usable version of a SNOW manager too! The code has been adapted from the last version of the rain manager. It is not the final version yet (it will be updated): there are things to do, like adding transparencies to the snow flakes that vary with the time, and also for when they have fallen to the ground (they should disappear smoothly). And maybe other small details.

Note that the current version of the snow manager is already far superior to the one of RPGshit RPGmaker.
I would like you to test it and give me some feedback. ;D
Title: Re: New rain script
Post by: Diarandor on November 16, 2017, 11:41:17 PM
The snow script is now finished!!! ;D
-It adds now dynamic transparencies to the snowflakes.
-I have also fixed some minor issues with the rain and snow scripts.

See the script in action:
https://youtu.be/TFIt7Quk4k0

Feedback is welcome (and mandatory!).
Title: Re: New rain script
Post by: Diarandor on November 17, 2017, 03:20:35 PM
Hail script coming soon! ;D
Title: Re: New rain script
Post by: MetalZelda on November 18, 2017, 01:14:59 PM
It is much better now, this is awesome, thanks for this awesome script !
Title: Re: New rain script
Post by: Diarandor on November 18, 2017, 05:02:02 PM
Quote from: MetalZelda on November 18, 2017, 01:14:59 PM
It is much better now, this is awesome, thanks for this awesome script !

You are welcome! ;D
And here goes the first version of the hail script:
https://youtu.be/H1M4t04eQ78
Title: Re: New rain script
Post by: Diarandor on November 18, 2017, 09:38:22 PM
The fog script, and maybe other weather scripts, will have to wait. :P
No more weather scripts for now.
Title: Re: New rain script
Post by: froggy77 on November 19, 2017, 12:06:08 AM
wow, amazing what Solarus engine can do!

Your scripts are awesome, very well commented and quite easy to change to create new effects, that's why I follow your GitHub (https://github.com/solarus-games/children-of-solarus/tree/master/data).

So, I created a fall (autumn) effect with orange leaves from your "snow manager" script. The "fall manager" is a first version, but I like the result.

(http://froggy.web.pagesperso-orange.fr/images/divers/SOLARUS_fall_mode.gif)

(I specify the location of files to help newbies. ;)
local fall_script_enabled = true

...

if fall_script_enabled then
  require("scripts/weather/fall_manager")
else -- Redefine methods to avoid errors.
  function game_meta:get_fall_mode() return nil end
  function game_meta:set_fall_mode(fall_mode) end
  function game_meta:get_world_fall_mode(world) return nil end
  function game_meta:set_world_fall_mode(world, fall_mode) end
end


You can find it here: https://github.com/solarus-games/children-of-solarus/blob/master/data/scripts/weather/weather_manager.lua (https://github.com/solarus-games/children-of-solarus/blob/master/data/scripts/weather/weather_manager.lua)

sprite{ id = "weather/leaf", description = "weather/leaf" }

You can find it here: https://github.com/solarus-games/children-of-solarus/blob/master/data/scripts/meta/teletransporter_meta.lua (https://github.com/solarus-games/children-of-solarus/blob/master/data/scripts/meta/teletransporter_meta.lua)You can find it here: https://github.com/solarus-games/children-of-solarus/blob/master/data/scripts/multi_events.lua (https://github.com/solarus-games/children-of-solarus/blob/master/data/scripts/multi_events.lua)

require("scripts/weather/weather_manager")
You can find it here: https://github.com/solarus-games/children-of-solarus/blob/master/data/scripts/features.lua (https://github.com/solarus-games/children-of-solarus/blob/master/data/scripts/features.lua)
You may need to delete some lines depending on your project, but you must add at least the line. I say that, because myself, I searched to find out why the weather scripts did not work.
game:set_world_fall_mode("outside", "fall") or "fall_storm" mode instead of "fall" mode.



Quote from: Diarandor on November 16, 2017, 03:11:26 PM
Note that the current version of the snow manager is already far superior to the one of RPGshit RPGmaker.
lol  ;D
Title: Re: New rain script
Post by: yankscally on January 07, 2018, 10:52:46 AM
Hi, I'm trying to impelement this into my project, but run into problems with putting it into my game manager, I'm still learning lua so the code I'm trying to put in game manager is this


-- Rain manager script.
-- Author: Diarandor (Solarus Team).
-- License: GPL v3-or-later.
-- Donations: solarus-games.org, diarandor at gmail dot com.

--[[   Instructions:
To add this script to your game, call from game_manager script:
    require("scripts/weather/rain_manager")
The functions here defined are:
    game:get_rain_mode()
    game:set_rain_mode(rain_mode)
    game:get_world_rain_mode(world)
    game:set_world_rain_mode(world, rain_mode)
Rain modes: "rain", "storm", nil (no rain).
--]]

-- This script requires the multi_event script and the teleporters meta:
require("scripts/multi_events")
local rain_manager = {}

local game_meta = sol.main.get_metatable("game")
local map_meta = sol.main.get_metatable("map")

--- ECT



in the instructions part, it doesnt say where to put it in game manager. I used to have a bit more lua knowledge last year after you guys showed me how to set up a P2 control and custom entity....
Title: Re: New rain script
Post by: Diarandor on January 07, 2018, 06:27:01 PM
@yankscally: You can put it above of your script "game_manager.lua". Make sure that the "require" line is called once, or the weather scripts will not work. Just study the scripts of CoS to understand how it works.

More important: make sure that the events that are registered in the weather scripts (with the multievents script) are also registered with the multievents script in your other scripts (in case they are defined); otherwise your definitions will override mine and the weather scripts will break and give you an error. (Two people had this problem before, so I should probably explain this better in the comments of the weather scripts in a future version.)

@froggy77: I like a lot your falling-leaves effects! ;D
Title: Re: New rain script
Post by: Svenibu on February 19, 2021, 10:52:10 PM
Hi Dirandor

can you help me with the weather script?

I have the script and the sprites imported.

I add the script weather_manager in my quest_manager script.

In the script from my map i have
add in the  the function map:on_started()
game:set_world_rain_mode("outside_world","rain")

it doesn't rain in the testgame
Title: Re: New rain script
Post by: PeterB on February 21, 2021, 08:15:13 AM
Hi,

I assume you added the rain_manger script to your scripts as well?

Also does your map have the world as outside_world?

Thanks,

PeterB
Title: Re: New rain script
Post by: Svenibu on February 23, 2021, 08:16:49 PM
Hi PeterB,

i have the Script whether_manager, hail_manager, rain_manager, snow_manager.

i have testet require("scripts/weather/weather_manager.lua") in main.lua and in my quest_manager.lua.

In the map script i call in the function map:on_started game:set_world_rain_mode("outside_world", "rain") the name of my map is set a world is: outside_world

I have print("rain is loaded") in the weather_manager and the same in the rain_manager to test the script is loaded.

in the Console I geht no error.

Title: Re: New rain script
Post by: PeterB on February 23, 2021, 09:12:35 PM
Hi,

Here is a link to a newer version of Children of Solarus rather than the old one in this post https://gitlab.com/solarus-games/children-of-solarus/-/tree/dev/data (https://gitlab.com/solarus-games/children-of-solarus/-/tree/dev/data)

I didn't add anything to main.lua so that may be part of the problem. I kept the same folder structure to save changing paths in the scripts and copied across -

scripts/teletransporter_meta (although i don't think this is required so could be commented out in the scripts?)
scripts/weather/hail, rain, snow and weather_manager
sprites/weather/rain and snow.png and dat

I also made sure that my scripts/multi_events wasn't missing anything from the Children of Solarus scripts/multi_events one (which it wasn't)

Then in the map.lua file of the map where you want the weather to appear you have to add


function map:on_started()

    game:set_world_rain_mode("your_world", "storm") or
    game:set_hail_mode("hail")

end


If you have a look at the snow, rain or hail manager scripts they all have examples of how to get the effect you are after.

But only do one effect.

I hope that helps.
Title: Re: New rain script
Post by: Svenibu on February 25, 2021, 09:08:36 PM
Hi,
i have imported the script in the link and i have the same problems.

i have tested game:set_rain_mode("rain")
function map:on_started()

    game:set_rain_mode("rain")

end


I get a error in the console

Error: In maps/hyrule/b3: scripts/weather/rain_manager.lua:212: attempt to index upvalue 'timers' (a nil value)
stack traceback:
[C]: in function '__index'
scripts/weather/rain_manager.lua:212: in function 'stop_timers'
scripts/weather/rain_manager.lua:224: in function 'start_rain_mode'
scripts/weather/rain_manager.lua:59: in function 'set_rain_mode'
maps/hyrule/b3.lua:4: in main chunk
Title: Re: New rain script
Post by: PeterB on February 25, 2021, 09:46:16 PM
Hi,

I am no lua expert but it looks as though timers is not getting any value assigned to it.

Have you tried snow or hail, do they throw up errors as well?

I assume you are calling require("scripts/weather/rain_manager") from your game_manager script otherwise you wouldn't get an error.

If you copied the scripts across they should work so what else have you got in your map.lua script?

The scripts work for me in my game so I am at a loss.
Title: Re: New rain script
Post by: froggy77 on February 25, 2021, 11:34:29 PM
Quote'set_rain_mode' maps/hyrule/b3.lua:4: in main chunk
What does your file 'b3.lua' contain? Something like that?local map = ...
local game = map:get_game()
function map:on_started()
   game:set_world_rain_mode("outside_world", "rain")
end