Weather System [TFS 1.x]

Printer

if Printer then print("LUA") end
Premium User
Joined
Dec 27, 2009
Messages
5,728
Reaction score
1,985
Location
Sweden?
Hello,

well it's time to release the weather system. Which alot of you waited for.


Features:
  • Rain only in players screen, to save memory usage. Instead of sending whole map.
  • If there is a roof, it will not send effect inside the building. But on the roof instead.
  • Aswell, if you are under a roof, it will only send outside the building.
  • When it hits water, it sends splash effect.
  • Thunder Effect and also deal damage.
Paste this into global.lua
Code:
weatherConfig = {
    groundEffect = CONST_ME_LOSEENERGY,
    fallEffect = CONST_ANI_ICE,
    thunderEffect = true,
    minDMG = 5,
    maxDMG = 10
}

function Player.sendWeatherEffect(self, groundEffect, fallEffect, thunderEffect)
    local position, random = self:getPosition(), math.random
    position.x = position.x + random(-4, 4)
      position.y = position.y + random(-4, 4)

    local fromPosition = Position(position.x + 1, position.y, position.z)
       fromPosition.x = position.x - 7
       fromPosition.y = position.y - 5

    local tile, getGround
    for Z = 1, 7 do
        fromPosition.z = Z
        position.z = Z

        tile = Tile(position)
        if tile then -- If there is a tile, stop checking floors
            fromPosition:sendDistanceEffect(position, fallEffect)
            position:sendMagicEffect(groundEffect, self)

            getGround = tile:getGround()
            if getGround and ItemType(getGround:getId()):getFluidSource() == 1 then
                position:sendMagicEffect(CONST_ME_WATERSPLASH, self)
            end
            break
        end
    end

    if thunderEffect and tile then
        if random(2) == 1 then
            local topCreature = tile:getTopCreature()

            if topCreature and topCreature:isPlayer() then
                position:sendMagicEffect(CONST_ME_BIGCLOUDS, self)
                doTargetCombatHealth(0, self, COMBAT_ENERGYDAMAGE, -weatherConfig.minDMG, -weatherConfig.maxDMG, CONST_ME_NONE)
                self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You were hit by lightning and lost some health.")
            end
        end
    end
end
How to use:
Code:
player:sendWeatherEffect(weatherConfig.groundEffect, weatherConfig.fallEffect, weatherConfig.thunderEffect)
I'm open for suggestions and even maybe how to make the code even better.
 
Last edited by a moderator:

Breed

Active Member
Joined
Jan 7, 2015
Messages
517
Reaction score
103
Thank you for your contribution to this community :)

I don't know if I would use this but I love the scripts you put out and do learn quite a bit from them :)
 

imback1

Unknown member
Joined
Jul 11, 2013
Messages
776
Reaction score
43
Hello,

well it's time to release the weather system. Which alot of you waited for.


Features:
  • Rain only in players screen, to save memory usage. Instead of sending whole map.
  • If there is a roof, it will not send effect inside the building. But on the roof instead.
  • Aswell, if you are under a roof, it will only send outside the building.
  • When it hits water, it sends splash effect.
  • Thunder Effect and also deal damage.
Paste this into global.lua
Code:
weatherConfig = {
    groundEffect = CONST_ME_LOSEENERGY,
    fallEffect = CONST_ANI_ICE,
    thunderEffect = true,
    minDMG = 5,
    maxDMG = 10
}

function Player.sendWeatherEffect(self, groundEffect, fallEffect, thunderEffect)
    local position, random = self:getPosition(), math.random
    position.x = position.x + random(-4, 4)
      position.y = position.y + random(-4, 4)

    local fromPosition = Position(position.x + 1, position.y, position.z)
       fromPosition.x = position.x - 7
       fromPosition.y = position.y - 5

    local tile, getGround
    for Z = 1, 7 do
        fromPosition.z = Z
        position.z = Z

        tile = Tile(position)
        if tile then -- If there is a tile, stop checking floors
            fromPosition:sendDistanceEffect(position, fallEffect)
            position:sendMagicEffect(groundEffect, self)

            getGround = tile:getGround()
            if getGround and ItemType(getGround:getId()):getFluidSource() == 1 then
                position:sendMagicEffect(CONST_ME_WATERSPLASH, self)
            end
            break
        end
    end

    if thunderEffect and tile then
        if random(2) == 1 then
            local topCreature = tile:getTopCreature()

            if topCreature and topCreature:isPlayer() then
                position:sendMagicEffect(CONST_ME_BIGCLOUDS, self)
                doTargetCombatHealth(0, self, COMBAT_ENERGYDAMAGE, -weatherConfig.minDMG, -weatherConfig.maxDMG, CONST_ME_NONE)
                self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You were hit by lightning and lost some health.")
            end
        end
    end
end
How to use:
Code:
player:doSendWeatherEffect(weatherConfig.groundEffect, weatherConfig.fallEffect, weatherConfig.thunderEffect)
I'm open for suggestions and even maybe how to make the code even better.
may you make some scripts for 0.3.6? its would be nice from you
 
OP
Printer

Printer

if Printer then print("LUA") end
Premium User
Joined
Dec 27, 2009
Messages
5,728
Reaction score
1,985
Location
Sweden?
How to use it to call it global events ?
Yes, or onThink creaturescript or you can even make a new function that execute it as addEvent. Depends how you want it.
may you make some scripts for 0.3.6? its would be nice from you
Sorry, but i'm trying to make people using TFS 1.x and not shitty 0.3.
 

imback1

Unknown member
Joined
Jul 11, 2013
Messages
776
Reaction score
43
Yes, or onThink creaturescript or you can even make a new function that execute it as addEvent. Depends how you want it.

Sorry, but i'm trying to make people using TFS 1.x and not shitty 0.3.
0.3. isn't that bad as you think :D
 

Eldin

Eldin Projects
Joined
Jun 12, 2008
Messages
1,301
Reaction score
521
Location
Sweden
Thank you @Printer for the system and thank you @Ninja for this below.

To make more people use it directly:

globalevents.xml (The 200 made it natural in my Eyes)
Code:
 <globalevent name="Weather" interval="200" script="Weather.lua" />
Weather.lua

Code:
function onThink(interval, lastExecution)
 local players = Game.getPlayers()
 if #players == 0 then
 return true
 end

 local player
 for i = 1, #players do
 player = players[i]
 player:sendWeatherEffect(weatherConfig.groundEffect, weatherConfig.fallEffect, weatherConfig.thunderEffect)
 end
 return true
end
A question tho, is it possible to use "chance" or so at global? Lets say it should be a 5% every hour for the rain to start and it continues during a set 5 minutes or lets say at random for 5-60 minutes? (Maybe less if it takes alot on the server itself due to the effects) Anyone? :)

Kind Regards,
Eldin.
 

whitevo

Feeling good, thats what I do.
Joined
Jan 2, 2015
Messages
3,446
Reaction score
593
Location
Estonia
ofcourse.

Use global Variable: Weather = false
or something
and then in global event: if Weather == false then
duration = math.random(something, something)
and dont forget to add:
Weather = true
addEvent(function() return Weather=false end, duration)


i havent rly looked printers code (but i assume something like this can be added)
 

Joe Rod

JoeRod #1189
Joined
Mar 16, 2011
Messages
485
Reaction score
109
i did mine on 0.3.6 in this way:
It works with global storage.

-> a function reloadRainArea() who works with a table to check the area screen (getArea(...)), so i can update that area whenever i want.

Player::eek:nThink (creaturescript)
if globalStorage...
->sendEffectToArea(numberOfPositions)

Player::eek:nWalk(creaturescript)
if (globalStorage)
->reloadRainArea() --to reload the area when a player walks
 

FLE

Active Member
Joined
Oct 5, 2008
Messages
428
Reaction score
25
Location
Vancouver Canada
Hello friends,

@Printer
Is it possible too change the magic effect with an item that only appears momentarily?

and how do i go about making it rain once every 60 minutes for 5 minutes? :3

please help i'm clueless.
 

rocamalo

Member
Joined
Jan 12, 2010
Messages
94
Reaction score
8
Is it possible to change the graphics used? And if so how? And what software can i use to create my own? Thanks :D
 

StreamSide

Joseluis Gonzalez
Support Team
Joined
Aug 31, 2007
Messages
3,165
Reaction score
721
Location
Arica - Chile
noticed something testing a war server
change
Code:
if tile then
to
Code:
if tile and not tile:hasFlag(TILESTATE_PROTECTIONZONE) then
 
Top