Darad
New Member
- Joined
- Jun 23, 2009
- Messages
- 119
- Reaction score
- 1
Proudly presenting!
Config
charges = 5, -- set to 0 if you want to make it endless
useCooldown = 1, -- 0 don't use it, 1 use it
cooldownTime = 60, -- cooldown in minutes
cooldownWhileLoggedOut = 1, -- let the cooldown end while the player is online. if set to 0 the cooldowntimer only runs while the player is logged in
removeAfterChargesEmpty = 1, -- remove the item when it's out of charges
storageIDCooldown = 4501, -- storageValue for the cooldown timer
storageIDCharges = 4502 -- storageValue for the charges
Feedback
On teleporting you will receive a message with the charges that are left on the map.
On using while on cooldown you will receive a message with the remaining minutes left
Cooldown of 2 minutes result
Future updates
- NPC to reload the charges/remove cooldown for gold (great for server's money sink)
Please report any bugs you may find. It's for TFS 0.3.5pl1
Feel free to rep++ me
Config
charges = 5, -- set to 0 if you want to make it endless
useCooldown = 1, -- 0 don't use it, 1 use it
cooldownTime = 60, -- cooldown in minutes
cooldownWhileLoggedOut = 1, -- let the cooldown end while the player is online. if set to 0 the cooldowntimer only runs while the player is logged in
removeAfterChargesEmpty = 1, -- remove the item when it's out of charges
storageIDCooldown = 4501, -- storageValue for the cooldown timer
storageIDCharges = 4502 -- storageValue for the charges
Feedback
On teleporting you will receive a message with the charges that are left on the map.
On using while on cooldown you will receive a message with the remaining minutes left
Cooldown of 2 minutes result
19:39 4 charges left on your map
19:47 Your home map is ready for use again.
19:47 3 charges left on your map
19:49 Your home map is ready for use again.
19:52 2 charges left on your map
Future updates
- NPC to reload the charges/remove cooldown for gold (great for server's money sink)
Please report any bugs you may find. It's for TFS 0.3.5pl1
Feel free to rep++ me
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Home map" version="1.0" author="Darad @ Babylon" enabled="yes">
<item id="1956" article="a" name="home map">
<attribute key="weight" value="1200"/>
</item>
<config name="map_config"><![CDATA[
config = {
charges = 5, -- set to 0 if you want to make it endless
useCooldown = 0, -- 0 don't use it, 1 use it
cooldownTime = 2, -- cooldown in minutes
cooldownWhileLoggedOut = 1, -- let the cooldown end while the player is online. if set to 0 the cooldowntimer only runs while the player is logged in
removeAfterChargesEmpty = 1, -- remove the item when it's out of charges
storageIDCooldown = 4501, -- storageValue for the cooldown timer
storageIDCharges = 4502 -- storageValue for the charges
-- Planning on adding an npc that can restore your map charges for money! Check the thread for more info on that later!
}
]]></config>
<action itemid="1956" allowfaruse="0" event="buffer"><![CDATA[
-- function onUse(cid, item, fromPosition, itemEx, toPosition)
domodlib('map_config')
-- Charges getter
local function getCharges()
local charges = getPlayerStorageValue(cid, config.storageIDCharges)
if(charges < 0) then
charges = config.charges
end
return charges
end
-- Charges setter
local function setCharges()
setPlayerStorageValue(cid, config.storageIDCharges, getCharges() - 1)
end
-- Cooldown getter
local function getCooldown()
return getPlayerStorageValue(cid, config.storageIDCooldown)
end
-- Cooldown setter
local function setCooldown()
setPlayerStorageValue(cid, config.storageIDCooldown, config.cooldownTime)
end
local mayTeleport = false
if(config.useCooldown == 1) then
if(getCooldown() < 1) then
if(config.charges > 0) then
if(getCharges() > 0) then
mayTeleport = true
else
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
doPlayerSendCancel(cid, 'This map has no charges left')
end
else
mayTeleport = true
end
else
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
doPlayerSendCancel(cid, 'Cooldown has no yet expired. ' .. getCooldown() .. ' minutes left!')
end
else
mayTeleport = true
end
if(getPlayerItemCount(cid, item.itemid) > 0) then
mayTeleport = true
else
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
doPlayerSendCancel(cid, 'This item cannot be used from the ground')
mayTeleport = false
end
if(mayTeleport == true) then
if(getCreatureCondition(cid, CONDITION_INFIGHT) == FALSE) then
local pos = getCreaturePosition(cid)
local townpos = getTownTemplePosition(getPlayerTown(cid))
if(config.charges > 0) then
setCharges()
if(getCharges() == 0 and config.removeAfterChargesEmpty == 1) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'No more charges left, map is removed.')
doPlayerRemoveItem(cid, item.itemid, 1)
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, getCharges() .. " charges left on your home map.")
end
end
if(config.useCooldown == 1) then
setCooldown()
end
doSendMagicEffect(pos, CONST_ME_HOLYAREA)
doTeleportThing(cid, townpos)
doSendMagicEffect(townpos, CONST_ME_TELEPORT)
else
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
doPlayerSendCancel(cid, 'You may only map home while not in combat')
end
end
return true
]]></action>
<globalevent name="homemapticker" interval="60" event="buffer"><![CDATA[
domodlib('map_config')
local function checkOnlinePlayers()
local players = getPlayersOnline()
for _, pid in ipairs(players) do
local cd = getPlayerStorageValue(pid, config.storageIDCooldown)
if(cd > 0) then
local newcd = cd - 1
if(newcd == 0) then
doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, 'Your home map is ready for use again.')
setPlayerStorageValue(pid, config.storageIDCooldown, -1)
end
setPlayerStorageValue(pid, config.storageIDCooldown, newcd)
end
end
end
local function checkAllPlayers()
db.executeQuery("UPDATE `player_storage` SET `value` = `value` -1 WHERE `key` = " .. config.storageIDCooldown .. " AND `value` > -1;")
end
if(config.cooldownWhileLoggedOut == 1 and config.useCooldown == 1) then
checkAllPlayers()
checkOnlinePlayers() -- Also check online players for unsaved values!
else
checkOnlinePlayers()
end
]]></globalevent>
</mod>
Last edited: