Check name monster in area

adamox223

Member
Joined
Oct 21, 2017
Messages
96
Reaction score
4
Hello i have this script and i need to check only "Mad Assassin" monster in this area, because it's check all monsters in world map, can you help me to add this?

Code:
function onKill(cid, target, lastHit)
local fromPos = {x = 770, y = 204, z = 7}
local toPos = {x= 963, y = 333, z = 7}

local amount = 0
for x = fromPos.x, toPos.x do
   for y = fromPos.y, toPos.y do
     for z = fromPos.z, toPos.z do
       local monster = getTopCreature({x=x,y=y,z=z}).uid
       if(isMonster(monster) == TRUE) then
         amount = amount+1
       end   
     end
   end
end
if(amount >= 1) then
   return doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "There are "..amount.." Mad Assasins in the rift.")
end
end
 

Perun

GET SHIT DONE
Premium User
Joined
May 1, 2009
Messages
256
Reaction score
78
Lua:
if(isMonster(monster) == TRUE and monster:getName() == "Mad Assassin") then
btw you should not name variables like
Lua:
local monster = getTopCreature({x=x,y=y,z=z}).uid
if you don't know what kind of creature it is. Because in bigger scripts you can have problems after some time if you want to change something and you see var name 'monster' and it's not really monster, because this can be npc or player too :D
 
OP
A

adamox223

Member
Joined
Oct 21, 2017
Messages
96
Reaction score
4
I dont know what i do wrong.. i have now this error:
[18/06/2019 18:19:41] [Error - CreatureScript Interface]
[18/06/2019 18:19:41] data/creaturescripts/scripts/rift.lua:eek:nKill
[18/06/2019 18:19:41] Description:
[18/06/2019 18:19:41] Stack size changed!

i add this
if(amount >= 1) and (isMonster(monster) == TRUE and monster:getName() == "Mad Assassin") then

and monsters after kill get freeze :/
 

Perun

GET SHIT DONE
Premium User
Joined
May 1, 2009
Messages
256
Reaction score
78
I dont know what i do wrong.. i have now this error:
[18/06/2019 18:19:41] [Error - CreatureScript Interface]
[18/06/2019 18:19:41] data/creaturescripts/scripts/rift.lua:eek:nKill
[18/06/2019 18:19:41] Description:
[18/06/2019 18:19:41] Stack size changed!

i add this
if(amount >= 1) and (isMonster(monster) == TRUE and monster:getName() == "Mad Assassin") then

and monsters after kill get freeze :/
btw why you're not using getSpec... func? Is it 1.2 or older 0.x tfs? I will rewrite your script.

And freeze is probably because you return
Lua:
doPlayerSendTextMessage
This return int, not bool, to really kill enemy you need to return true.
So change
Lua:
function onKill(cid, target, lastHit)
local fromPos = {x = 770, y = 204, z = 7}
local toPos = {x= 963, y = 333, z = 7}

local amount = 0
for x = fromPos.x, toPos.x do
   for y = fromPos.y, toPos.y do
     for z = fromPos.z, toPos.z do
       local monster = getTopCreature({x=x,y=y,z=z}).uid
       if(isMonster(monster) == TRUE) then
         amount = amount+1
       end   
     end
   end
end
if(amount >= 1) then
   return doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "There are "..amount.." Mad Assasins in the rift.")
end
end
to

Lua:
function onKill(cid, target, lastHit)
    local fromPos = {x = 770, y = 204, z = 7}
    local toPos = {x= 963, y = 333, z = 7}
    
    local amount = 0
    for x = fromPos.x, toPos.x do
       for y = fromPos.y, toPos.y do
         for z = fromPos.z, toPos.z do
           local monster = getTopCreature({x=x,y=y,z=z}).uid
           if(isMonster(monster) == TRUE) then
             amount = amount+1
           end   
         end
       end
    end
    if(amount >= 1) then
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "There are "..amount.." Mad Assasins in the rift.")
    end
    return true
end
 
Top