• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua create function

sasuke.maria

New Member
Joined
Nov 19, 2016
Messages
17
Reaction score
0
I maked this function for 1.3
Code:
function checkMonster()
    local spectator = Game.getSpectators(Position(55, 32, 5), false, false, 10, 10, 10, 10)
        if spectator:isMonster() and spectator:getName() == "Rat" then
            spectator:say("No! I am losing my energy!", TALKTYPE_MONSTER_SAY)
            spectator:remove()
            return true
        end
    return false
end

but i receveid this error:

Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/woe.lua:eek:nSay
data/talkactions/scripts/woe.lua:18: attempt to call method 'isMonster' (a nil value)
stack traceback:
[C]: in function 'isMonster'
data/talkactions/scripts/woe.lua:18: in function 'checkMonster'
data/talkactions/scripts/woe.lua:47: in function <data/talkactions/scripts/woe.lua:1>


Someone know why?
PS: i create this funcion on my custom lib.
 
Code:
function checkMonster(position, name)
    local specs = Game.getSpectators(position, false, false, 10, 10, 10, 10)
    for i = 1, #specs do
        local spec = specs[i]
        if isMonster(spec:getId()) and spec:getName() == name then
            spec:say('No! I am losing my energy!', TALKTYPE_MONSTER_SAY)
            spec:remove()
            return true
        end
    end
end

checkMonster(Position(55, 32, 5), 'Rat')

isMonster doesn't exist as a creature method
getSpectators returns a table of creatures userdatas so you have to iterate through the table checking for monster and the name
 
Code:
function checkMonster(position, name)
    local specs = Game.getSpectators(position, false, false, 10, 10, 10, 10)
    for i = 1, #specs do
        local spec = specs[i]
        if isMonster(spec:getId()) and spec:getName() == name then
            spec:say('No! I am losing my energy!', TALKTYPE_MONSTER_SAY)
            spec:remove()
            return true
        end
    end
end

checkMonster(Position(55, 32, 5), 'Rat')

isMonster doesn't exist as a creature method
getSpectators returns a table of creatures userdatas so you have to iterate through the table checking for monster and the name


Oh!! Great!
Thanks for that, now i understand!
 
Back
Top