• 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]

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,782
Solutions
31
Reaction score
2,284
Location
Sweden?
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.
 
Last edited by a moderator:
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 :)
 
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: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
 
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.
 
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
 
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.
 
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)
 
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
 
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.
 
Is it possible to change the graphics used? And if so how? And what software can i use to create my own? Thanks :D
 
noticed something testing a war server
change
Code:
if tile then
to
Code:
if tile and not tile:hasFlag(TILESTATE_PROTECTIONZONE) then
 
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

@Eldin, @Printer, it is possible to add this globalevent with the time interval, as a moveevent that activates when player step on tile? on example, i use a boat npc that teleport me as player to x=100 y=100 z=7, then, when i step on tile x=100, y=100, z=7 after being teleported the rain is activated... and when i leave the place, by traveling on the same npc, i get teleported and step on other tile, example, x=200 y=200 z=7, that make the rain stops...

the idea of this is to applicate the rain only on a certain icy island and not in the whole map... more simple
  • player step on tile uid 1234 and rain start
  • player step on tile uid 4321 and rain stop
the interval of 200 looks very good btw
 
Last edited:
Back
Top