• 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 Don't allow onEquip event if item has word "unidentified" on it.

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,526
Solutions
27
Reaction score
871
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi again! I use TFS 1.5 downgrades 8.6 and came to ask someone if can help me with this. I need that every item that has the word "unidentified" on it's name, don't be able to be equiped. This way no player can wear unidentified items and forces them to identify them (with another system, oen's upgrade system). Can be either c++ or .lua solution and I will provide any needed test ^^

Thanks in advance!
 
This is already part of my upgrade system.
So weird, it is not working. I probably did a change on the script that broke that because it isn't working for me. But I don't think that is the case... See this video, here's the fork repository aswell GitHub - ralke23/TFS-Upgrade-System: Upgrade system for theforgottenserver 1.4 and pre-1.4 (https://github.com/ralke23/TFS-Upgrade-System)


If someone else wish to help too, there could be a chance that if an item has the word "unidentified" on it, inmediatly deny the equip event? or something like that. I will really appreciate any help with this system, works so good but it has so many things to enhance :/.

Sorry for the late reply btw @oen432 , thanks for responding!
Regards
 
Bump for this, I was trying to use AI to craft a piece of code. Ended up with

C++:
    // Check if the item's name contains "unidentified"
    std::string itemName = item->getName();
    if (itemName.find("identificado") != std::string::npos) {
        if (!isCheck) {
            player->sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot equip an unidentified item.");
        }
        return RETURNVALUE_NOTPOSSIBLE;
    }

But still doesn't work. Can someone please help me to don't allow people wear unidentified items? I already tried with the code that is on core.lua, but it only triggers a message, it couldn't prevent the item from being equiped. I also tried with return moveItem:moveTo(parent) instead of return false on core.lua but didn't work either.
 
I've always found that onEquip and onDeEquip basically can't be denied, via Lua.

They are basically saying "Hey, we've equipped this item, is there anything else you want to do?"
So there's no way to stop the equip, since it happened before the script triggered.

My solution was to use the onMove event instead, but comes with some caveats.
Where if people get the item from a quest / npc / trading / et cetera, then the item can sometimes be auto-equipped, if the player leaves that inventory slot empty.

My solution to that, was to simply give all items via a brown bag, and require trades to be done inside of a brown bag as well.

Although for melee weapons this wasn't a solution, as they have the 'use with' property.
If the item was on the ground, and the player was 2+ sqm away, and 'use with' the item on a similarly far enough away location, the server would auto-walk the player to the item, auto pick-up the item (into the inventory slot, if it were empty), and then attempt to use the item at that location.

Thereby, being able to equip the item and be a nuisance.
For my situation, since all the damage calculations were done via Lua as well, it didn't matter if the players could equip the items at some point, as they would receive no benefits if they didn't have the required attributes to wield the item.

There's definitely a cleaner solution available if you do source edits, but it can be done via Lua this way. 🤷‍♀️

Lua:
function containsWord(str, word)
    return string.find(str, word) ~= nil
end
Lua:
local wordToFind = "unidentified"

if containsWord(item:getName(), wordToFind) then
    print("The string contains the word:", wordToFind)
else
    print("The string does not contain the word:", wordToFind)
end
 
Last edited:
@Xikini thanks for guiding me to a proper solution! at the end I didn't commit to don't allow the unidentified items to be equiped, but I just got rid of the unidentified system and everything is rolling excellent on loot now. Thanks a lot!
 
Back
Top