T
Tibia Demon
Guest
i made spell and i need know if this will crash server or its good
and if anyone can show tips to write it in better way
i explain spell in tags if need more explain tell me and i explain again anypart
and if anyone can show tips to write it in better way
i explain spell in tags if need more explain tell me and i explain again anypart
Lua:
local time = 30
local config = {
ItemPos1 = Position(1014, 958, 7),
ItemPos2 = Position(1019, 961, 7),
ItemPos3 = Position(1022, 956, 7),
ItemCheck1 = 1729,
ItemCheck2 = 1730,
ItemCheck3 = 1731,
ItemCreate = 1728,
AID = 5008,
StorageCheck = PlayerStorageKeys.magictreestorage
}
-- create item i added decay in items.xml after time
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_TELEPORT)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
combat:setParameter(COMBAT_PARAM_CREATEITEM, config.ItemCreate)
combat:setArea(createCombatArea(AREA_BEAM8))
local combatEffect = Combat()
combatEffect:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_POFF)
combatEffect:setArea(createCombatArea(AREA_BEAM8))
-- add timer to first front item
local function countDown(cid, position, time)
local player = Player(cid)
if not player or time == 0 then
return
end
player:say(time, TALKTYPE_MONSTER_SAY, false, 0, position)
addEvent(countDown, 1000, cid, position, time - 1)
end
-- show effect after 1 second one time only
local function EffectDelay(creatureId, variant)
local creature = Creature(creatureId)
if not creature then
return
end
combatEffect:execute(creature, variant)
end
function onCastSpell(creature, variant)
local player = Player(creature)
local playersDir = player:getDirection()
local position = variant:getPosition()
local tile = Tile(position)
if not tile then
return false
end
-- check if tile i am looking at has actionid
if not (tile:getGround():getActionId() == config.AID) then
return false
end
-- check if the three items in pos
local PosCheck1 = Tile(config.ItemPos1):getItemById(config.ItemCheck1)
local PosCheck2 = Tile(config.ItemPos2):getItemById(config.ItemCheck2)
local PosCheck3 = Tile(config.ItemPos3):getItemById(config.ItemCheck3)
if not PosCheck1 or not PosCheck2 or not PosCheck3 then
return false
end
-- check if player looking east
if playersDir ~= DIRECTION_EAST then
return false
end
-- check if player dont have spell timed storage
if player:getStorageValue(config.StorageCheck) > os.time() then
return false
end
if tile then
-- do spell and add 30 second timed storage
if tile:getGround():getActionId() == config.AID then
player:setStorageValue(config.StorageCheck, os.time() + 30)
position:sendMagicEffect(CONST_ME_TELEPORT)
countDown(creature.uid, Variant.getPosition(variant), 30)
combat:execute(creature, variant)
addEvent(EffectDelay, 1000, creature:getId(), variant)
end
end
return true
end