• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua local var = Creature(petUid)

Simbaclaws

ˁ(⦿ᴥ⦿)ˀ
Joined
Mar 15, 2016
Messages
41
Reaction score
1
Location
Netherlands
So basically, I'm using the following code:
https://otland.net/threads/tfs-1-2-pet-system.236403/


And I've caught a bear. (I removed the vocation check because it was a deprecated function so it would work)
Now that I've caught a bear, as soon as I do !petinfo it will display the text: Your's pet is offline.
This basically means that the local variable pet is nil.
This line:
Code:
local pet = Creature(petUid)
seems to return nil, even though I've caught a bear.
I've tried setting text to:
Code:
text = pet:isCreature()
but that will give an error saying that pet is nil.

Is there any reason as to why pet would be nil? Should I checkout the pet library and check the Creature function? because I couldn't find any Creature function in the following thread:
https://otland.net/threads/lua-functions-list.14039/

EDIT: in the pet library I couldn't find any function named Creature. Does anyone know where this comes from?
I've also tried searching the git repo and couldn't seem to find any function named Creature, however I did find code where the same function is used...
 
If we think of the tfs metatables as a class hierarchy like say in java, Creature is super class, of Player, Monster, Npc etc..
isCreature() is a metamethod of Creature and is the basic form of validation in terms of determining what type of creature it is.

So if isCreature returns nil you can feel confident that the monster, player or npc does not exist in the userdata if any is passed to these constructors.

Not the best explanation i wanted to give.. but i am at work and my boss is looking at me funny. :p
 
If we think of the tfs metatables as a class hierarchy like say in java, Creature is super class, of Player, Monster, Npc etc..
isCreature() is a metamethod of Creature and is the basic form of validation in terms of determining what type of creature it is.

So if isCreature returns nil you can feel confident that the monster, player or npc does not exist in the userdata if any is passed to these constructors.

Not the best explanation i wanted to give.. but i am at work and my boss is looking at me funny. :p

So you're saying that the monster or *pet* is not in my userdata? Because not only does isCreature return nil but the entire super class of Creature returns nil for the petUid that's being send.
So I suppose local pet is a pointer towards that super class meaning it inherits all it's child methods? But this seems to be nil.
That being said, what exactly should I check? Is it my monsters.xml file in data/monster I should be worried about?
I have the following line in there:
Code:
<monster name="PET Bear" file="Pets/bear.xml"/>

Which contains:
Code:
<?xml version="1.0" encoding="utf-8"?>
<monster name="Bear" namedescription="a bear" race="blood" experience="23" speed="176" manacost=¨0">
    <health now="80" max="80"/>
    <look type="16" corpse="5975"/>
    <targetchange interval="2000" chance="0"/>
    <strategy attack="100" defense="0"/>
    <flags>
        <flag summonable="0"/>
        <flag attackable="1"/>
        <flag hostile="1"/>
        <flag illusionable="1"/>
        <flag convinceable="1"/>
        <flag pushable="1"/>
        <flag canpushitems="0"/>
        <flag canpushcreatures="0"/>
        <flag targetdistance="1"/>
        <flag staticattack="90"/>
        <flag runonhealth="0"/>
    </flags>
    <attacks>
        <attack name="melee" interval="2000" skill="22" attack="24"/>
    </attacks>
    <defenses armor="8" defense="8"/>
    <elements>
        <element earthPercent="20"/>
        <element holyPercent="7"/>
        <element icePercent="-10"/>
        <element deathPercent="-4"/>
    </elements>
</monster>

I'm not quite sure what I should be looking at...
 
My bad I should have not said userdata.. I should have said number.. :p

For instance
Code:
function x(id)
    return Creature(id):isPlayer()
end

local cid = player:getId()
x(cid) -- if the player is online then this will return true
 
My bad I should have not said userdata.. I should have said number.. :p
I suppose you mean the petUid number correct? How can I check what the correct number is :S? Is this defined somewhere for each creature?

EDIT: hmmm so the creature itself is offline ^.^? Because that's what the message is telling me from the script. I could post it here if you'd like but it's also in the thread I've mentioned.
 

Similar threads

Back
Top