• 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!

Function onLook 1.1

bomba

Member
Joined
Feb 26, 2008
Messages
635
Reaction score
7
Location
Brazil
Why don't work?
Code:
function Player:onLook(thing, position, distance)
    if thing:isPlayer() then
        if getPlayerStorageValue(thing.uid, factionStorage) == 1 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nNordica")
        elseif getPlayerStorageValue(thing.uid, factionStorage) == 2 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nImperial")
        elseif getPlayerStorageValue(thing.uid, factionStorage) == 3 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nAltmer")
        else
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nNeutro")
        end
    end
end

Full script:
Code:
function Player:onLook(thing, position, distance)
    if thing:isPlayer() then
        if getPlayerStorageValue(thing.uid, factionStorage) == 1 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nNordica")
        elseif getPlayerStorageValue(thing.uid, factionStorage) == 2 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nImperial")
        elseif getPlayerStorageValue(thing.uid, factionStorage) == 3 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nAltmer")
        else
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nNeutro")
        end
    end
  
    local description = "You see " .. thing:getDescription(distance)
    if self:getGroup():getAccess() then
        if thing:isItem() then
            description = string.format("%s\nItem ID: %d", description, thing:getId())

            local actionId = thing:getActionId()
            if actionId ~= 0 then
                description = string.format("%s, Action ID: %d", description, actionId)
            end

            local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
            if uniqueId > 0 and uniqueId < 65536 then
                description = string.format("%s, Unique ID: %d", description, uniqueId)
            end

            local itemType = thing:getType()

            local transformEquipId = itemType:getTransformEquipId()
            local transformDeEquipId = itemType:getTransformDeEquipId()
            if transformEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onEquip)", description, transformEquipId)
            elseif transformDeEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onDeEquip)", description, transformDeEquipId)
            end

            local decayId = itemType:getDecayId()
            if decayId ~= -1 then
                description = string.format("%s\nDecays to: %d", description, decayId)
            end
        elseif thing:isCreature() then
            local str = "%s\nHealth: %d / %d"
            if thing:getMaxMana() > 0 then
                str = string.format("%s, Mana: %d / %d", str, thing:getMana(), thing:getMaxMana())
            end
            description = string.format(str, description, thing:getHealth(), thing:getMaxHealth()) .. "."
        end

        local position = thing:getPosition()
        description = string.format(
            "%s\nPosition: %d, %d, %d",
            description, position.x, position.y, position.z
        )

        if thing:isCreature() then
            if thing:isPlayer() then
                description = string.format("%s\nIP: %s.", description, Game.convertIpToString(thing:getIp()))
            end
        end
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end
 
Last edited:
if getPlayerStorageValue(thing.uid, factionStorage) == 1 then
What?
Code:
int32_t LuaScriptInterface::luaPlayerGetStorageValue(lua_State* L)
{
    // player:getStorageValue(key)
this means only 1 INT value inside brackets. You got 2.
 
What error do you have? As I see you are sending another message with the faction string instead of using the one you get using the onlook, but that shouldn't be a problem at all.
 
lol
if getPlayerStorageValue(thing.uid, factionStorage) == 1 then
need to be
if player:getStorageValue(thing.uid, factionStorage) == 1 then
 
so you are saying thing.uid has player:getId() ? i DOUBT it. player:getId() changed on every logIn, there are better ways..

Besides I gave my example because he is using lib functions what might aswell not be there..

Someone should read up abit more :p
You can call the userdata from names, uids, player ids etc etc
No one said they are both the same.


lol
if getPlayerStorageValue(thing.uid, factionStorage) == 1 then
need to be
if player:getStorageValue(thing.uid, factionStorage) == 1 then

Ehm no, because then you are looking for a storage with the key that is the unique id of the player.
More like player:getStorageValue(factionStorage) == 1
 
lol
the thing.uid in this case is a player... if thing: isPlayer() then
well, thinking about it
not need the parameter thing.uid
 
try:
Code:
    if thing:isPlayer() then
        if thing:getStorageValue(factionStorage) == 1 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nNordica")
        elseif thing:getStorageValue(factionStorage) == 2 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nImperial")
        elseif thing:getStorageValue(factionStorage) == 3 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nAltmer")
        else
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nNeutro")
        end
    end
[
 
Don't work...
14:10 You see Pescador De Redmont (Level 351). He is a knight.

Code:
    if thing:isPlayer() then
        if thing:getStorageValue(factionStorage) == 1 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nNordica")
        elseif thing:getStorageValue(factionStorage) == 2 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nImperial")
        elseif thing:getStorageValue(factionStorage) == 3 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nAltmer")
        else
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nNeutro")
        end
    end
 
Are you using OTClient? Then you need to put ur code at function
Code:
function Player:onLookInBattleList(creature, distance)
too. Since OTClient works differently.
 
I'm using Tibia client with ipchanger =/

Code:
function Player:onLook(thing, position, distance)
    if thing:isPlayer() then
        if thing:getStorageValue(factionStorage) == 1 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nNordica")
        elseif thing:getStorageValue(factionStorage) == 2 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nImperial")
        elseif thing:getStorageValue(factionStorage) == 3 then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nAltmer")
        else
            self:sendTextMessage(MESSAGE_INFO_DESCR, "\nNeutro")
        end
    end

    local description = "You see " .. thing:getDescription(distance)
    if self:getGroup():getAccess() then
        if thing:isItem() then
            description = string.format("%s\nItem ID: %d", description, thing:getId())

            local actionId = thing:getActionId()
            if actionId ~= 0 then
                description = string.format("%s, Action ID: %d", description, actionId)
            end

            local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
            if uniqueId > 0 and uniqueId < 65536 then
                description = string.format("%s, Unique ID: %d", description, uniqueId)
            end

            local itemType = thing:getType()

            local transformEquipId = itemType:getTransformEquipId()
            local transformDeEquipId = itemType:getTransformDeEquipId()
            if transformEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onEquip)", description, transformEquipId)
            elseif transformDeEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onDeEquip)", description, transformDeEquipId)
            end

            local decayId = itemType:getDecayId()
            if decayId ~= -1 then
                description = string.format("%s\nDecays to: %d", description, decayId)
            end
        elseif thing:isCreature() then
            local str = "%s\nHealth: %d / %d"
            if thing:getMaxMana() > 0 then
                str = string.format("%s, Mana: %d / %d", str, thing:getMana(), thing:getMaxMana())
            end
            description = string.format(str, description, thing:getHealth(), thing:getMaxHealth()) .. "."
        end

        local position = thing:getPosition()
        description = string.format(
            "%s\nPosition: %d, %d, %d",
            description, position.x, position.y, position.z
        )

        if thing:isCreature() then
            if thing:isPlayer() then
                description = string.format("%s\nIP: %s.", description, Game.convertIpToString(thing:getIp()))
            end
        end
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

Code:
function Player:onLookInBattleList(creature, distance)
    local description = "You see " .. creature:getDescription(distance)
    if self:getGroup():getAccess() then
        local str = "%s\nHealth: %d / %d"
        if creature:getMaxMana() > 0 then
            str = string.format("%s, Mana: %d / %d", str, creature:getMana(), creature:getMaxMana())
        end
        description = string.format(str, description, creature:getHealth(), creature:getMaxHealth()) .. "."

        local position = creature:getPosition()
        description = string.format(
            "%s\nPosition: %d, %d, %d",
            description, position.x, position.y, position.z
        )

        if creature:isPlayer() then
            description = string.format("%s\nIP: %s", description, Game.convertIpToString(creature:getIp()))
        end
    end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end
 
Back
Top