Ir para conteúdo

Detect Life


Skyen

Posts Recomendados

Vou postar alguns scripts meus que estiveram engavetados. Faz algum tempo que fiz estes scripts, então não vou postar screenshots ou como configurar, mas as configurações são fáceis de entender, então divirtam-se.

 

O primeiro deles é uma spell, "detect life", que funciona igual à um exiva, mas detecta todos os players perto de você (incluindo monstros e npcs na versão "ultimate").

 

/data/spells/scripts/detect life.lua

-- 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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4, 4, 4, 0, 0, 0},
{0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 0, 0, 0, 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(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)
			end
		end
	end
end
return detected
end

function onCastSpell(cid, var)
local pos = getThingPosition(cid)
local life = detect_life(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


 

/data/spells/scripts/ultimate detect life.lua

-- 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 = 1

-- 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 = false

-- 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 = true

local area = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0, 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, 1, 1, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 1, 1, 1, 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, 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, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 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(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) then
				if isPlayer(thing.uid) then
					if warn then
						doPlayerSendTextMessage(thing.uid, MESSAGE_STATUS_DEFAULT, 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)
			end
		end
	end
end
return detected
end

function onCastSpell(cid, var)
local pos = getThingPosition(cid)
local life = detect_life(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


 

/data/spells/spells.xml

<!-- Detect Life Spell -->
<instant name="Detect Life" words="exiva vita" lvl="1" mana="0" aggressive="0" selftarget="1" exhaustion="1000" needlearn="0" event="script" value="detect life.lua"/>
<instant name="Ultimate Detect Life" words="exiva mas vita" lvl="60" mana="820" aggressive="0" selftarget="1" exhaustion="1000" needlearn="0" event="script" value="ultimate detect life.lua"/>


 

Se quiserem usem apenas uma das versões da spell, estão bem customizáveis.

Link para o comentário
Compartilhar em outros sites

Ou sabe o que ficaria legal? Se você juntasse esses seus scripts com aquele de exiva que aparece no minimap. Se conseguir fazer esse ganha outro REP+

Ficaria assim, alem dele falar que tem os monstros e player por perto, ele ainda falaria aonde estão no mapa.

vlws

Link para o comentário
Compartilhar em outros sites

Ou sabe o que ficaria legal? Se você juntasse esses seus scripts com aquele de exiva que aparece no minimap. Se conseguir fazer esse ganha outro REP+

Ficaria assim, alem dele falar que tem os monstros e player por perto, ele ainda falaria aonde estão no mapa.

vlws

 

Isso é bem simples de fazer, mas vai dar muito lixo no mapa. Suponha que encontre 18 criaturas, vai adicionar 18 marcas no mapa...

Bem, se mesmo assim quiser, aqui estão as versões modificadas:

 

/data/spells/scripts/detect life.lua

-- This script is part of Detect Life Spell
-- Copyright (C) 2011 AbouTibia, 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,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, 4, 0, 0},
{0, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0},
{0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0},
{0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 0, 0, 0, 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(cid, 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(cid, dpos, MAPMARK_FLAG, getCreatureName(thing.uid))
			end
		end
	end
end
return detected
end

function onCastSpell(cid, var)
local pos = getThingPosition(cid)
local life = detect_life(cid, 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

 

/data/spells/scripts/ultimate detect life.lua

-- This script is part of Detect Life Spell
-- Copyright (C) 2011 AbouTibia, 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 = 1

-- 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 = false

-- 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 = true

local area = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 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, 0, 0,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0, 0, 0, 6, 6, 6, 5, 5, 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, 0, 0, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 0, 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, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 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(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) then
				if isPlayer(thing.uid) then
					if warn then
						doPlayerSendTextMessage(thing.uid, MESSAGE_STATUS_DEFAULT, 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(cid, dpos, MAPMARK_FLAG, getCreatureName(thing.uid))
			end
		end
	end
end
return detected
end

function onCastSpell(cid, var)
local pos = getThingPosition(cid)
local life = detect_life(cid, 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

 

;)

Link para o comentário
Compartilhar em outros sites

cara ficou show essa spell mesma marcando no mapa

 

o q eu queria saber

é se tem como colocar pra depois de um tempo sumir as marcas do mapa

sem vc ter q ir la remover

 

e n sei pq essa ultimate detect life q marca no mapa

n ta funcionando '.'

Editado por rohfagundes
Link para o comentário
Compartilhar em outros sites

cara ficou show essa spell mesma marcando no mapa

 

o q eu queria saber

é se tem como colocar pra depois de um tempo sumir as marcas do mapa

sem vc ter q ir la remover

 

e n sei pq essa ultimate detect life q marca no mapa

n ta funcionando '.'

 

Não tem como remover, porque ao menos em Lua não existe nenhuma rotina pra isso.

 

E se a primeira funcionou, a segunda deveria estar funcionando também D:

A única diferença entre as duas é a configuração!

Link para o comentário
Compartilhar em outros sites

cara ficou show essa spell mesma marcando no mapa

 

o q eu queria saber

é se tem como colocar pra depois de um tempo sumir as marcas do mapa

sem vc ter q ir la remover

 

e n sei pq essa ultimate detect life q marca no mapa

n ta funcionando '.'

 

Não tem como remover, porque ao menos em Lua não existe nenhuma rotina pra isso.

 

E se a primeira funcionou, a segunda deveria estar funcionando também D:

A única diferença entre as duas é a configuração!

 

entao mas a segunda n vai ai eu tava vendo

o pq

 

local life = detect_life(cid, area, keys, pos, floors, effect, warn)

 

se vc tirar esse cid ela funciona mas n marca o mapa

e se deixa ela nem funciona '.'

estranho

Link para o comentário
Compartilhar em outros sites

Eu achei a spell bem interessante... mais quando fui testa-la ela gera varias vezes um erro... alguém sabe o porque?

[Error - Spell Interface]

data/spells/scripts/support/nomedamagia.lua:onCastSpell

Description:

<luaGerThingFromPosition> Tile not found

Link para o comentário
Compartilhar em outros sites

Eu achei a spell bem interessante... mais quando fui testa-la ela gera varias vezes um erro... alguém sabe o porque?

[Error - Spell Interface]

data/spells/scripts/support/nomedamagia.lua:onCastSpell

Description:

<luaGerThingFromPosition> Tile not found

 

Provavelmente não tem nenhum tile na posição que foi passada como parâmetro da função <luaGerThingFromPosition>

Link para o comentário
Compartilhar em outros sites

  • 3 weeks later...
×
×
  • Criar Novo...