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