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

TFS 1.2 - CreatureStorages

UnsineSoft

www.gungaleonline.net
Joined
Dec 23, 2014
Messages
239
Solutions
1
Reaction score
67
Location
Latin America
Is possible to add a storage to a creature? I testedit before but i think that it only works with booleans (true/false).

Example:
Code:
creature:setStorageValue(1, 1)

if creature:getStorageValue(1) then
print("Storage")
end

The data of the creature in this case will be obviously added before

Greetings.
 
you can do it with the unique id of creatures like
Code:
onCastSpell(player, var)
data = table[getCreatureTarget(player)]
data.y = 10
you can use a global table in global.lua for example, or set/get -globalStorageValue(storage, value)
its essentially the same thing, except globalStorageValue doesnt get cleared on /reload global (if you have table = {} in global it will)

this is essentially the same as creaturestorages from 0.4, however these are not cleared automatically on death, so preferrably you'd add to onDeath something like this:
Code:
onDeath(cid, corpse)
table[cid] = nil
(i know 1.2 ondeath doesnt look like that but example..)
 
Last edited:
you can do it with the unique id of creatures like
Code:
onCastSpell(player, var)
data = table[getCreatureTarget(player)]
data.y = 10
you can use a global table in global.lua for example, or set/get -globalStorageValue(storage, value)
its essentially the same thing, except globalStorageValue doesnt get cleared on /reload global (if you have table = {} in global it will)

this is essentially the same as creaturestorages from 0.4, however these are not cleared automatically on death, so preferrably you'd add to onDeath something like this:
Code:
onDeath(cid, corpse)
table[cid] = nil
(i know 1.2 ondeath doesnt look like that but example..)
Nope, it's just a personal storage for a monster, i don't know if the global storages would work here, i'm using a summons system (pokemon), and i think that i need c++ for that, is just for rage/power up spells, something like utito tempo, i built a custom move system and i want just to double the melee/spell attack if the monster got the storage xD
 
putting values in a global table with monsters uniqueid as a key is the same as creature storages...
for example
setCreatureStorage(creature.uid, "powerUp", 1) sets powerUp storage on that creature to be 1
thats how you can do in 0.4, but in 1.2 it doesnt exist so rather you can do
Code:
data = table[creature.uid]
data.powerUp = 1
then in 0.4 you could do
getCreatureStorage(creature.uid, "powerUp") to get the storage, and in 1.2 you would do
Code:
table[creature.uid].powerUp

as far as i know, storages for players/monsters/items (which depending on version of tfs) just puts that value in a global table with the things uid..
 
for example, i went on my server and tested it and used
Code:
data = {}
target = getCreatureTarget(player)
data[target] = {name = "", level = 0}
data[target]["name"] = "Rabbit"
data[target]["level"] = 10
data[target]["powerUp"] = true
then it will look like this
Code:
print(data[target]["name"])
"Rabbit"
print(data[target]["level"])
10
print(data[target]["powerUp"]
true
keep in mind i use ["level"] ingame while testing because my lua command doesnt seem to like .level, but if you're using it in a script it works perfectly fine to use it like
Code:
data[target].name = "rabbit"
print(data[target].name)

i do it like this with a very extensive monster stat system, so i know it works :)
 
Is possible to add a storage to a creature? I testedit before but i think that it only works with booleans (true/false).

Example:
Code:
creature:setStorageValue(1, 1)

if creature:getStorageValue(1) then
print("Storage")
end

The data of the creature in this case will be obviously added before

Greetings.
you can always save the info by player id and then do a table inside
 
if its a summon its much easier to just save the info to a global table with the key of that monsters unique id, instead of going to a table by a players unique id then saving data to a table with the monsters unique id..
 
depends if you want to have the info always for this monster (like a pet) or if you just want it for this monster temporary.
 
well with monsters you can just add if table[id] ~= nil then table[id] = nil to onDeath, but im not sure if summon despawning counts as onDeath
 
works until /reload
Code:
if not monsterstorage then
	monsterstorage = {}
end

function Monster.setTempStorage(self, key, value)
local cid = self:getId()
	if not monsterstorage[cid] then
		monsterstorage[cid] = {}
	end
	
	monsterstorage[cid][key] = value
	return true
end

function Monster.getTempStorage(self, key)
local cid = self:getId()
	if not monsterstorage[cid] then
		return -1
	end
	
	if not monsterstorage[cid][key] then
		return -1
	end
	
	return monsterstorage[cid][key]
end

some more examples you might find useful:
https://otland.net/threads/tfs-1-1-cat-mages-insane-custom-ai-example.230484/
add /raw/ to pastebin links if loading page causes your browser freeze, example:
http://pastebin.com/raw/fKMf6n5S/
 
works until /reload
Code:
if not monsterstorage then
    monsterstorage = {}
end

function Monster.setTempStorage(self, key, value)
local cid = self:getId()
    if not monsterstorage[cid] then
        monsterstorage[cid] = {}
    end
   
    monsterstorage[cid][key] = value
    return true
end

function Monster.getTempStorage(self, key)
local cid = self:getId()
    if not monsterstorage[cid] then
        return -1
    end
   
    if not monsterstorage[cid][key] then
        return -1
    end
   
    return monsterstorage[cid][key]
end

some more examples you might find useful:
https://otland.net/threads/tfs-1-1-cat-mages-insane-custom-ai-example.230484/
add /raw/ to pastebin links if loading page causes your browser freeze, example:
http://pastebin.com/raw/fKMf6n5S/
Thanks, one last question, the monster ids are working with each monster is working global with every monsterName?
 
depends if you want to have the info always for this monster (like a pet) or if you just want it for this monster temporary.
I was looking it as a temporary storage, it's for a pokemon boost system (Rage, strafe, etc), with the storage selected it will add of course an extra power.
 
what do you mean?
each monster has their own unique id, unrelated to the name, but Creature(cid):getName() can get the name from id
That, i haven't worked with monster data before and of course i know how getName works, i just thought that a monster will get a uniqueId of the monsterType, i mean:

I spawn a demon, it get uId 30
I spawn a dragon, it get uId 31
I spawn another demon, it get again the uId 30, but as you said, it must be 32, right?
 
each monster has their own unique id, no 2 monsters will ever have the same
demon one: id 30
dragon one: id 31
any monster: id 32
etc

the only thing about this is you have to manually remove it where u remove the monsters, like if you despawn it i dont think onDeath will work, so despawn function should have table[id] = nil etc, or the table will become very cluttered (although you probably wont notice its good practice)
 
each monster has their own unique id, no 2 monsters will ever have the same
demon one: id 30
dragon one: id 31
any monster: id 32
etc

the only thing about this is you have to manually remove it where u remove the monsters, like if you despawn it i dont think onDeath will work, so despawn function should have table[id] = nil etc, or the table will become very cluttered (although you probably wont notice its good practice)
Anyway, it will be just a temporary storage, stuff that can be cleared easy with a server save/shutdown xD
 
Back
Top