• 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!

Lua How to get UID creature

Kahras

Member
Joined
Aug 6, 2012
Messages
101
Reaction score
7
Location
Warsaw
Hello!
I have a problem, I can't get the creature's UID.
I wrote functions in lib doCheckBotPlayer(player, monsterName)
The function is that it creates a unique monster and is triggered by talkactions.
And I would like to make it so that when the character logs out, the monster automatically disappears.
I tried to save the UID of the monster to storage, but only numbers can be saved there.
Does anyone have an idea for this?
 
Solution
Hello!
I have a problem, I can't get the creature's UID.
I wrote functions in lib doCheckBotPlayer(player, monsterName)
The function is that it creates a unique monster and is triggered by talkactions.
And I would like to make it so that when the character logs out, the monster automatically disappears.
I tried to save the UID of the monster to storage, but only numbers can be saved there.
Does anyone have an idea for this?
Lua:
local monster = Game.createMonster("monsterName", position)
if monster then
   local monsterId = monster:getId() -- this is the 'uid'
end
Lua:
-- at some later time
local monster = Monster(monsterId)
if monster then
    print("monster is still alive")
    -- monster:remove() ?
end
Hello!
I have a problem, I can't get the creature's UID.
I wrote functions in lib doCheckBotPlayer(player, monsterName)
The function is that it creates a unique monster and is triggered by talkactions.
And I would like to make it so that when the character logs out, the monster automatically disappears.
I tried to save the UID of the monster to storage, but only numbers can be saved there.
Does anyone have an idea for this?
Lua:
local monster = Game.createMonster("monsterName", position)
if monster then
   local monsterId = monster:getId() -- this is the 'uid'
end
Lua:
-- at some later time
local monster = Monster(monsterId)
if monster then
    print("monster is still alive")
    -- monster:remove() ?
end
 
Solution
Also, to further what Xikini said, make sure the monster ID is stored in a global table(outside of the scope of the talkAction function, using player id/guid as the key), so that when you call onLogout you can grab the global variable.

You could even use player storage instead of a global table. Whichever floats your boat.
 
Please don't :)

STORAGE IS NOT A GLOBAL VARIABLE CONTAINER
Hence the word "could", because the storage would be removed on player logout, so it's set and removed during in memory anyway (with the downside of being able to only store one monster Id per storage key).
However, obviously not the intended use of player storages, but for those who cannot learn basic tables, its an easier route ;)

It's good to provide all the possible solutions, whilst recommending the best one...

But yeah....you are still correct... just use a table, you can store whatever you want in there
 
Last edited:
Back
Top