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

Action [MOD][configurable] Advanced home map script with cooldown timer!

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
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:
- Home map with configurable charges, cooldown and more
- NPC That will recharge the map when it's empry is in the making.
- Feedback on the cooldown and charges on use!

Please more info? :p
 
It teleports a player to his home town from any position. Like the soulstone in WoW or the homemap in lotro.
 
LOL Shawak, you should understand by reading whole script, u're scripter...
 
LOL Shawak, you should understand by reading whole script, u're scripter...

I know, but i mean: So a long script only for teleport a player to home town?

EDIT: ohh now i understnad, useless charges that teleport all player to one position, <_<.
 
Mods really are the shit! No messing with tons of files, all in one!

Soon I'll release some more complicated mods ^^ Vip system maybe, but might as well keep that for myself ;D

EDIT: Found a bug; but fixed now. Map cannot be used from the ground, it resulted in some weird errors. Only usable from backpack. Als prevents players to use other players maps! :)
 
Last edited:
good job. good people are using mods now. I'll start releasing some soon when I think of some ideas.
 
Tried to fix this, after u use it once you need wait 10 minutes but it always works to tp you and only says
edit im using tfs 0.3.6
Cooldown has no yet expired.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Home map" version="1.0" author="Darad @ Babylon" enabled="yes">
        <item id="9019" article="a" name="home map">
                <attribute key="weight" value="1200"/>
        </item>
        <config name="map_config"><![CDATA[
                config = {
                        charges = 0, -- set to 0 if you want to make it endless
                        useCooldown = 1, -- 0 don't use it, 1 use it
                        cooldownTime = 10, -- 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 = 0, -- 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="9019" 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:
Back
Top