[x] I am aware that this PR may be closed if the above-mentioned criteria are not fulfilled.
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:
There are some cases in which a method returns a cylinder and this cylinder can be a player, a container or a tile, so if you want to know if it is a tile, you cannot execute the isTile method, because if it is a player or a container this method does not exist, but in the opposite case if you want to know if the cylinder is a player you can use isPlayer, but if the cylinder happens to be a tile there will be an error because isPlayer does not exist
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:
isTile, isPlayer, isCreature, isMonster, isItem, isContainer, isTeleport, isNpc
and their respective get
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 nameisClass
Cases in which it can be useful:
isTile
method, because if it is a player or a container this method does not exist, but in the opposite case if you want to know if the cylinder is a player you can useisPlayer
, but if the cylinder happens to be a tile there will be an error becauseisPlayer
does not existExample
```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:
isTile, isPlayer, isCreature, isMonster, isItem, isContainer, isTeleport, isNpc
and their respective getgetTile, getPlayer, getCreature, getMonster, getItem, getContainer, getTeleport, getNpc
Issues addressed: Nothing!