local name = 'elf' -- name of summon
local exhausttime = 60 -- how many seconds exhaustion.
local function check(cid)
local checked = 0
local place = {x=0,y=0,z=0}
local h = getThingPos(cid)
local frompos = {x=h.x-2,y=h.y-2,z=h.z}
local topos = {x=h.x+2,y=h.y+2,z=h.z}
for g = frompos.x,topos.x do
for d = frompos.y,topos.y do
local poss = {x=g,y=d,z=h.z}
local tid = getTopCreature(poss).uid
if isMonster(tid) or isPlayer(tid) or getTilePzInfo(poss) == TRUE or doTileQueryAdd(cid, poss) ~= 1 then
checked = checked + 1
else
place.x = poss.x
place.y = poss.y
place.z = poss.z
break
end
$ end
end
if checked >= 25 then
return checked
elseif checked < 25 then
return place
end
return true
end
function onSay(cid,words,param)
local v = getThingPos(cid)
local s = {exhaust=5023,summon=5024}
if isPaladin(cid) then
if isInArray({'!summon','/summon'},words:lower()) then
if exhaustion.check(cid,s.exhaust) then
doPlayerSendTextMessage(cid,MESSAGE_FIRST,'You can summon again in '..exhaustion.get(cid,s.exhaust)..' seconds!')
doSendMagicEffect(v,CONST_ME_POFF)
return true
end
if getPlayerStorageValue(cid,s.summon) ~= -1 then
local search = false
if(#getCreatureSummons(cid) >= 1) then
for _,pid in ipairs(getCreatureSummons(cid)) do
if getCreatureName(pid):lower() == name:lower() then
search = true
break
end
end
end
if search == true then
doPlayerSendTextMessage(cid,MESSAGE_FIRST,'You already have a summon!')
doSendMagicEffect(v,CONST_ME_POFF)
return true
else
setPlayerStorageValue(cid,s.summon,-1)
end
end
if not(tonumber(check(cid)))then
doPlayerSendTextMessage(cid,MESSAGE_FIRST,'You summoned your '..name..'!')
local pet = doSummonCreature(name:lower(), check(cid))
setPlayerStorageValue(cid,s.summon,pet)
doSendMagicEffect(v,CONST_ME_MAGIC_GREEN)
exhaustion.set(cid,s.exhaust,exhausttime)
else
doPlayerSendCancel(cid,'You can\'t summon here.')
doSendMagicEffect(getThingPos(cid),CONST_ME_POFF)
end
elseif isInArray({'!dismiss','/dismiss'},words:lower()) then
if(#getCreatureSummons(cid) >= 1) then
for _,pid in ipairs(getCreatureSummons(cid)) do
if getCreatureName(pid):lower() == name:lower() then
doRemoveCreature(pid)
break
end
end
doPlayerSendTextMessage(cid,MESSAGE_FIRST,'You dismissed your pet!')
doSendMagicEffect(v,CONST_ME_MAGIC_RED)
end
return true
end
else
doPlayerSendCancel(cid,'Only paladins can use this.')
doSendMagicEffect(v,CONST_ME_POFF)
end
return true
end