New rain script

Started by Diarandor, November 10, 2017, 09:40:39 AM

Previous topic - Next topic
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
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

The fog script, and maybe other weather scripts, will have to wait. :P
No more weather scripts for now.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

November 19, 2017, 12:06:08 AM #17 Last Edit: November 19, 2017, 01:22:44 AM by froggy77
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.

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.



(I specify the location of files to help newbies. ;)

       
  • Add these lines in ..\solarus\data\scripts\weather\weather_manager.lua
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


       
  • ..\solarus\data\project_db.dat  (Change it via the editor)
sprite{ id = "weather/leaf", description = "weather/leaf" }


       
  • Don't forget ..\solarus\data\scripts\meta\teletransporter_meta.lua
You can find it here: https://github.com/solarus-games/children-of-solarus/blob/master/data/scripts/meta/teletransporter_meta.lua

       
  • Also ..\solarus\data\script\multi_events.lua
You can find it here: https://github.com/solarus-games/children-of-solarus/blob/master/data/scripts/multi_events.lua


       
  • In ..\solarus\data\script\features.lua, add this line:
require("scripts/weather/weather_manager")
You can find it here: 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.

       
  • In your "map".lua, add this line to trigger the effect in the "function map:on_started()"
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

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

January 07, 2018, 06:27:01 PM #19 Last Edit: January 07, 2018, 06:29:26 PM by Diarandor
@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
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

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

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

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.


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

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.

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

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.

February 25, 2021, 11:34:29 PM #26 Last Edit: February 25, 2021, 11:37:28 PM by froggy77
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