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

GlobalEvent Rain Sistem

Elexonic

Well-Known Member
Joined
Jun 18, 2008
Messages
1,920
Reaction score
59
Hello everyone :)
I bring this script created by kaotar ^^


Tested in: 0.3.6+


Install->

1º data / lib / and create a new file called rain.lua


PHP:
-- Features:
	-- chance = OBJECT.chance = INT
	-- createItem = OBJECT.createItem = {chance = INT, item = {itemid = INT, type = INT}}
 
 
Rain = {ignoreIds = {4526}}
 
function Rain:new()
    local obj = {}
    setmetatable(obj, self)
    self.__index = self
	return obj
end
function Rain:getPositionInArea(fromPos, toPos)
	self.positions = {}
	for Y = fromPos.y, toPos.y do
		for X = fromPos.x, toPos.x do
			if (getTileThingByPos({x=X, y=Y, z=7, stackpos=0}).itemid ~= 0) then
				if not (string.match(string.lower(getItemNameById(getTileThingByPos({x=X, y=Y, z=7, stackpos=0}).itemid)), "water")) then
					table.insert(self.positions, {x=X, y=Y, z=Z})
				end
			end
		end
	end
	return true
end
 
function Rain:doRain(position, disteffect, effect)
	if (self.duraction ~= self.executed) then
		local chance = self.chance or 100
		if (math.random(0, 1000) <= chance) then
			for Z = 0, 7 do
				if (getTileThingByPos(({x = position.x, y = position.y, z = Z})).itemid ~= 0) then
					doSendDistanceShoot({x = position.x - 7, y = position.y - 5, z = Z}, {x = position.x, y = position.y, z = Z}, disteffect)
					doSendMagicEffect({x = position.x, y = position.y, z = Z}, effect)
					if (self.createItem) then
						if (math.random(0, 1000) <= self.createItem.chance) then
							if (isInArray(self.ignoreIds, getTileThingByPos({x=X, y=Y, z=Z, stackpos=0}).itemid) == FALSE) then
								local item = doCreateItem(self.createItem.item.itemid, self.createItem.item.type, {x=position.x, y=position.y, z=Z})
								doDecayItem(item)
							end
						end
					end
					break
				end
			end
		end
		return true
	else
		return false
	end
end
 
function Rain:start(positions, effects, duraction, delay, var)
	self:getPositionInArea(positions.fromPos, positions.toPos)
	if not (self.positions[1]) then
		return false
	end
	self.delay = delay
	self.var = var or self
	self.effects = effects
	self.duraction = duraction
	self.executed = 0
	addEvent(doCallback, self.delay, {var=self.var})
	return true
end
 
function doCallback(p)
	for _, v in pairs(p.var.positions) do
		if not (p.var:doRain(v, p.var.effects.disteffect, p.var.effects.effect)) then
			return true
		end
	end
	addEvent(doCallback, p.var.delay, {var=p.var})
	p.var.executed = p.var.executed+1
end

Go data/glovalevent/ and create a new file called rain.lua

PHP:
local rain = Rain:new()
 
function onThink(interval, lastExecution)
	local minX = 990
	local minY = 993
	local maxX = 1008
	local maxY = 1006
 
	local frompos = {x=math.random(minX, maxX), y=math.random(minY, maxY), z=7}
	local topos = {x=math.random(frompos.x, maxX), y=math.random(frompos.y, maxY), z=7}
 
	local effects = {
		snow = {
			disteffect = CONST_ANI_SNOWBALL,
			effect = CONST_ME_ENERGYAREA
		},
		rain = {
			disteffect = CONST_ANI_ICE,
			effect = CONST_ME_LOSEENERGY
 
		}
	}
	random = math.random(0, 10)
	if (random == 0) then
		rain.chance = math.random(10,50)
		rain:start({fromPos = frompos, toPos = topos}, effects.snow, 300, math.random(100, 500))
	else
		rain.chance = math.random(40,100)
		rain.createItem = {chance = math.random(0,10), item = {itemid = 2016, type = 1}}
		rain:start({fromPos = frompos, toPos = topos}, effects.rain, math.random(300, 1000), math.random(100, 350))
	end
	return TRUE
end

3º data/glovalevent.xml add:

Code:
<globalevent name="rain" interval="200" event="script" value="rain.lua"/>

4º data \ globalevents \ lib and there create a file called rain.lua

PHP:
-- Features:
	-- chance = OBJECT.chance = INT
	-- createItem = OBJECT.createItem = {chance = INT, item = {itemid = INT, type = INT}}
 
 
Rain = {ignoreIds = {4526}}
 
function Rain:new()
    local obj = {}
    setmetatable(obj, self)
    self.__index = self
	return obj
end
function Rain:getPositionInArea(fromPos, toPos)
	self.positions = {}
	for Y = fromPos.y, toPos.y do
		for X = fromPos.x, toPos.x do
			if (getTileThingByPos({x=X, y=Y, z=7, stackpos=0}).itemid ~= 0) then
				if not (string.match(string.lower(getItemNameById(getTileThingByPos({x=X, y=Y, z=7, stackpos=0}).itemid)), "water")) then
					table.insert(self.positions, {x=X, y=Y, z=Z})
				end
			end
		end
	end
	return true
end
 
function Rain:doRain(position, disteffect, effect)
	if (self.duraction ~= self.executed) then
		local chance = self.chance or 100
		if (math.random(0, 1000) <= chance) then
			for Z = 0, 7 do
				if (getTileThingByPos(({x = position.x, y = position.y, z = Z})).itemid ~= 0) then
					doSendDistanceShoot({x = position.x - 7, y = position.y - 5, z = Z}, {x = position.x, y = position.y, z = Z}, disteffect)
					doSendMagicEffect({x = position.x, y = position.y, z = Z}, effect)
					if (self.createItem) then
						if (math.random(0, 1000) <= self.createItem.chance) then
							if (isInArray(self.ignoreIds, getTileThingByPos({x=X, y=Y, z=Z, stackpos=0}).itemid) == FALSE) then
								local item = doCreateItem(self.createItem.item.itemid, self.createItem.item.type, {x=position.x, y=position.y, z=Z})
								doDecayItem(item)
							end
						end
					end
					break
				end
			end
		end
		return true
	else
		return false
	end
end
 
function Rain:start(positions, effects, duraction, delay, var)
	self:getPositionInArea(positions.fromPos, positions.toPos)
	if not (self.positions[1]) then
		return false
	end
	self.delay = delay
	self.var = var or self
	self.effects = effects
	self.duraction = duraction
	self.executed = 0
	addEvent(doCallback, self.delay, {var=self.var})
	return true
end
 
function doCallback(p)
	for _, v in pairs(p.var.positions) do
		if not (p.var:doRain(v, p.var.effects.disteffect, p.var.effects.effect)) then
			return true
		end
	end
	addEvent(doCallback, p.var.delay, {var=p.var})
	p.var.executed = p.var.executed+1
end


Configuration:

Open /data/glovalevent
Code:
[COLOR="Red"]local minX = 0 
local minY = 0[/COLOR]
[COLOR="Yellow"]local maxX = 0
local maxY = 0[/COLOR]

Set positions with the rme, as indicated by the colors = D
105Dibujo.bmp



You can configure the time between rain in glovalevent.xml intervall and ramdon here
Code:
rain.chance = Math.random (20.100)


You can also change the item you created in the soil and creates effector
rain.createItem = {chance = math.random(0,10), item = {itemid = 2016, type = 1}}

And

local effects = {
snow = {
disteffect = CONST_ANI_SNOWBALL,
effect = CONST_ME_ENERGYAREA
},
rain = {
disteffect = CONST_ANI_ICE,
effect = CONST_ME_LOSEENERGY



With its system of rain that they worked perfectly :)

An image of what it is :p

images


I hope you like it :D


Rep++


Elexonic
 
Last edited:
Haha naa it does not make server lagg at all, question tho. Can I make it to one big rain over lets say a whole city at the same time? My rain jumps from place to place I want the whole area to rain at the same time :>

Thanks, Appz
 
Ok, but this script is my...
Where is my credits?

Bye bye
 
Last edited:
Haha naa it does not make server lagg at all, question tho. Can I make it to one big rain over lets say a whole city at the same time? My rain jumps from place to place I want the whole area to rain at the same time :>

Thanks, Appz

yes, when you do the whole city the server will lagg
 
this script was released at otserv networks and you shouldn't have released it unless you had permission from the author of it..

if you did then im sorry.
 
this script was released at otserv networks and you shouldn't have released it unless you had permission from the author of it..

if you did then im sorry.
he doesn't need it
kaotar does not forbid anybody to post it anywhere
and OP posted credits ;)
 
Error help me in fixing it

[20/06/2010 01:51:06] [Error - GlobalEvent Interface]
[20/06/2010 01:51:06] data/globalevents/scripts/rain.lua:eek:nThink
[20/06/2010 01:51:06] Description:
[20/06/2010 01:51:06] data/globalevents/scripts/rain.lua:9: bad argument #2 to 'random' (interval is empty)
[20/06/2010 01:51:06] stack traceback:
[20/06/2010 01:51:06] [C]: in function 'random'
[20/06/2010 01:51:06] data/globalevents/scripts/rain.lua:9: in function <data/globalevents/scripts/rain.lua:3>
[20/06/2010 01:51:06] [Error - GlobalEvents::think] Couldn't execute event: rain

[20/06/2010 01:51:37] [Error - GlobalEvent Interface]
[20/06/2010 01:51:37] data/globalevents/scripts/rain.lua:eek:nThink
[20/06/2010 01:51:37] Description:
[20/06/2010 01:51:37] data/globalevents/scripts/rain.lua:9: bad argument #2 to 'random' (interval is empty)
[20/06/2010 01:51:37] stack traceback:
[20/06/2010 01:51:37] [C]: in function 'random'
[20/06/2010 01:51:37] data/globalevents/scripts/rain.lua:9: in function <data/globalevents/scripts/rain.lua:3>
[20/06/2010 01:51:37] [Error - GlobalEvents::think] Couldn't execute event: rain

[20/06/2010 01:52:08] [Error - GlobalEvent Interface]
[20/06/2010 01:52:08] data/globalevents/scripts/rain.lua:eek:nThink
[20/06/2010 01:52:08] Description:
[20/06/2010 01:52:08] data/globalevents/scripts/rain.lua:9: bad argument #2 to 'random' (interval is empty)
[20/06/2010 01:52:08] stack traceback:
[20/06/2010 01:52:08] [C]: in function 'random'
[20/06/2010 01:52:08] data/globalevents/scripts/rain.lua:9: in function <data/globalevents/scripts/rain.lua:3>
[20/06/2010 01:52:08] [Error - GlobalEvents::think] Couldn't execute event: rain


And i got other idea it could be snow ball + ice on floor
 
Up: No Thunder no. .. the script is only the image as the effects in the image. You can change the file glovalevent


364lluviaa.bmp
 
Back
Top