otland / forgottenserver

A free and open-source MMORPG server emulator written in C++
https://otland.net
GNU General Public License v2.0
1.57k stars 1.05k forks source link

New function isClass #4640

Closed MillhioreBT closed 5 months ago

MillhioreBT commented 5 months ago

Pull Request Prelude

Changes Proposed

This new method would help us know if the datatype belongs to a specific class. Although we can do the raw comparison using the getmetatable function, it seems more intuitive to have this method with the name isClass

Cases in which it can be useful:

Example ```lua local event = Event() function event.onMoveItem(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder) if isClass(toCylinder, Tile) then player:sendTextMessage(MESSAGE_INFO_DESCR, "To Tile.") elseif isClass(toCylinder, Player) then player:sendTextMessage(MESSAGE_INFO_DESCR, "To Player.") elseif isClass(toCylinder, Container) then player:sendTextMessage(MESSAGE_INFO_DESCR, "To Container.") end return RETURNVALUE_NOERROR end event:register() ```

The other option would be to add all the methods corresponding to all the classes:

Issues addressed: Nothing!