• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] How to use Object:ToCreature()

Status
Not open for further replies.

Tommy

Founder
Let's say you have a WorldObject variable. This WorldObject variable represents a creature you're trying to manipulate, however, you won't be able to access the creature's methods since the variable's type is currently and strictly WorldObject. Example method that you might use this on: :GetNearObject

To convert the variable to Creature, that is where ToCreature comes in at.

Code:
creature = WorldObject:ToCreature()
if (creature ~= nil) then -- Make sure the conversion was successful
    -- Conversion Successful
    -- You can now use 'creature' variable
    print(creature:GetName())
end

- Moved. Eluna Lua Engine © -> Lua section is FOR RELEASES ONLY. THIS IS NOT A RELEASE. Eluna Support -> Scripting is for SCRIPTING SUPPORT. This is the second time I had to move one of your threads.
 

Rochet2

Moderator / Eluna Dev
Some background:
Object does not have Player methods. Player has Object and Player methods.
In C++ you would need to always convert Object yourself to Player if you want to access Player methods.
However Eluna will do that for you automatically. Player should always be a Player in Lua code no matter if it is passed to Eluna as Object in the C++ code.

However - like Tommy already said - even though that conversion doesn't need to be done (anymore / atm) you may still use the function to check if an object is a Player or Creature etc. because the function returns nil if the conversion fails.
 

ALILP

Emulation Addict
Some background:
Object does not have Player methods. Player has Object and Player methods.
In C++ you would need to always convert Object yourself to Player if you want to access Player methods.
However Eluna will do that for you automatically. Player should always be a Player in Lua code no matter if it is passed to Eluna as Object in the C++ code.

However - like Tommy already said - even though that conversion doesn't need to be done (anymore / atm) you may still use the function to check if an object is a Player or Creature etc. because the function returns nil if the conversion fails.

you say i cant convert creature to player with this command?
 

Rochet2

Moderator / Eluna Dev
you say i cant convert creature to player with this command?
You can do player:ToCreature() but the result will be nil if player variable was indeed of type Player and not Creature.
So no. You can not convert an actual creature into a player with this.
 

Tommy

Founder
you say i cant convert creature to player with this command?

You obviously cannot convert a creature to a player with this method. You can convert an Object, WorldObject or Unit to a player using :ToPlayer(), if the conditions are correct (e.g. If the Object, WorldObject or Unit's typeId equals player).

P.S. It is a method not a "command".
 
Status
Not open for further replies.
Top