-- BOSS BAILOUT
-- By: Evan @ otland.net
local goldCoins = {
[2148] = {worth = 1},
[2152] = {worth = 100},
[2160] = {worth = 10000}
}
-- This function was made to remove a creature from the jail (to make it look more realistic) --
function removeCreature()
for x = 1045, 1051 do
for y = 1034, 1040 do
local a = getTopCreature({x=x, y=y, z=9}).uid
if a ~= 0 and isMonster(a) then
doRemoveCreature(a)
end
end
end
return true
end
-- This function is used when the amount of gold is reached --
function doSomething()
doCreateMonster(newBoss[randomChance], newBossLocation)
doBroadcastMessage(releaseMessage, advance)
setGlobalStorageValue(goldStore, 0)
doSetItemSpecialDescription(object.uid, "There are 0 gold coins in here.\n"..(targetCount).." more gold coins is needed.")
removeCreature()
return true
end
-- Main function --
function onAddItem(moveitem, tileitem, position)
-- YOU CAN CHANGE ANYTHING HERE --
goldStore = 8890 -- The storage ID of where the amount of gold is stored
pos = {x = 1043, y = 1045, z = 8, stackpos = 2} -- Location of the sign
targetCount = 10500000 -- The amount of gold that is required to doSomething()
newBoss = {'Ghazbaran', 'Demon', 'Orc', 'Warlock'} -- The boss that will be bailed out
newBossLocation = {x = 1025, y = 1036, z = 7} -- The location where the boss will be summoned
randomChance = math.random(1, #newBoss)
releaseMessage = "It was a hefty payment, but the " ..(newBoss[randomChance]).. " has been bailed out!" -- The message sent when the boss is bailed out
-- DO NOT CHANGE ANYTHING HERE UNLESS YOU KNOW WHAT YOU'RE DOING --
goldCountStore = getGlobalStorageValue(goldStore)
object = getThingFromPos(pos)
goldWeight = getItemWeight(moveitem.uid) * 10
local v = goldCoins[moveitem.itemid]
if v then
doRemoveItem(moveitem.uid)
doSendMagicEffect(position, 3)
setGlobalStorageValue(goldStore, goldCountStore + (goldWeight * v.worth))
doSetItemSpecialDescription(object.uid, "There are " ..(goldCountStore + (goldWeight * v.worth)).. " gold coins in here.\n"..(targetCount - (goldCountStore + (goldWeight * v.worth))).." more gold coins is needed.")
if ((targetCount - (goldCountStore + (goldWeight * v.worth)))) <= 0 then
doSomething()
end
else
doRemoveItem(moveitem.uid)
doSendMagicEffect(position, CONST_ME_POFF)
end
return true
end