• 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 onAddItem() doesn't pass cid, is there a way to display text on screen?

TimerTim

New Member
Joined
Dec 17, 2009
Messages
19
Reaction score
3
I want to create a quest in which the player throws an item into a magic forcefield and among other things, a message appears at the position of the portal. I found two functions with which to send a message, doPlayerSendTextMessage and doSendAnimatedText (doCreatureSay would be unfitting since the message doesn't come from a creature). But doSendAnimatedText is deprecated, and onAddItem doesn't seem to pass the cid variable that is required for doPlayerSendTextMessage.

movements.xml
Code:
<movements>
    <!-- CUSTOM MOVEMENTS -->
    <movevent event="AddItem" tileitem="1" itemid="1387" script="other/rookicequest.lua"/>
</movements>

rookicequest.lua
Code:
function onAddItem(moveitem, tileitem, position, cid)
    if (tileitem.actionid > 0 and tileitem.uid == 61012) then -- player throws an item into a portal
        doRemoveItem(moveitem.uid)
   
        if moveitem ~= nil then print("moveitem has value, " .. tostring(moveitem)) end -- true, userdata
        if tileitem ~= nil then print("tileitem has value, " .. tostring(tileitem)) end -- true, userdata
        if position ~= nil then print("position has value, " .. tostring(position)) end -- true, table
        if cid ~= nil then print("cid has value, " .. tostring(cid)) end -- false
   
        -- deprecated
        doSendAnimatedText(position, "Inferior creatures, do they think they can delude me with their offerings?", MESSAGE_COLOR_ORANGE)
        -- function would require cid
        doPlayerSendTextMessage(cid, MESSAGE_COLOR_ORANGE, "Inferior creatures, do they think they can delude me with their offerings?")
    end
    return true
end

I tried putting cid at the beginning of the parameter list instead of at the end, it didn't help.

I'm using TFS 1.1 with client version 10.76.

Any ideas?
 
I want to create a quest in which the player throws an item into a magic forcefield and among other things, a message appears at the position of the portal. I found two functions with which to send a message, doPlayerSendTextMessage and doSendAnimatedText (doCreatureSay would be unfitting since the message doesn't come from a creature). But doSendAnimatedText is deprecated, and onAddItem doesn't seem to pass the cid variable that is required for doPlayerSendTextMessage.

movements.xml
Code:
<movements>
    <!-- CUSTOM MOVEMENTS -->
    <movevent event="AddItem" tileitem="1" itemid="1387" script="other/rookicequest.lua"/>
</movements>

rookicequest.lua
Code:
function onAddItem(moveitem, tileitem, position, cid)
    if (tileitem.actionid > 0 and tileitem.uid == 61012) then -- player throws an item into a portal
        doRemoveItem(moveitem.uid)
 
        if moveitem ~= nil then print("moveitem has value, " .. tostring(moveitem)) end -- true, userdata
        if tileitem ~= nil then print("tileitem has value, " .. tostring(tileitem)) end -- true, userdata
        if position ~= nil then print("position has value, " .. tostring(position)) end -- true, table
        if cid ~= nil then print("cid has value, " .. tostring(cid)) end -- false
 
        -- deprecated
        doSendAnimatedText(position, "Inferior creatures, do they think they can delude me with their offerings?", MESSAGE_COLOR_ORANGE)
        -- function would require cid
        doPlayerSendTextMessage(cid, MESSAGE_COLOR_ORANGE, "Inferior creatures, do they think they can delude me with their offerings?")
    end
    return true
end

I tried putting cid at the beginning of the parameter list instead of at the end, it didn't help.

I'm using TFS 1.1 with client version 10.76.

Any ideas?


onAddItem initial dosen't support cid in the "header". a option is an area check, bad side is, make sure only the throwing player is standing in the coordinates.
If it's tfs 1.1 use meta.

fast example, untested.
Code:
function onAddItem(moveitem, tileitem, position)
if (tileitem.uid == 61012) then 
for _, pid in ipairs(Game.getPlayers()) do
if isInRange(pid:getPosition(), Position(000,000,0), Position(000, 000, 0)) then  -- Left top coordinate and right bottom.
  player = Player(pid)
     Game.removeItem(moveitem.uid)
  position:sendMagicEffect(CONST_ME_ADD EFFECT)
  pid:say('text here', TALKTYPE_MONSTER_SAY, false, pid, position)
  end
   end
   end
  return true
end
 
Last edited:
I want to create a quest in which the player throws an item into a magic forcefield and among other things, a message appears at the position of the portal. I found two functions with which to send a message, doPlayerSendTextMessage and doSendAnimatedText (doCreatureSay would be unfitting since the message doesn't come from a creature). But doSendAnimatedText is deprecated, and onAddItem doesn't seem to pass the cid variable that is required for doPlayerSendTextMessage.

movements.xml
Code:
<movements>
    <!-- CUSTOM MOVEMENTS -->
    <movevent event="AddItem" tileitem="1" itemid="1387" script="other/rookicequest.lua"/>
</movements>

rookicequest.lua
Code:
function onAddItem(moveitem, tileitem, position, cid)
    if (tileitem.actionid > 0 and tileitem.uid == 61012) then -- player throws an item into a portal
        doRemoveItem(moveitem.uid)
  
        if moveitem ~= nil then print("moveitem has value, " .. tostring(moveitem)) end -- true, userdata
        if tileitem ~= nil then print("tileitem has value, " .. tostring(tileitem)) end -- true, userdata
        if position ~= nil then print("position has value, " .. tostring(position)) end -- true, table
        if cid ~= nil then print("cid has value, " .. tostring(cid)) end -- false
  
        -- deprecated
        doSendAnimatedText(position, "Inferior creatures, do they think they can delude me with their offerings?", MESSAGE_COLOR_ORANGE)
        -- function would require cid
        doPlayerSendTextMessage(cid, MESSAGE_COLOR_ORANGE, "Inferior creatures, do they think they can delude me with their offerings?")
    end
    return true
end

I tried putting cid at the beginning of the parameter list instead of at the end, it didn't help.

I'm using TFS 1.1 with client version 10.76.

Any ideas?
not have this function in client 10.76
doSendAnimatedText(position, "Inferior creatures, do they think they can delude me with their offerings?", MESSAGE_COLOR_ORANGE)
not have anymore, you only can use creature:say
 
onAddItem initial dosen't support cid in the "header". a option is an area check, bad side is, make sure only the throwing player is standing in the coordinates.
If it's tfs 1.1 use meta.

fast example, untested.
Code:
function onAddItem(moveitem, tileitem, position)
if (tileitem.uid == 61012) then
for _, pid in ipairs(Game.getPlayers()) do
if isInRange(pid:getPosition(), Position(000,000,0), Position(000, 000, 0)) then  -- Left top coordinate and right bottom.
  player = Player(pid)
     Game.removeItem(moveitem.uid)
  position:sendMagicEffect(CONST_ME_ADD EFFECT)
  pid:say('text here', TALKTYPE_MONSTER_SAY, false, pid, position)
  end
   end
   end
  return true
end

Ehmm ye that won't work at all
 
Ehmm ye that won't work at all

Ofcourse it wont work... it was just an fast example how to build something very simpel using meta in tfs 1.1. He still needs to add more coding...

Use
doRemoveItem(getTileItemById(Position(000, 000, 0), 15030).uid,1)
instead of
Game.removeItem
 
Ofcourse it wont work... it was just an fast example how to build something very simpel using meta in tfs 1.1. He still needs to add more coding...

Use
doRemoveItem(getTileItemById(Position(000, 000, 0), 15030).uid,1)
instead of
Game.removeItem

Still more problems, ex you can't compare a number value to a userdata value. (pid:getPosition())
The loop can also be optimized more since you only need the creature id from the player, not the row id.

Would not even call that something to work with, since 99% of it can't or should not even be used.
 
It isn't menth as a script for him to use. just added small examples.

this pid:getPosition() does work... i even took it from my own script.
 
It isn't menth as a script for him to use. just added small examples.

this pid:getPosition() does work... i even took it from my own script.

Oh they changed so Game.getPlayers return userdata values.
But the script is still way off and in that case you can add "recompiling userdata values" to the list.
 
Oh they changed so Game.getPlayers return userdata values.
But the script is still way off and in that case you can add "recompiling userdata values" to the list.

True, although i would advice him to approach this somewhat differently, so the script know who "cid" is instead of area check and such. But it was a fast example i dont have time to actually make something working for him :p since we're working on the new tibia systems.
 
True, although i would advice him to approach this somewhat differently, so the script know who "cid" is instead of area check and such. But it was a fast example i dont have time to actually make something working for him :p since we're working on the new tibia systems.

There is no other way, if you look at how onAddItem is coded.
The "best" way would be to add that argument to the function insted.
 
Back
Top