• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Weather System [TFS 1.x]

Hi!, I am too stupid to use this without further instructions...so where exactly from "global.lua" should I put this code? It gives me a hell of a bunch of errors now when loading the server...and it seams to me a super nice system just to give up at the first try...

I have copied the code into my "global.lua" just before the last "return true", which should work, but I get the next error from the Weather.lua I am using, posted in this same thread!:
Bash:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/Weather.lua:onThink
data/globalevents/scripts/Weather.lua:11: attempt to index global 'weatherConfig' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/globalevents/scripts/Weather.lua:11: in function <data/globalevents/scripts/Weather.lua:1>
[Error - GlobalEvents::think] Failed to execute event: Weather

So I thought that the "Weather.lua", wasn't getting the "weatherConfig" because it was in a "global.lua" function...which I allready tried to change place but nope, it still give me the error!
 
Last edited:
Hello,

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


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.
can you make a spell out of that, changing weather in area and possibly other stuff?
 
Back
Top