Light Yagami
Banned User
- Joined
- Feb 12, 2017
- Messages
- 20
- Reaction score
- 6
Greetings all!
This is my 1st script It emulates find player which also sends a text to the player you are looking for that the person who cast the spell is looking for them and gives them their location.
This is my 1st script It emulates find player which also sends a text to the player you are looking for that the person who cast the spell is looking for them and gives them their location.
Lua:
-- this returns the offset of x, y, z
function getOffsetXYZ(pos1, pos2)
return (pos1.x - pos2.x), (pos1.y - pos2.y), (pos1.z - pos2.z)
end
-- self explanitory
function getFloorLevel(z)
if z > 0 then
return "higher"
elseif z < 0 then
return "lower"
end
return "same"
end
-- self explanitory
function getDistance(x, y)
local distance = ''
if math.abs(x) < 4 and math.abs(y) < 4 then
distance = "beside"
else
local d = x * x + y * y
if d < 10000 then
distance = "close"
elseif d < 75076 then
distance = "far"
else
distance = "very far"
end
end
return distance
end
-- self explanitory
function getDirection(x, y)
local t, direction = 0, ''
if x ~= 0 then
t = y / x
else
t = 10.
end
if math.abs(t) < 0.4142 then
if x > 0 then
direction = "west"
else
direction = "east"
end
elseif math.abs(t) < 2.4142 then
if t > 0 then
if y > 0 then
direction = "north-west"
else
direction = "south-east"
end
else
if x > 0 then
direction = "south-west"
else
direction = "north-east"
end
end
else
if y > 0 then
direction = "north"
else
direction = "south"
end
end
return direction
end
-- returns a general location of the player
function getLocation(x, y, z)
local distance = getDistance(x, y)
local level = getFloorLevel(z)
local msg = ''
if distance == "beside" then
if level == "same" then
return " is standing next to you."
elseif level == "higher" then
return " is above you."
elseif level == "lower" then
return " is below you."
end
elseif distance == "close" then
if level == "same" then
msg = " is to the "
elseif level == "higher" then
msg = " is on a higher level to the "
elseif level == "lower" then
msg = " is on a lower level to the "
end
elseif distance == "far" then
msg = " is far to the "
elseif distance == "very far" then
msg = " is very far to the "
end
return msg .. getDirection(x, y) .. "."
end
-- send the target you are trying to find a message?
local sendTargetText = true
-- if so, what message would you like to send?
local targetMsg = " just exiva'd you"
function onCastSpell(creature, variant)
local target = Creature(variant["string"])
if target then
if target:isPlayer() then
-- default message
local text = "You can not exiva yourself."
local isSelf = target:getName() == creature:getName()
-- if you aren't exivaing yourself then get the target's whereabouts
if not isSelf then
text = target:getName() .. getLocation(getOffsetXYZ(creature:getPosition(), target:getPosition()))
end
creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, text)
-- send a message to the player when someone uses exiva on them, cannot exiva yourself
if sendTargetText and not isSelf then
-- message to send to the player, or make up one of your own and assign it to text
text = creature:getName() .. targetMsg .. " and" .. getLocation(getOffsetXYZ(target:getPosition(), creature:getPosition()))
target:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, text)
end
end
end
return true
end