MONSTER_STORAGE = MONSTER_STORAGE or {}
function Monster.setStorageValue(self, key, value)
local cid = self:getId()
local storageMap = MONSTER_STORAGE[cid]
if not storageMap then
MONSTER_STORAGE[cid] = {[key] = value}
else
storageMap[key] = value
end
end
function Monster.getStorageValue(self, key)
local storageMap = MONSTER_STORAGE[self:getId()]
if storageMap then
return storageMap[key] or -1
end
return -1
end
monster:setStorageValue(29937, 1)
print(monster:getStorageValue(22937)) -- 1
MONSTER_STORAGE = MONSTER_STORAGE or {}
function Monster.setStorageValue(self, key, value)
local cid = self:getId()
local storageMap = MONSTER_STORAGE[cid]
if not storageMap then
MONSTER_STORAGE[cid] = {[key] = value}
else
storageMap[key] = value
end
end
function Monster.getStorageValue(self, key)
local storageMap = MONSTER_STORAGE[self:getId()]
if storageMap then
return storageMap[key] or -1
end
return -1
end
monster:setStorageValue(29937, 1)
print(monster:getStorageValue(22937)) -- 1
except there's 0 use to add it in source because monster storage values shouldn't be saved to database + it takes 1 minute to implement in lua
if anything source technically would be more optimized for memory usage, but imo not to the point where it's worth to implement it unless you're going to be throwing storages on 100,000+ monsters
1 storage on 100,000 monsters would only take up approx~ 8mb of memory if implemented in lua
that's without any optimizations
if you really wanted you could delete invalid cids in the MONSTER_STORAGE table on server save and then let lua garbage collector run to remove all unnecessary memory used from monsters that aren't ingame anymore
which if you used you could probably get that 8mb down to approx 1-2mb assuming most monsters die before server save
in c++ the storage map gets deleted automatically once the monster gets removed
in lua you can implement the same thing with onDeath creatureevent
put this in global.lua
LUA:MONSTER_STORAGE = MONSTER_STORAGE or {} function Monster.setStorageValue(self, key, value) local cid = self:getId() local storageMap = MONSTER_STORAGE[cid] if not storageMap then MONSTER_STORAGE[cid] = {[key] = value} else storageMap[key] = value end end function Monster.getStorageValue(self, key) local storageMap = MONSTER_STORAGE[self:getId()] if storageMap then return storageMap[key] or -1 end return -1 end
example
LUA:monster:setStorageValue(29937, 1) print(monster:getStorageValue(22937)) -- 1
You can save some informations on specific monsters and yes getId() is unique for every creatureSo, lets see if i understand this chunk of code. If i use this lets say in a creaturescript or a spell, that is used by a monster creature, it will save the desired storage. My question here is, shouldnt cid be self:getUniqueId(), or getId is already unique for everyspawn monster?
Also, what usages could have this snipet? Other than making a monster "different" from others (which can be achieved on easier ways).
Thank you!