-- This script is part of Detect Life Spell
-- Copyright (C) 2011 Skyen Hasus
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- Radius of floors that will be detected by the spell
local floors = 0
-- Magic effect shown on detected creatures
local effect = CONST_ME_MAGIC_BLUE
-- Message sent as a warning to detected players, false to deactivate
local warn = "You feel like you're being watched."
-- Message sent when no living creature is found nearby
local nolife = "You detected no signs of life nearby."
-- If true, the message will show in detail how many creatures of each type are in each direction.
local detailed = false
local area = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 8, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
{0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0},
{0, 0, 8, 8, 8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0, 0},
{0, 0, 0, 0, 0, 0, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}
local keys = {
[1] = "north",
[2] = "northeast",
[3] = "east",
[4] = "southeast",
[5] = "south",
[6] = "southwest",
[7] = "west",
[8] = "northwest",
}
function is_index(t, index)
for i, v in ipairs(t) do
if index == i then
return true
end
end
return false
end
local function get_message(life, keys)
local msg
local add = {}
if life.total == 0 then
return false
end
for key, direction in ipairs(keys) do
local keymsg = ""
local keyadd = {}
if life[key].players == 1 then
if not msg then
msg = "There is "
end
table.insert(keyadd, "a player")
elseif life[key].players > 1 then
if not msg then
msg = "There are "
end
table.insert(keyadd, life[key].players .. " players")
end
if life[key].monsters == 1 then
if not msg then
msg = "There is "
end
table.insert(keyadd, "a monster")
elseif life[key].monsters > 1 then
if not msg then
msg = "There are "
end
table.insert(keyadd, life[key].monsters .. " monsters")
end
if life[key].npcs == 1 then
if not msg then
msg = "There is "
end
table.insert(keyadd, "a NPC")
elseif life[key].npcs > 1 then
if not msg then
msg = "There are "
end
table.insert(keyadd, life[key].npcs .. " NPCs")
end
for i = 1, #keyadd do
if i == #keyadd and #keyadd > 1 then
keymsg = keymsg .. " and "
elseif i ~= 1 then
keymsg = keymsg .. ", "
end
keymsg = keymsg .. keyadd[i]
end
if #keyadd > 0 then
table.insert(add, keymsg .. " by the " .. keys[key])
end
end
for i = 1, #add do
if i == #add and #add > 1 then
msg = msg .. " and "
elseif i ~= 1 then
msg = msg .. ", "
end
msg = msg .. add[i]
end
return msg .. "."
end
local function detect_life(uid, area, keys, pos, floors, effect, warn)
local detected = {}
local center = {}
-- Make sure the area is large enought and has a center
if #area < 1 or #area[1] < 1 or #area % 2 == 0 or #area[1] % 2 == 0 then
error("The size of the area is invalid.")
return false
end
center.y = math.ceil(#area / 2)
center.x = math.ceil(#area[1] / 2)
detected.total = 0
for key, value in pairs(keys) do
detected[key] = {
players = 0,
monsters = 0,
npcs = 0,
}
end
for z = -floors, floors do
for y = 1, #area do
-- Make sure that the size of the area doesn't vary
if #area[y] ~= #area[1] then
error("The size of the area varies.")
return false
end
for x = 1, #area[y] do
local dpos = {}
local key = area[y][x]
dpos.x = pos.x - center.x + x
dpos.y = pos.y - center.y + y
dpos.z = pos.z + z
dpos.stackpos = STACKPOS_TOP_CREATURE
local thing = getThingFromPos(dpos, false)
if thing.uid ~= 0 and is_index(keys, key) and not isPlayerGhost(thing.uid) then
if isPlayer(thing.uid) then
if warn then
doPlayerSendTextMessage(thing.uid, MESSAGE_EVENT_ADVANCE, warn)
end
detected[key].players = detected[key].players + 1
elseif isMonster(thing.uid) then
detected[key].monsters = detected[key].monsters + 1
elseif isNpc(thing.uid) then
detected[key].npcs = detected[key].npcs + 1
end
detected.total = detected.total + 1
doSendMagicEffect(dpos, effect)
doPlayerAddMapMark(uid, dpos, 9, "Here is a thing.")
end
end
end
end
return detected
end
function onCastSpell(cid, var)
local pos, uid = getThingPosition(cid), cid
local life = detect_life(uid, area, keys, pos, floors, effect, warn)
if not life then
return false
end
local message = "There " .. (life.total == 1 and "is " or "are ") .. life.total .. " creatures nearby."
if detailed then
message = get_message(life, keys)
end
if life.total == 0 then
message = nolife
end
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, message)
return true
end
vê se você gosta.






info
Grupo: Cavaleiro
Registrado: 04/09/12
Posts: 185
Reputação: +2
Baseando nesse topico http://www.xtibia.co...70-detect-life/
Gostaria de que alem de rastrear ele mostrasse no minimap oq ele rastreou.
Poderia se basear nesse script do Ramza
Quem conseguir dou REP+
Editado Janeiro 8 por Allangod