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

TFS 1.X+ Drag Item to NPC start action?

Here you have an alternative! they are two examples.
I hope I'm not wrong, this is what you wanted?

events.xml
Code:
<event class="Player" method="onMoveItem" enabled="1" />

events/scripts/player.lua
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)

    -- DROP
    local npc = toPosition:getTile():getTopCreature() -- or Tile(toPosition):getTopCreature()
    if npc and npc:getName() == "Sonya" then
        -- stuffs
        -- return true
    end

    -- DRAG
    local npc = fromPosition:getTile():getTopCreature() -- or Tile(fromPosition):getTopCreature()
    if npc and npc:getName() == "Sonya" then
        -- stuffs
        -- return true
    end
 
Here you have an alternative! they are two examples.
I hope I'm not wrong, this is what you wanted?

events.xml
Code:
<event class="Player" method="onMoveItem" enabled="1" />

events/scripts/player.lua
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)

    -- DROP
    local npc = toPosition:getTile():getTopCreature() -- or Tile(toPosition):getTopCreature()
    if npc and npc:getName() == "Sonya" then
        -- stuffs
        -- return true
    end

    -- DRAG
    local npc = fromPosition:getTile():getTopCreature() -- or Tile(fromPosition):getTopCreature()
    if npc and npc:getName() == "Sonya" then
        -- stuffs
        -- return true
    end
If getTile returns nil whole function breaks with nil value error.
 
Here you have an alternative! they are two examples.
I hope I'm not wrong, this is what you wanted?

events.xml
Code:
<event class="Player" method="onMoveItem" enabled="1" />

events/scripts/player.lua
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition)

    -- DROP
    local npc = toPosition:getTile():getTopCreature() -- or Tile(toPosition):getTopCreature()
    if npc and npc:getName() == "Sonya" then
        -- stuffs
        -- return true
    end

    -- DRAG
    local npc = fromPosition:getTile():getTopCreature() -- or Tile(fromPosition):getTopCreature()
    if npc and npc:getName() == "Sonya" then
        -- stuffs
        -- return true
    end
Thanks i try this. :)
by dropping the item to the NPC, the onUse action on the item begins
 
Back
Top