Tofame
Intermediate OT User
Yo,
I've just downgraded exiva spell (find_person.lua) from TFS 1.4.2 to TFS 0.X (Tested working on TFS 0.4).
Since it's working and it's good to have the script for that I thought I would share.
spells.xml
config those spells.xml, but with the above it's Player Sense "name"
Regards,
Tofame
I've just downgraded exiva spell (find_person.lua) from TFS 1.4.2 to TFS 0.X (Tested working on TFS 0.4).
Since it's working and it's good to have the script for that I thought I would share.
Lua:
local LEVEL_LOWER = 1
local LEVEL_SAME = 2
local LEVEL_HIGHER = 3
local DISTANCE_BESIDE = 1
local DISTANCE_CLOSE = 2
local DISTANCE_FAR = 3
local DISTANCE_VERYFAR = 4
local directions = {
[NORTH] = "north",
[SOUTH] = "south",
[EAST] = "east",
[WEST] = "west",
[NORTHEAST] = "north-east",
[NORTHWEST] = "north-west",
[SOUTHEAST] = "south-east",
[SOUTHWEST] = "south-west"
}
local descriptions = {
[DISTANCE_BESIDE] = {
[LEVEL_LOWER] = "is below you",
[LEVEL_SAME] = "is standing next to you",
[LEVEL_HIGHER] = "is above you"
},
[DISTANCE_CLOSE] = {
[LEVEL_LOWER] = "is on a lower level to the",
[LEVEL_SAME] = "is to the",
[LEVEL_HIGHER] = "is on a higher level to the"
},
[DISTANCE_FAR] = "is far to the",
[DISTANCE_VERYFAR] = "is very far to the"
}
function onCastSpell(cid, var)
local target = getPlayerByName(var.string)
if not target then
doPlayerSendCancel(cid, "Player with this name is not online!")
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
return true
end
if target == cid then
doPlayerSendCancel(cid, "You can't be sensing yourself!")
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
return true
end
local targetPosition = getPlayerPosition(target)
local creaturePosition = getPlayerPosition(cid)
local positionDifference = {
x = creaturePosition.x - targetPosition.x,
y = creaturePosition.y - targetPosition.y,
z = creaturePosition.z - targetPosition.z
}
local maxPositionDifference, direction = math.max(math.abs(positionDifference.x), math.abs(positionDifference.y))
if maxPositionDifference >= 5 then
local positionTangent = (positionDifference.y / positionDifference.x) or 10
if math.abs(positionTangent) < 0.4142 then
direction = positionDifference.x > 0 and WEST or EAST
elseif math.abs(positionTangent) < 2.4142 then
direction = positionTangent > 0 and (positionDifference.y > 0 and NORTHWEST or SOUTHEAST) or positionDifference.x > 0 and SOUTHWEST or NORTHEAST
else
direction = positionDifference.y > 0 and NORTH or SOUTH
end
end
local level = positionDifference.z > 0 and LEVEL_HIGHER or positionDifference.z < 0 and LEVEL_LOWER or LEVEL_SAME
local distance = maxPositionDifference < 5 and DISTANCE_BESIDE or maxPositionDifference < 51 and DISTANCE_CLOSE or maxPositionDifference < 150 and DISTANCE_FAR or DISTANCE_VERYFAR -- changed 101, 250 to 51, 150
local description = descriptions[distance][level] or descriptions[distance]
if distance ~= DISTANCE_BESIDE then
description = description .. " " .. directions[direction]
end
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, var.string .. " " .. description .. ".")
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
return true
end
spells.xml
XML:
<instant name="Player Sense" words="Player Sense" lvl="1" mana="0" aggressive="0" params="1" exhaustion="1000" needlearn="0" event="script" value="yoursense.lua"/>
Regards,
Tofame
Last edited: