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

[MOD] Pandora Box

Tuslawek

New Member
Joined
Aug 16, 2011
Messages
28
Reaction score
2
XML:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Pandora Box" version="1.2" author="Oskar" contact="[email protected]" enabled="yes">
<config name="pandoraBox_conf"><![CDATA[
pandoraBox = {
			monstersPositions = {
								leftTopCorner = {x=33236,y=31693,z=7},
								rightBottomCorner = {x=33247,y=31703,z=7}
								},
			pandoraBoxAccesToUseCommand = 4,
			--box config
			boxId = 9661,
			timeOnPutBox = 10, --in minutes
			chance = 100,
			pandoraBoxPosition = {x=33241,y=31698,z=7},
 
			--monsters config
			monstersName = {'dragon lord',25,'serpent spawn',8,'dragon',30}, --'name', chance, 'name1', chance1
			monstersSpawnCount = {10,20}, --{from, to}
 
			--waves config
			wavesCount = {2,4}, --{from, to}
			timeBetweenWaves = 60, --in seconds
 
			timeOnKillAllMonsters = 13, --in minutes
			timeOnGetRewards = 20, --in seconds
			bossPositionToSamePandoraBox = true,
			bossName = 'Pandora',
			pandoraGuards = 'warlock',
			pandoraGuardsCount = 10,
			expRateValue = 0.25,
			}
 
pandoraBoxRewards = {
				  --[vocationId] = {itemid, count, itemid1, count1, ...}
					[1] = {2160, 25, 9969, 1, 9932, 1}, --sorc
					[2] = {2160, 25, 9969, 1, 9932, 1}, --druid
					[3] = {2160, 25, 9969, 1, 9932, 100}, --pall
					[4] = {2160, 25, 9969, 1, 9932, 1}, --knight
					[5] = {2160, 30, 9969, 1, 9932, 1}, --ms
					[6] = {2160, 30, 9969, 1, 9932, 1}, --ed
					[7] = {2160, 30, 9969, 1, 9932, 1}, --rp
					[8] = {2160, 30, 9969, 1, 9932, 1}, --ek
					}
 
function getArea(pandoraBox)
local LTCx, LTCy, LTCz = pandoraBox.monstersPositions.leftTopCorner.x, pandoraBox.monstersPositions.leftTopCorner.y, pandoraBox.monstersPositions.leftTopCorner.z
local RBCx, RBCy, RBCz = pandoraBox.monstersPositions.rightBottomCorner.x, pandoraBox.monstersPositions.rightBottomCorner.y, pandoraBox.monstersPositions.rightBottomCorner.z
local centerPos, rangex, rangey = {x=(LTCx+RBCx)/2,y=(LTCy+RBCy)/2,z=(LTCz+RBCz)/2}, math.abs(RBCx-LTCx), math.abs(RBCy-LTCy)
return centerPos, rangex, rangey
end
 
function isWalkable(pos, creature, proj, pz)
if getTileThingByPos({x=pos.x,y=pos.y,z=pos.z,stackpos=0}).itemid == 0 then return false end
if getTopCreature(pos).uid > 0 and creature then return false end
if getTileInfo(pos).protection and pz then return false, true end
local n = not proj and 3 or 2
for i = 0, 255 do
	pos.stackpos = i
	local tile = getTileThingByPos(pos)
	if tile.itemid ~= 0 and not isCreature(tile.uid) then
		if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
			return false
		end
	end
end
return true
end
 
function checkPositions(fromPos, toPos, nb)
local pos = {x=math.random(fromPos.x,toPos.x), y=math.random(fromPos.y,toPos.y), z=math.random(fromPos.z,toPos.z)}
if isWalkable(pos, true, true, true) then
	return pos
end
return (nb < 200 and checkPositions(fromPos, toPos, nb+1) or pos)
end
 
function setMonster(pandoraBox)
for i = 1, #pandoraBox.monstersName/2 do
	local pos = checkPositions(pandoraBox.monstersPositions.leftTopCorner, pandoraBox.monstersPositions.rightBottomCorner, 0)
	if pos and math.random(100000) <= pandoraBox.monstersName[i*2]*1000 then
		local mon = doCreateMonster(pandoraBox.monstersName[i*2-1], pos, false, false, false)
		return (isCreature(mon) and doCreatureSetStorage(mon, 1000, 1) or true)
	end
end
return setMonster(pandoraBox)
end
 
function setPandoraBoxMonsters(pandoraBox)
for j = 1, math.random(pandoraBox.wavesCount[1], pandoraBox.wavesCount[2]) do
	addEvent(function()
			doBroadcastMessage('Next wave is raid on the city! Beware mortals, death come for you!')
			for i = 1, math.random(pandoraBox.monstersSpawnCount[1], pandoraBox.monstersSpawnCount[2]) do
				setMonster(pandoraBox)
			end return true end,
			(j == 1 and 1000 or pandoraBox.timeBetweenWaves * 1000 * (j-1)),
			pandoraBox
			)
end
return true
end
 
function setPandoraBox(pandoraBox)
if getStorage(5000) ~= -1 then 
	return addEvent(setPandoraBox, pandoraBox.timeOnPutBox * 60 * 1000, pandoraBox) end
if math.random(100000) <= pandoraBox.chance*1000 then
	doSetStorage(5000, 0)
	local item = doCreateItem(pandoraBox.boxId, pandoraBox.pandoraBoxPosition)
	doItemSetAttribute(item, 'uid', 2000)
	doItemSetAttribute(item, 'name', 'Pandora Box')
	return doBroadcastMessage('Pandora Box is appeared somewhere in the city!')
end
return doSetStorage(5000, -1) and addEvent(setPandoraBox, pandoraBox.timeOnPutBox * 60 * 1000, pandoraBox)
end
 
function checkMonsters(pandoraBox, n)
local centerPos, rangex, rangey = getArea(pandoraBox)
if getSpectators(centerPos, rangex, rangey) then
	for _, v in ipairs(getSpectators(centerPos, rangex, rangey)) do
		if isMonster(v) and getCreatureStorage(v, 1000) == 1 then
			for _, k in ipairs(getPlayersOnline()) do
				if n == 0 then
					doBroadcastMessage('Experience rate is to decreased by '.. pandoraBox.expRateValue * 100 ..' percent and not grow, until the evil from Pandora Box walk on the city.')
					n = 60
				end
				doPlayerSetExperienceRate(k, pandoraBox.expRateValue)
			end
			return addEvent(checkMonsters, 5000, pandoraBox, n - 1)
		end
	end
end
doBroadcastMessage('Evil from Pandora Box is defeated! '..pandoraBox.bossName..' in his own person be came to the city for revenage!')
local pand = doCreateMonster(pandoraBox.bossName, (pandoraBox.bossPositionToSamePandoraBox and pandoraBox.pandoraBoxPosition or checkPositions(pandoraBox.monstersPositions.leftTopCorner, pandoraBox.monstersPositions.rightBottomCorner, 0)), false, false, false)
local pos = getThingPos(pand)
for i = 1, pandoraBox.pandoraGuardsCount do
	pos.x = pos.x + math.random(-4,4)
	pos.y = pos.y + math.random(-4,4)
	doCreateMonster(pandoraBox.pandoraGuards, pos, false, false, false)
end
return (isMonster(pand) and registerCreatureEvent(pand, 'pandoraDeath') or false)
end
]]></config>
 
<event type="death" name="pandoraDeath" event="script"><![CDATA[
domodlib('pandoraBox_conf')
function onDeath(cid)
if getTileItemById(pandoraBox.pandoraBoxPosition, pandoraBox.boxId).uid == 2000 then
	item = getTileItemById(pandoraBox.pandoraBoxPosition, pandoraBox.boxId)
end
addEvent(function()
				doSetStorage(5000, -1)
				doBroadcastMessage('Pandora Box is disappeared from the world!')
				if getTileItemById(pandoraBox.pandoraBoxPosition, pandoraBox.boxId).uid == 2000 then
					return doRemoveItem(getTileItemById(pandoraBox.pandoraBoxPosition, pandoraBox.boxId).uid)
				end
				return true end,
				pandoraBox.timeOnGetRewards * 1000,
				pandoraBox
				)
return item and doItemSetAttribute(item.uid, 'pandoraBox', 1000) and doBroadcastMessage('The ancient evil has been defeated! The Pandora\'s Box are the reward for each, but only for '..timeOnGetRewards..' seconds!') or true
end
]]></event>
 
<action uniqueid="2000" event="script"><![CDATA[
domodlib('pandoraBox_conf')
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.itemid == pandoraBox.boxId and getItemAttribute(item.uid, 'pandoraBox') == nil then
	doItemSetAttribute(item.uid, 'pandoraBox', 500)
	addEvent(checkMonsters, pandoraBox.timeOnKillAllMonsters * 1000 * 60, pandoraBox, 0)
	return setPandoraBoxMonsters(pandoraBox)
elseif item.itemid == pandoraBox.boxId and getItemAttribute(item.uid, 'pandoraBox') == 1000 then
	if getPlayerStorageValue(cid, 150) ~= -1 then
		return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It\'s empty.') end
	if pandoraBoxRewards[getPlayerVocation(cid)] then
		doPlayerSetStorageValue(cid, 150, 0)
		msg = 'You have found '
		for i = 1, #pandoraBoxRewards[getPlayerVocation(cid)]/2 do
			msg = msg .. getItemNameById(pandoraBoxRewards[getPlayerVocation(cid)][i*2-1]) .. (i < #pandoraBoxRewards[getPlayerVocation(cid)]/2-1 and ', ' or i == #pandoraBoxRewards[getPlayerVocation(cid)]/2-1 and ' and ' or '.')
			doPlayerAddItem(cid, pandoraBoxRewards[getPlayerVocation(cid)][i*2-1], pandoraBoxRewards[getPlayerVocation(cid)][i*2])
		end
		return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg)
	end
end
return false
end
]]></action>
 
<globalevent name="pandoraTime" time="20:00" event="script"><![CDATA[
domodlib("pandoraBox_conf")
function onTime(time)
return doSetStorage(5000, -1) and setPandoraBox(pandoraBox)
end
]]></globalevent>
 
<talkaction words="!pandoraBox" event="script"><![CDATA[
domodlib('pandoraBox_conf')
function onSay(cid, words, param, channel)
return getPlayerAccess(cid) >= pandoraBox.pandoraBoxAccesToUseCommand and doSetStorage(5000, -1) and setPandoraBox(pandoraBox) or true 
end
]]></talkaction>
</mod>

When i kill the final box this error pops in the console. I was trying to figure it why it happens but script wasn't created by me so I am unable to clarify what is wrong.

Error:
Lua:
[19/12/2012 18:44:33] [Error - CreatureScript Interface] 
[19/12/2012 18:44:33] buffer:onDeath
[19/12/2012 18:44:33] Description: 
[19/12/2012 18:44:33] [string "loadBuffer"]:16: attempt to concatenate global 'timeOnGetRewards' (a nil value)
[19/12/2012 18:44:33] stack traceback:
[19/12/2012 18:44:33] [string "loadBuffer"]:16: in function <[string "loadBuffer"]:2>
[19/12/2012 18:44:53] > Broadcasted message: "Pandora Box is disappeared from the world!".
the code above is from other topic because i am running my server on Linux so I was unable to get the error out of it.
 
Last edited:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Pandora Box" version="1.2" author="Oskar" contact="[email protected]" enabled="yes">
<config name="pandoraBox_conf"><![CDATA[
pandoraBox = {
			monstersPositions = {
								leftTopCorner = {x=33236,y=31693,z=7},
								rightBottomCorner = {x=33247,y=31703,z=7}
								},
			pandoraBoxAccesToUseCommand = 4,
			--box config
			boxId = 9661,
			timeOnPutBox = 10, --in minutes
			chance = 100,
			pandoraBoxPosition = {x=33241,y=31698,z=7},
 
			--monsters config
			monstersName = {'dragon lord',25,'serpent spawn',8,'dragon',30}, --'name', chance, 'name1', chance1
			monstersSpawnCount = {10,20}, --{from, to}
 
			--waves config
			wavesCount = {2,4}, --{from, to}
			timeBetweenWaves = 60, --in seconds
 
			timeOnKillAllMonsters = 13, --in minutes
			timeOnGetRewards = 20, --in seconds
			bossPositionToSamePandoraBox = true,
			bossName = 'Pandora',
			pandoraGuards = 'warlock',
			pandoraGuardsCount = 10,
			expRateValue = 0.25,
			}
 
pandoraBoxRewards = {
				  --[vocationId] = {itemid, count, itemid1, count1, ...}
					[1] = {2160, 25, 9969, 1, 9932, 1}, --sorc
					[2] = {2160, 25, 9969, 1, 9932, 1}, --druid
					[3] = {2160, 25, 9969, 1, 9932, 100}, --pall
					[4] = {2160, 25, 9969, 1, 9932, 1}, --knight
					[5] = {2160, 30, 9969, 1, 9932, 1}, --ms
					[6] = {2160, 30, 9969, 1, 9932, 1}, --ed
					[7] = {2160, 30, 9969, 1, 9932, 1}, --rp
					[8] = {2160, 30, 9969, 1, 9932, 1}, --ek
					}
 
function getArea(pandoraBox)
local LTCx, LTCy, LTCz = pandoraBox.monstersPositions.leftTopCorner.x, pandoraBox.monstersPositions.leftTopCorner.y, pandoraBox.monstersPositions.leftTopCorner.z
local RBCx, RBCy, RBCz = pandoraBox.monstersPositions.rightBottomCorner.x, pandoraBox.monstersPositions.rightBottomCorner.y, pandoraBox.monstersPositions.rightBottomCorner.z
local centerPos, rangex, rangey = {x=(LTCx+RBCx)/2,y=(LTCy+RBCy)/2,z=(LTCz+RBCz)/2}, math.abs(RBCx-LTCx), math.abs(RBCy-LTCy)
return centerPos, rangex, rangey
end
 
function isWalkable(pos, creature, proj, pz)
if getTileThingByPos({x=pos.x,y=pos.y,z=pos.z,stackpos=0}).itemid == 0 then return false end
if getTopCreature(pos).uid > 0 and creature then return false end
if getTileInfo(pos).protection and pz then return false, true end
local n = not proj and 3 or 2
for i = 0, 255 do
	pos.stackpos = i
	local tile = getTileThingByPos(pos)
	if tile.itemid ~= 0 and not isCreature(tile.uid) then
		if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
			return false
		end
	end
end
return true
end
 
function checkPositions(fromPos, toPos, nb)
local pos = {x=math.random(fromPos.x,toPos.x), y=math.random(fromPos.y,toPos.y), z=math.random(fromPos.z,toPos.z)}
if isWalkable(pos, true, true, true) then
	return pos
end
return (nb < 200 and checkPositions(fromPos, toPos, nb+1) or pos)
end
 
function setMonster(pandoraBox)
for i = 1, #pandoraBox.monstersName/2 do
	local pos = checkPositions(pandoraBox.monstersPositions.leftTopCorner, pandoraBox.monstersPositions.rightBottomCorner, 0)
	if pos and math.random(100000) <= pandoraBox.monstersName[i*2]*1000 then
		local mon = doCreateMonster(pandoraBox.monstersName[i*2-1], pos, false, false, false)
		return (isCreature(mon) and doCreatureSetStorage(mon, 1000, 1) or true)
	end
end
return setMonster(pandoraBox)
end
 
function setPandoraBoxMonsters(pandoraBox)
for j = 1, math.random(pandoraBox.wavesCount[1], pandoraBox.wavesCount[2]) do
	addEvent(function()
			doBroadcastMessage('Next wave is raid on the city! Beware mortals, death come for you!')
			for i = 1, math.random(pandoraBox.monstersSpawnCount[1], pandoraBox.monstersSpawnCount[2]) do
				setMonster(pandoraBox)
			end return true end,
			(j == 1 and 1000 or pandoraBox.timeBetweenWaves * 1000 * (j-1)),
			pandoraBox
			)
end
return true
end
 
function setPandoraBox(pandoraBox)
if getStorage(5000) ~= -1 then 
	return addEvent(setPandoraBox, pandoraBox.timeOnPutBox * 60 * 1000, pandoraBox) end
if math.random(100000) <= pandoraBox.chance*1000 then
	doSetStorage(5000, 0)
	local item = doCreateItem(pandoraBox.boxId, pandoraBox.pandoraBoxPosition)
	doItemSetAttribute(item, 'uid', 2000)
	doItemSetAttribute(item, 'name', 'Pandora Box')
	return doBroadcastMessage('Pandora Box is appeared somewhere in the city!')
end
return doSetStorage(5000, -1) and addEvent(setPandoraBox, pandoraBox.timeOnPutBox * 60 * 1000, pandoraBox)
end
 
function checkMonsters(pandoraBox, n)
local centerPos, rangex, rangey = getArea(pandoraBox)
if getSpectators(centerPos, rangex, rangey) then
	for _, v in ipairs(getSpectators(centerPos, rangex, rangey)) do
		if isMonster(v) and getCreatureStorage(v, 1000) == 1 then
			for _, k in ipairs(getPlayersOnline()) do
				if n == 0 then
					doBroadcastMessage('Experience rate is to decreased by '.. pandoraBox.expRateValue * 100 ..' percent and not grow, until the evil from Pandora Box walk on the city.')
					n = 60
				end
				doPlayerSetExperienceRate(k, pandoraBox.expRateValue)
			end
			return addEvent(checkMonsters, 5000, pandoraBox, n - 1)
		end
	end
end
doBroadcastMessage('Evil from Pandora Box is defeated! '..pandoraBox.bossName..' in his own person be came to the city for revenage!')
local pand = doCreateMonster(pandoraBox.bossName, (pandoraBox.bossPositionToSamePandoraBox and pandoraBox.pandoraBoxPosition or checkPositions(pandoraBox.monstersPositions.leftTopCorner, pandoraBox.monstersPositions.rightBottomCorner, 0)), false, false, false)
local pos = getThingPos(pand)
for i = 1, pandoraBox.pandoraGuardsCount do
	pos.x = pos.x + math.random(-4,4)
	pos.y = pos.y + math.random(-4,4)
	doCreateMonster(pandoraBox.pandoraGuards, pos, false, false, false)
end
return (isMonster(pand) and registerCreatureEvent(pand, 'pandoraDeath') or false)
end
]]></config>
 
<event type="death" name="pandoraDeath" event="script"><![CDATA[
domodlib('pandoraBox_conf')
function onDeath(cid)
if getTileItemById(pandoraBox.pandoraBoxPosition, pandoraBox.boxId).uid == 2000 then
	item = getTileItemById(pandoraBox.pandoraBoxPosition, pandoraBox.boxId)
end
addEvent(function()
				doSetStorage(5000, -1)
				doBroadcastMessage('Pandora Box is disappeared from the world!')
				if getTileItemById(pandoraBox.pandoraBoxPosition, pandoraBox.boxId).uid == 2000 then
					return doRemoveItem(getTileItemById(pandoraBox.pandoraBoxPosition, pandoraBox.boxId).uid)
				end
				return true end,
				pandoraBox.timeOnGetRewards * 1000,
				pandoraBox
				)
return item and doItemSetAttribute(item.uid, 'pandoraBox', 1000) and doBroadcastMessage('The ancient evil has been defeated! The Pandora\'s Box are the reward for each, but only for '..pandoraBox.timeOnGetRewards..' seconds!') or true
end
]]></event>
 
<action uniqueid="2000" event="script"><![CDATA[
domodlib('pandoraBox_conf')
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.itemid == pandoraBox.boxId and getItemAttribute(item.uid, 'pandoraBox') == nil then
	doItemSetAttribute(item.uid, 'pandoraBox', 500)
	addEvent(checkMonsters, pandoraBox.timeOnKillAllMonsters * 1000 * 60, pandoraBox, 0)
	return setPandoraBoxMonsters(pandoraBox)
elseif item.itemid == pandoraBox.boxId and getItemAttribute(item.uid, 'pandoraBox') == 1000 then
	if getPlayerStorageValue(cid, 150) ~= -1 then
		return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'It\'s empty.') end
	if pandoraBoxRewards[getPlayerVocation(cid)] then
		doPlayerSetStorageValue(cid, 150, 0)
		msg = 'You have found '
		for i = 1, #pandoraBoxRewards[getPlayerVocation(cid)]/2 do
			msg = msg .. getItemNameById(pandoraBoxRewards[getPlayerVocation(cid)][i*2-1]) .. (i < #pandoraBoxRewards[getPlayerVocation(cid)]/2-1 and ', ' or i == #pandoraBoxRewards[getPlayerVocation(cid)]/2-1 and ' and ' or '.')
			doPlayerAddItem(cid, pandoraBoxRewards[getPlayerVocation(cid)][i*2-1], pandoraBoxRewards[getPlayerVocation(cid)][i*2])
		end
		return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg)
	end
end
return false
end
]]></action>
 
<globalevent name="pandoraTime" time="20:00" event="script"><![CDATA[
domodlib("pandoraBox_conf")
function onTime(time)
return doSetStorage(5000, -1) and setPandoraBox(pandoraBox)
end
]]></globalevent>
 
<talkaction words="!pandoraBox" event="script"><![CDATA[
domodlib('pandoraBox_conf')
function onSay(cid, words, param, channel)
return getPlayerAccess(cid) >= pandoraBox.pandoraBoxAccesToUseCommand and doSetStorage(5000, -1) and setPandoraBox(pandoraBox) or true 
end
]]></talkaction>
</mod>
 
one more question the code above fixed the whole error bit but i am just wondering why when i try to make the pandora event again, I can't take the reward? It says "It's Empty"
 
That happen because your player got a storage when uses the Pandora Box, This edit remove that problem

XML:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Pandora Box" version="1.2" author="Oskar" contact="[email protected]" enabled="yes">
<config name="pandoraBox_conf"><![CDATA[
pandoraBox = {
			monstersPositions = {
								leftTopCorner = {x=33236,y=31693,z=7},
								rightBottomCorner = {x=33247,y=31703,z=7}
								},
			pandoraBoxAccesToUseCommand = 4,
			--box config
			boxId = 9661,
			timeOnPutBox = 10, --in minutes
			chance = 100,
			pandoraBoxPosition = {x=33241,y=31698,z=7},
 
			--monsters config
			monstersName = {'dragon lord',25,'serpent spawn',8,'dragon',30}, --'name', chance, 'name1', chance1
			monstersSpawnCount = {10,20}, --{from, to}
 
			--waves config
			wavesCount = {2,4}, --{from, to}
			timeBetweenWaves = 60, --in seconds
 
			timeOnKillAllMonsters = 13, --in minutes
			timeOnGetRewards = 20, --in seconds
			bossPositionToSamePandoraBox = true,
			bossName = 'Pandora',
			pandoraGuards = 'warlock',
			pandoraGuardsCount = 10,
			expRateValue = 0.25,
			}
 
pandoraBoxRewards = {
				  --[vocationId] = {itemid, count, itemid1, count1, ...}
					[1] = {2160, 25, 9969, 1, 9932, 1}, --sorc
					[2] = {2160, 25, 9969, 1, 9932, 1}, --druid
					[3] = {2160, 25, 9969, 1, 9932, 100}, --pall
					[4] = {2160, 25, 9969, 1, 9932, 1}, --knight
					[5] = {2160, 30, 9969, 1, 9932, 1}, --ms
					[6] = {2160, 30, 9969, 1, 9932, 1}, --ed
					[7] = {2160, 30, 9969, 1, 9932, 1}, --rp
					[8] = {2160, 30, 9969, 1, 9932, 1}, --ek
					}
 
function getArea(pandoraBox)
local LTCx, LTCy, LTCz = pandoraBox.monstersPositions.leftTopCorner.x, pandoraBox.monstersPositions.leftTopCorner.y, pandoraBox.monstersPositions.leftTopCorner.z
local RBCx, RBCy, RBCz = pandoraBox.monstersPositions.rightBottomCorner.x, pandoraBox.monstersPositions.rightBottomCorner.y, pandoraBox.monstersPositions.rightBottomCorner.z
local centerPos, rangex, rangey = {x=(LTCx+RBCx)/2,y=(LTCy+RBCy)/2,z=(LTCz+RBCz)/2}, math.abs(RBCx-LTCx), math.abs(RBCy-LTCy)
return centerPos, rangex, rangey
end
 
function isWalkable(pos, creature, proj, pz)
if getTileThingByPos({x=pos.x,y=pos.y,z=pos.z,stackpos=0}).itemid == 0 then return false end
if getTopCreature(pos).uid > 0 and creature then return false end
if getTileInfo(pos).protection and pz then return false, true end
local n = not proj and 3 or 2
for i = 0, 255 do
	pos.stackpos = i
	local tile = getTileThingByPos(pos)
	if tile.itemid ~= 0 and not isCreature(tile.uid) then
		if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
			return false
		end
	end
end
return true
end
 
function checkPositions(fromPos, toPos, nb)
local pos = {x=math.random(fromPos.x,toPos.x), y=math.random(fromPos.y,toPos.y), z=math.random(fromPos.z,toPos.z)}
if isWalkable(pos, true, true, true) then
	return pos
end
return (nb < 200 and checkPositions(fromPos, toPos, nb+1) or pos)
end
 
function setMonster(pandoraBox)
for i = 1, #pandoraBox.monstersName/2 do
	local pos = checkPositions(pandoraBox.monstersPositions.leftTopCorner, pandoraBox.monstersPositions.rightBottomCorner, 0)
	if pos and math.random(100000) <= pandoraBox.monstersName[i*2]*1000 then
		local mon = doCreateMonster(pandoraBox.monstersName[i*2-1], pos, false, false, false)
		return (isCreature(mon) and doCreatureSetStorage(mon, 1000, 1) or true)
	end
end
return setMonster(pandoraBox)
end
 
function setPandoraBoxMonsters(pandoraBox)
for j = 1, math.random(pandoraBox.wavesCount[1], pandoraBox.wavesCount[2]) do
	addEvent(function()
			doBroadcastMessage('Next wave is raid on the city! Beware mortals, death come for you!')
			for i = 1, math.random(pandoraBox.monstersSpawnCount[1], pandoraBox.monstersSpawnCount[2]) do
				setMonster(pandoraBox)
			end return true end,
			(j == 1 and 1000 or pandoraBox.timeBetweenWaves * 1000 * (j-1)),
			pandoraBox
			)
end
return true
end
 
function setPandoraBox(pandoraBox)
if getStorage(5000) ~= -1 then 
	return addEvent(setPandoraBox, pandoraBox.timeOnPutBox * 60 * 1000, pandoraBox) end
if math.random(100000) <= pandoraBox.chance*1000 then
	doSetStorage(5000, 0)
	local item = doCreateItem(pandoraBox.boxId, pandoraBox.pandoraBoxPosition)
	doItemSetAttribute(item, 'uid', 2000)
	doItemSetAttribute(item, 'name', 'Pandora Box')
	return doBroadcastMessage('Pandora Box is appeared somewhere in the city!')
end
return doSetStorage(5000, -1) and addEvent(setPandoraBox, pandoraBox.timeOnPutBox * 60 * 1000, pandoraBox)
end
 
function checkMonsters(pandoraBox, n)
local centerPos, rangex, rangey = getArea(pandoraBox)
if getSpectators(centerPos, rangex, rangey) then
	for _, v in ipairs(getSpectators(centerPos, rangex, rangey)) do
		if isMonster(v) and getCreatureStorage(v, 1000) == 1 then
			for _, k in ipairs(getPlayersOnline()) do
				if n == 0 then
					doBroadcastMessage('Experience rate is to decreased by '.. pandoraBox.expRateValue * 100 ..' percent and not grow, until the evil from Pandora Box walk on the city.')
					n = 60
				end
				doPlayerSetExperienceRate(k, pandoraBox.expRateValue)
			end
			return addEvent(checkMonsters, 5000, pandoraBox, n - 1)
		end
	end
end
doBroadcastMessage('Evil from Pandora Box is defeated! '..pandoraBox.bossName..' in his own person be came to the city for revenage!')
local pand = doCreateMonster(pandoraBox.bossName, (pandoraBox.bossPositionToSamePandoraBox and pandoraBox.pandoraBoxPosition or checkPositions(pandoraBox.monstersPositions.leftTopCorner, pandoraBox.monstersPositions.rightBottomCorner, 0)), false, false, false)
local pos = getThingPos(pand)
for i = 1, pandoraBox.pandoraGuardsCount do
	pos.x = pos.x + math.random(-4,4)
	pos.y = pos.y + math.random(-4,4)
	doCreateMonster(pandoraBox.pandoraGuards, pos, false, false, false)
end
return (isMonster(pand) and registerCreatureEvent(pand, 'pandoraDeath') or false)
end
]]></config>
 
<event type="death" name="pandoraDeath" event="script"><![CDATA[
domodlib('pandoraBox_conf')
function onDeath(cid)
if getTileItemById(pandoraBox.pandoraBoxPosition, pandoraBox.boxId).uid == 2000 then
	item = getTileItemById(pandoraBox.pandoraBoxPosition, pandoraBox.boxId)
end
addEvent(function()
				doSetStorage(5000, -1)
				doBroadcastMessage('Pandora Box is disappeared from the world!')
				if getTileItemById(pandoraBox.pandoraBoxPosition, pandoraBox.boxId).uid == 2000 then
					return doRemoveItem(getTileItemById(pandoraBox.pandoraBoxPosition, pandoraBox.boxId).uid)
				end
				return true end,
				pandoraBox.timeOnGetRewards * 1000,
				pandoraBox
				)
return item and doItemSetAttribute(item.uid, 'pandoraBox', 1000) and doBroadcastMessage('The ancient evil has been defeated! The Pandora\'s Box are the reward for each, but only for '..pandoraBox.timeOnGetRewards..' seconds!') or true
end
]]></event>
 
<action uniqueid="2000" event="script"><![CDATA[
domodlib('pandoraBox_conf')
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.itemid == pandoraBox.boxId and getItemAttribute(item.uid, 'pandoraBox') == nil then
	doItemSetAttribute(item.uid, 'pandoraBox', 500)
	addEvent(checkMonsters, pandoraBox.timeOnKillAllMonsters * 1000 * 60, pandoraBox, 0)
	return setPandoraBoxMonsters(pandoraBox)
elseif item.itemid == pandoraBox.boxId and getItemAttribute(item.uid, 'pandoraBox') == 1000 then
	if pandoraBoxRewards[getPlayerVocation(cid)] then
		msg = 'You have found '
		for i = 1, #pandoraBoxRewards[getPlayerVocation(cid)]/2 do
			msg = msg .. getItemNameById(pandoraBoxRewards[getPlayerVocation(cid)][i*2-1]) .. (i < #pandoraBoxRewards[getPlayerVocation(cid)]/2-1 and ', ' or i == #pandoraBoxRewards[getPlayerVocation(cid)]/2-1 and ' and ' or '.')
			doPlayerAddItem(cid, pandoraBoxRewards[getPlayerVocation(cid)][i*2-1], pandoraBoxRewards[getPlayerVocation(cid)][i*2])
		end
		return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg)
	end
end
return false
end
]]></action>
 
<globalevent name="pandoraTime" time="20:00" event="script"><![CDATA[
domodlib("pandoraBox_conf")
function onTime(time)
return doSetStorage(5000, -1) and setPandoraBox(pandoraBox)
end
]]></globalevent>
 
<talkaction words="!pandoraBox" event="script"><![CDATA[
domodlib('pandoraBox_conf')
function onSay(cid, words, param, channel)
return getPlayerAccess(cid) >= pandoraBox.pandoraBoxAccesToUseCommand and doSetStorage(5000, -1) and setPandoraBox(pandoraBox) or true 
end
]]></talkaction>
</mod>
 
Back
Top