Hello!
I'm trying to write a module that will add spells for pets, but I encountered an issue that most Pet class methods don't seem to work, PLAYER_EVENT_ON_PET_ADDED_TO_WORLD event and player:GetPet() return Creature class instead of Pet.
Here is an example code that illustrates the issue:
local function OnPetAddedToWorld(event, player, pet)
if not player or not pet then
return
end
local petFamily = pet:GetCreatureFamily() -- Works
if petFamily == 0 then
return
end
print("player:GetPet: ", player:GetPet()) -- player:GetPet: Creature: 0x01ed117090 <- Creature and not Pet class
print("Pet: ", pet) -- Pet: Creature: 0x01ed117090 <- Creature and not Pet class
-- print("Pet:GetHappinessState: ", pet:GetHappinessState()) -- Doesn't work: attempt to call method 'GetHappinessState' (a nil value)
-- print("Pet:GetPetType: ", pet:GetPetType()) -- Doesn't work: attempt to call method 'GetPetType' (a nil value)
-- print("Pet:LearnSpell: ", pet:LearnSpell(24604)) -- Doesn't work: attempt to call method 'LearnSpell' (a nil value)
print("pet:GetOwner: ", pet:GetOwner()) -- Works: Player: 0x01b622d270
end
RegisterPlayerEvent(43, OnPetAddedToWorld) -- PLAYER_EVENT_ON_PET_ADDED_TO_WORLD = 43 (event, player, pet)
Hello!
I'm trying to write a module that will add spells for pets, but I encountered an issue that most Pet class methods don't seem to work, PLAYER_EVENT_ON_PET_ADDED_TO_WORLD event and player:GetPet() return Creature class instead of Pet.
Here is an example code that illustrates the issue: