Leo32
Getting back into it...
- Joined
- Sep 21, 2007
- Messages
- 987
- Solutions
- 14
- Reaction score
- 532
Teleport spell players can use.
Starts at teleporting you 2 squares, gain an extra sqm per 20 magic levels.
This allows normal players to teleport to any square they can normally walk to (because we check for pathing).
However you can also teleport straight to PZ TILES and HOUSE TILES if you're the owner (because we don't check pathing).
This is for adding functionality/value when retreating or trying to get to cover.
That's pretty much it, a mage teleport spell that can go through walls - but won't allow your players to jump through walls they can't normally get through and raid all your inaccessible treasure.
If you have some weird-ass treasure rooms or inaccessible areas in any of your temples or whatever - I suggest turning pathing ON for the PZ check:
line 66:
to:
spells.xml
support/teleport.lua
I'm kinda done with Mage spells for now.
Will move onto rogue/paladin and knight spells.
This spell is part of the logic I need to create a Charge spell for knights, so it needed to be done first.
Starts at teleporting you 2 squares, gain an extra sqm per 20 magic levels.
This allows normal players to teleport to any square they can normally walk to (because we check for pathing).
However you can also teleport straight to PZ TILES and HOUSE TILES if you're the owner (because we don't check pathing).
This is for adding functionality/value when retreating or trying to get to cover.
That's pretty much it, a mage teleport spell that can go through walls - but won't allow your players to jump through walls they can't normally get through and raid all your inaccessible treasure.
If you have some weird-ass treasure rooms or inaccessible areas in any of your temples or whatever - I suggest turning pathing ON for the PZ check:
line 66:
if teleportAttempt(creature, playerPos, teleportPos) then
to:
if teleportAttempt(creature, playerPos, teleportPos, true) then
spells.xml
XML:
<instant group="support" name="Teleport" words="teleport" lvl="37" mana="250" prem="1" aggressive="0" script="support/teleport.lua">
<vocation name="..." />
</instant>
support/teleport.lua
Lua:
-- Get position depending on distance and direction
function adjustDirection(playerDirection, teleportPos, teleportDistance)
if playerDirection == DIRECTION_NORTH then
teleportPos.y = teleportPos.y - teleportDistance
elseif playerDirection == DIRECTION_SOUTH then
teleportPos.y = teleportPos.y + teleportDistance
elseif playerDirection == DIRECTION_EAST then
teleportPos.x = teleportPos.x + teleportDistance
elseif playerDirection == DIRECTION_WEST then
teleportPos.x = teleportPos.x - teleportDistance
end
return teleportPos
end
function teleportAttempt(creature, playerPos, teleportPos, pathing)
if pathing then
local checkPathing = creature:getPathTo(teleportPos, 0 , 0, true, false)
if checkPathing == false then
creature:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot teleport there.")
return false
end
end
creature:teleportTo(teleportPos)
playerPos:sendMagicEffect(CONST_ME_TELEPORT)
teleportPos:sendMagicEffect(CONST_ME_MORTAREA)
return true
end
function onCastSpell(creature, var)
local playerPos = creature:getPosition()
local playerDirection = creature:getDirection()
local magicLevel = creature:getMagicLevel()
local teleportDistance = 2
local skull = creature:getSkull()
-- Teleport extra sqm every 20 magic levels
if magicLevel >= 20 then
teleportDistance = teleportDistance + math.floor(magicLevel / 20)
end
-- Loop, starting from max distance
-- This prioritizes max distance teleports and settles for lower range teleports if that is all that's available
for i = teleportDistance, 2, -1 do
local teleportPos = creature:getPosition()
adjustDirection(playerDirection, teleportPos, i)
local teleportTile = Tile(teleportPos)
if teleportTile then -- Only continue if there is a ground tile
if teleportTile:hasFlag(TILESTATE_BLOCKSOLID) == false and teleportTile:hasFlag(TILESTATE_FLOORCHANGE) == false then -- Only continue if tile doesn't contains stairs or a blocking object
local creatureCheck = teleportTile:getCreatures()
if creatureCheck then
if #creatureCheck == 0 then -- Only continue if there isn't a creature on the sqm (player/monster/npc)
-- If House
if teleportTile:hasFlag(TILESTATE_HOUSE) then
if skull == 0 then
local house = teleportTile:getHouse()
local houseOwner = house:getOwnerGuid()
if creature:getGuid() == houseOwner then
if teleportAttempt(creature, playerPos, teleportPos) then
return true -- Teleport successful, exit script
end
end
end
-- If PZ
elseif teleportTile:hasFlag(TILESTATE_PROTECTIONZONE) then
if skull == 0 then
if teleportAttempt(creature, playerPos, teleportPos) then
return true -- Teleport successful, exit script
end
end
end
-- If valid position return true, otherwise - keep looping.
if teleportAttempt(creature, playerPos, teleportPos, true) then
return true -- Teleport successful, exit script
end
end
end
end
end
end
-- No valid position found
creature:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot teleport there.")
return false
end
I'm kinda done with Mage spells for now.
Will move onto rogue/paladin and knight spells.
This spell is part of the logic I need to create a Charge spell for knights, so it needed to be done first.
Last edited: