• 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+ How to check if player clicked on something

poe6man3

Member
Joined
Aug 6, 2020
Messages
87
Solutions
1
Reaction score
12
Like in title, for example if player clicks on a corpse (opens a corpse) something will happend
 
Solution
Most common method is using an ActionId or UniqueId on the object the player is going to interact with.
Less favourable method would be using the itemId of the object.

In both scenario's above, this would be scripted as an Action event.

data/scripts
Lua:
local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    print("Doing something.")
    return true
end

-- choose 1
action:aid(45001) -- can be put on multiple objects
action:uid(45001) -- can be put on a single object. (unique)
action:id(111111) -- triggers when an item with this itemid is clicked / interacted with.

action:register()
Most common method is using an ActionId or UniqueId on the object the player is going to interact with.
Less favourable method would be using the itemId of the object.

In both scenario's above, this would be scripted as an Action event.

data/scripts
Lua:
local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    print("Doing something.")
    return true
end

-- choose 1
action:aid(45001) -- can be put on multiple objects
action:uid(45001) -- can be put on a single object. (unique)
action:id(111111) -- triggers when an item with this itemid is clicked / interacted with.

action:register()
 
Solution
thank you <3
Post automatically merged:

Most common method is using an ActionId or UniqueId on the object the player is going to interact with.
Less favourable method would be using the itemId of the object.

In both scenario's above, this would be scripted as an Action event.

data/scripts
Lua:
local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    print("Doing something.")
    return true
end

-- choose 1
action:aid(45001) -- can be put on multiple objects
action:uid(45001) -- can be put on a single object. (unique)
action:id(111111) -- triggers when an item with this itemid is clicked / interacted with.

action:register()
got 1 more small question is it possible to move the corpse from onDropLoot

Lua:
function Monster:onDropLoot(corpse)
    if hasEventCallback(EVENT_CALLBACK_ONDROPLOOT) then
        EventCallback(EVENT_CALLBACK_ONDROPLOOT, self, corpse)
    end
end

to the onUse that u showed ?
 
Last edited:
thank you <3
Post automatically merged:


got 1 more small question is it possible to move the corpse from onDropLoot

Lua:
function Monster:onDropLoot(corpse)
    if hasEventCallback(EVENT_CALLBACK_ONDROPLOOT) then
        EventCallback(EVENT_CALLBACK_ONDROPLOOT, self, corpse)
    end
end

to the onUse that u showed ?
You'd have to explain what you're trying to do.

While there might not be a direct way to do what you're intending, we can probably figure out something / workaround.
 
You'd have to explain what you're trying to do.

While there might not be a direct way to do what you're intending, we can probably figure out something / workaround.
Im trying to just change the sprites, when player dies chest appears and when somebody clicks/opens the corpse(chest) the sprite changes into the open sprites but when i do this with onUse the corpse loses the owner and everybody can open it
 
Try using these functions to set/remove ownership
Lua:
item:hasAttribute(key)
item:getAttribute(key)
item:setAttribute(key, value) -- value would likely need to be a player
item:removeAttribute(key)

ITEM_ATTRIBUTE_CORPSEOWNER -- this would be the key

That being said, I'm surprised that transforming an object item:transform would remove the ownsership value.
Strange.
 
Try using these functions to set/remove ownership
Lua:
item:hasAttribute(key)
item:getAttribute(key)
item:setAttribute(key, value) -- value would likely need to be a player
item:removeAttribute(key)

ITEM_ATTRIBUTE_CORPSEOWNER -- this would be the key

That being said, I'm surprised that transforming an object item:transform would remove the ownsership value.
Strange.
Its because decaying items use transform. So all corpse would never remove ownership at any state. Once a body decays (transforms) the first time it removes the ownership.

Lua:
void Game::internalDecayItem(Item* item)
{
    const ItemType& it = Item::items[item->getID()];
    if (it.decayTo != 0) {
        Item* newItem = transformItem(item, item->getDecayTo());
        startDecay(newItem);
    } else {
        ReturnValue ret = internalRemoveItem(item);
        if (ret != RETURNVALUE_NOERROR) {
            std::cout << "[Debug - Game::internalDecayItem] internalDecayItem failed, error code: " << static_cast<uint32_t>(ret) << ", item id: " << item->getID() << std::endl;
        }
    }
}
 
Back
Top