- Joined
- Oct 30, 2010
- Messages
- 364
- Solutions
- 13
- Reaction score
- 841
Hello everyone,
I've created a script that activates a global experience, skill and loot boost upon using a basin, shrine or any other object you desire. It is configured to get specified amount of money from bank balance and inventory of a player at the same time.
It features for example:
1. data/scripts/actions/worldBoostExp.lua
2. data/events/events.xml
make sure to have these set at "1"
3. data/events/scripts/player.lua
inside
inside
4. data/lib/core/container.lua
inside
5. and finally in data/lib/core/position.lua, at the end of the file insert this function (not made by me)
GL & HF
I've created a script that activates a global experience, skill and loot boost upon using a basin, shrine or any other object you desire. It is configured to get specified amount of money from bank balance and inventory of a player at the same time.
It features for example:
- change of used object for the duration of the boost
- constant orange description over the object with cooldown until the end of the boost
- broadcast to every player online at the start and at the end of the boost
- gold consumption from backpack and bank balance simultaneously
- based on globalstorage value, not db, so it disappears after server restart/crash
1. data/scripts/actions/worldBoostExp.lua
LUA:
local config = {
basinPosition = Position(1993, 1324, 7),
basinEmpty = 28317,
basinFull = 28316,
boostTime = 120, --seconds
boostStorage = 480664,
boostActionId = 7824, --give it to the item/basin/shrine that will activate the boost
boostCost = 10000,
effectOn = 206,
effectOff = 6,
textcolor = "FAD66E", --optional for OTC users
textBoostHasEnded = "World XP+Skill+Loot boost has ended.",
textNotEnoughResources = "You don\'t have enough resources to activate world XP+Skill+Loot boost.",
textAlreadyActive = "World XP+Skill+Loot boost is already active.",
}
local function reset()
local basin = Tile(config.basinPosition):getItemById(config.basinFull)
if basin then
basin:transform(config.basinEmpty)
basin:getPosition():sendMagicEffect(config.effectOff)
basin:getPosition():sendAnimatedText(config.textBoostHasEnded)
broadcastMessage(config.textBoostHasEnded .. " {#"..config.textcolor.."}", MESSAGE_STATUS_WARNING)
else
print("World Boost reset event error: cannot locate the basin.")
end
end
local function displayTimeLeft()
local basin = Tile(config.basinPosition):getItemById(config.basinFull)
local timeSec = getGlobalStorageValue(config.boostStorage) - os.time()
local timeMin = math.floor((timeSec) / 60)
local timeRemainingSec = timeSec - timeMin * 60
if basin then
if timeSec < 60 then
basin:getPosition():sendAnimatedText("World XP+Skill+Loot Boost:\n" .. timeSec .." seconds")
elseif timeSec >= 60 and timeSec < 120 then
basin:getPosition():sendAnimatedText("World XP+Skill+Loot boost:\n" .. timeMin .." minute " .. timeRemainingSec .. " seconds")
else
basin:getPosition():sendAnimatedText("World XP+Skill+Loot boost:\n" .. timeMin .." minutes " .. timeRemainingSec .. " seconds")
end
else
return false
end
addEvent(displayTimeLeft, 3000)
end
local worldBoostExp = Action()
function worldBoostExp.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item:getId() == config.basinEmpty then
if getGlobalStorageValue(config.boostStorage) < os.time() then
if player:removeTotalMoney(config.boostCost) == true then
setGlobalStorageValue(config.boostStorage, os.time() + config.boostTime)
broadcastMessage(player:getName() .. " has activated the global double XP+Skill+Loot boost for next " .. config.boostTime / 60 .. " minutes. {#"..config.textcolor.."}", MESSAGE_STATUS_WARNING)
item:transform(config.basinFull)
item:getPosition():sendMagicEffect(config.effectOn)
-- item:getPosition():sendAnimatedText("Double XP boost has been activated.")
local event = addEvent(reset, config.boostTime * 1000, config.basinPosition)
displayTimeLeft()
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, config.textNotEnoughResources)
player:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, config.textAlreadyActive)
player:getPosition():sendMagicEffect(CONST_ME_POFF)
end
return
end
worldBoostExp:aid(config.boostActionId)
worldBoostExp:register()
2. data/events/events.xml
make sure to have these set at "1"
XML:
<event class="Player" method="onGainExperience" enabled="1" />
<event class="Player" method="onGainSkillTries" enabled="1" />
<event class="Monster" method="onDropLoot" enabled="1" />
3. data/events/scripts/player.lua
inside
function Player:onGainExperience(source, exp, rawExp)
LUA:
if getGlobalStorageValue(480664) > os.time() then
exp = exp * 2 --- 100% boost
end
inside
function Player:onGainSkillTries(skill, tries)
LUA:
if getGlobalStorageValue(480664) > os.time() then
tries = tries * 2 --- 100% boost
end
4. data/lib/core/container.lua
inside
function Container.createLootItem(self, item, creatureName)
, somewhere after local chance = item.chance
LUA:
if getGlobalStorageValue(480664) > os.time() then
chance = chance * 2
end
5. and finally in data/lib/core/position.lua, at the end of the file insert this function (not made by me)
LUA:
function Position.sendAnimatedText(self, message)
local specs = Game.getSpectators(self, false, true, 8, 8, 7, 7)
if #specs > 0 then
for i = 1, #specs do
local player = specs[i]
player:say(message, TALKTYPE_MONSTER_SAY, false, player, self)
end
end
end
GL & HF
Last edited: