HomeStone script for TFS 1.1
(Idea from Ruthless Chaos OT)
* How it looks? *
☛ About
HomeStone is an item which brings us to our home place (actual character Temple).
Script is easy and fully configurable for newbies scripters on TFS 1.1 (like me )
I wrote it with mind of RPG servers, after I saw that item on server called Ruthless Chaos. It's pretty nice idea
☛ How it works?
It teleports player (when you wait specific period of time after use it) to his temple, after done few requirements.
My requirements (you can change them in script):
(Idea from Ruthless Chaos OT)
* How it looks? *
☛ About
HomeStone is an item which brings us to our home place (actual character Temple).
Script is easy and fully configurable for newbies scripters on TFS 1.1 (like me )
I wrote it with mind of RPG servers, after I saw that item on server called Ruthless Chaos. It's pretty nice idea
☛ How it works?
It teleports player (when you wait specific period of time after use it) to his temple, after done few requirements.
My requirements (you can change them in script):
- Player can use HomeStone when his level is UNDER 50;
- Player need to wait 5 seconds to get teleported (countdown);
- Player need to wait 10 seconds to use HomeStone again (cooldown/exhaust);
- Player cant be during a fight to use HomeStone;
- Player cant move when using HomeStone (in script);
- Feature - when you Look on HomeStone it shows your actual temple by name and max level to use from script;
☛ Bring it On!
First of all, you need to create exhaust.lua and allowmovement.lua in data folder
exhaust.lua - this is function that responsible for checking the exhaust (not exist in TFS 1.1 i guess, thats why you need to add it):
Code:
function exhaust(cid, storevalue, exhausttime)
-- Returns 1 if not exhausted and 0 if exhausted
newExhaust = os.time()
oldExhaust = getPlayerStorageValue(cid, storevalue)
if (oldExhaust == nil or oldExhaust < 0) then
oldExhaust = 0
end
if (exhausttime == nil or exhausttime < 0) then
exhausttime = 1
end
diffTime = os.difftime(newExhaust, oldExhaust)
if (diffTime >= exhausttime or diffTime < 0) then
setPlayerStorageValue(cid, storevalue, newExhaust)
return 1
else
return 0
end
end
Code:
local function allowMovementEvent(cid, allow, oldPosition)
local creature = Creature(cid)
if not creature then
return false
end
if allow then
return stopEvent(event)
else
stopEvent(event)
end
creature:teleportTo(oldPosition, true)
creature:sendCancelMessage('You cannot move.')
event = addEvent(allowMovementEvent, 100, cid, allow, oldPosition)
end
function Creature.allowMovement(self, allow)
allowMovementEvent(self:getId(), allow, self:getPosition())
end
Code:
dofile('data/exhaust.lua')
dofile('data/allowmovement.lua')
Finally it's time for homestone. Create in actions/scripts file named homestone.lua :
Code:
local config = {
waittime = 10, -- time in seconds to use homestone again.
storage = 2301, -- storage for `waittime`
level = 50, -- after this level you CANT use homestone.
cooldown = 5 -- how many seconds character must wait after use stone until get teleported.
}
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
local player = Player(cid)
local pos = player:getPosition()
if (player:getLevel() >= config.level) then
player:sendCancelMessage('Only players under ' .. config.level .. ' can use homestone!')
pos:sendMagicEffect(3)
else
if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
player:say('I cant do that in fight!', TALKTYPE_MONSTER_SAY)
player:sendCancelMessage('You cannot use homestone while you during a fight!')
pos:sendMagicEffect(3)
else
if(exhaust(cid, config.storage, config.waittime) == 0) then
local time = ((os.difftime(oldExhaust, newExhaust))-(50))
local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)
if time >= 3600 then
text = hours.." "..(hours > 1 and "hours" or "hour")..", "..minutes.." "..(minutes > 1 and "minutes" or "minute").." and "..seconds.." "..(seconds > 1 and "seconds" or "second")
elseif time >= 120 then
text = minutes.." "..(minutes > 1 and "minutes" or "minute").." and "..seconds.." "..(seconds > 1 and "seconds" or "second")
else
text = seconds.." "..(seconds > 1 and "seconds" or "second")
end
player:sendCancelMessage('You need to wait ' .. text .. ' before you can use homestone again.')
pos:sendMagicEffect(3)
else
function tped(cid)
local player = Player(cid)
local destination = player:getTown():getTemplePosition()
local homeid = (getPlayerTown(player))
local pos = player:getPosition()
if not player then
return false
end
item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "This stone can teleport player (under " .. config.level .. " level) to his home. \n Current home: "..getTownName(homeid)..".")
pos:sendMagicEffect(40)
player:teleportTo(destination)
destination:sendMagicEffect(40)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have succesfully teleported to ' .. getTownName(homeid) .. '.')
exhaust(cid, config.storage, config.waittime)
setPlayerStorageValue(cid, 2302, 0)
player:allowMovement(true)
return true
end
addEvent(tped, (config.cooldown * 1000), cid)
pos:sendMagicEffect(40)
setPlayerStorageValue(cid, 2302, 1)
player:allowMovement(false)
end -- end re-use
end -- end pzlock
end -- end levelcap
return true
end -- end function
Code:
<action itemid="YOUR ITEMID" script="homestone.lua"/>
If you want magiceffect per second after using homestone until character get teleported, you need to create homestonefx.lua in creaturescripts.
homestonefx.lua :
Code:
function onThink(cid)
local player = Player(cid)
if (getPlayerStorageValue(cid, 2302) == 1) then
player:getPosition():sendMagicEffect(40)
end
return true
end
Declare it in creaturescripts.xml :
Code:
<event type="think" name="Homestonefx" script="homestonefx.lua"/>
And register event in login.lua :
Code:
player:registerEvent("Homestonefx")
☛ Thats all, have a nice use!