Skip to content

Most of Pet methods don't work, player:GetPet() and event hooks return Creature instad of Pet class #379

@odt1

Description

@odt1

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions