• 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 Script that takes the name of monsters near to the player

Mr.Caffeine

Active Member
Joined
Nov 4, 2018
Messages
79
Reaction score
43
Hello, I would like a help to make a movement script that shows on the screen the name of a monster that is close to the player at the time of execution. The distance can be around 8sqm. It is not necessary to get the name of all monsters, I just want the script to be executed 1x, with the first monsters that it gets

TFS 0.X
 
Hello, I would like a help to make a movement script that shows on the screen the name of a monster that is close to the player at the time of execution. The distance can be around 8sqm. It is not necessary to get the name of all monsters, I just want the script to be executed 1x, with the first monsters that it gets

TFS 0.X
Untested, but try this.
It will scan the area 7 by 7 for all creatures, then find the one closest to the person who stepped on the tile.
If 2 creatures are both the same distance away, it will only 'choose' the first one it scanned.
Note: It ignores the player stepping on the tile, so it won't 'find' itself.
Lua:
function onStepIn(cid, item, position, fromPosition)
    if not isPlayer(cid) then
        return true
    end
    local spectators = getSpectators(position, 7, 7)
    local distance, temp_distance = 9, 0
    local creature = 0
    for _, pid in ipairs(spectators) do
        if cid ~= pid then
            temp_distance = getDistanceBetween(position, getCreaturePosition(pid))
            if temp_distance < distance then
                distance = temp_distance
                creature = pid
            end
        end
    end
    if creature ~= 0 then
        print(getCreatureName(creature)) -- this is the closest monster
    else
        print("No creatures found in search area.")
    end
    return true
end
 
Back
Top