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

Item lib

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
106
Location
Brazil
I had some problems in TFS 0.3.6 to get item attack etc. i use getItemAttribute(uid,'attack') and it return 0 but if i change item attack (doItemSetAttribute) to 50 it return 50. And how to get item real attack? or wheig? or another item attribute key?

with this lib
wink.gif


Add it on data/lib
item.lua
Lua:
items = {
	_VERSION='1.0 By mock',
	XML_DIR='data/items/items.xml',
	}
do
	local ia = os.clock()
	io.write('Loading items')
	local i = io.open(items.XML_DIR,'r')
	local u = i:read(-1)
	i:close()
	local u = u:match('<items>(.+)</items>')
	for mi,id,mid,name,data,me in u:gmatch('<(%a-)%s*id%s*=%s*"(%d+)"%s*(.-)%s*name%s*=%s*"(.-)"%s*>(.-)</(%a*)>') do
		if mi == 'item' and me == 'item' then
			local td = {name=name,id=id,type=1}
			for key,value in data:gmatch('<attribute key="(.-)" value="(.-)"/>') do
				td[key] = value
			end
			for key,value in mid:gmatch('(.-)="(.-)"') do
				td[key] = value
			end
			items[tonumber(id)] = td
			if not name then print(id,'l',mi,id,mid,data,me) end
			items[name] = td
		end
	end
	for mi,id,mid,name,data in u:gmatch('<(%a-)%s*id%s*=%s*"(%d*)"%s*(.-)%s*name%s*=%s*"(%a+)"%s*/>') do
		if mi == 'item' then
			local td = {name=name,id=id,type=2}
			for key,value in mid:gmatch('(.-)="(.-)"') do
				td[key] = value
			end
			items[tonumber(id)] = td
			items[name] = td
		end
	end
	io.write('[done '..os.clock()-ia..']\n')
end
function getItemValue(item,value)
	return items[item] and items[item][value]
end

And enjoy the functions

Lua:
print(getItemValue('sword','attack'))
local id = getItemValue('sword','id')
print(getItemValue(id,'attack'))
 
@Nahruto
i think you can do it better.
getItemInfo spent 5x alot more memory than my lib.
this function open XML not by lua and in server source every time you use it it use more and more ram because it load xml n each use.
my function load only one time and get ALL item attr key.

or you really think that all functions form TFS is 100% safe and clean? -.-

Next time know what is you saying
 
Last edited:
@Nahruto
i think you can do it better.
getItemInfo spent 5x alot more memory than my lib.
this function open XML not by lua and in server source every time you use it it use more and more ram because it load xml n each use.
my function load only one time and get ALL item attr key

Next time know what is you saying

i loled
getItemInfo -> does not open xml every time its called, items info becomes constant when server its loading and never changes until server is restarted.

Next time know what is you saying
 
i loled
getItemInfo -> does not open xml every time its called, items info becomes constant when server its loading and never changes until server is restarted.

Next time know what is you saying

open TFS source and check :thumbup: >0.3.6 source
 
Last edited:
this function open XML not by lua and in server source every time you use it it use more and more ram because it load xml n each use.
my function load only one time and get ALL item attr key

getItemInfo doesn't load items.xml every time, TFS only loads it on startup and then stores all items with their attributes in RAM. And then getItemInfo just returns all attributes for this item as a Lua table.

This is faster because it only returns 1 attribute.

>aff, too late!#
 
@Cykotitan
i dont remenber, is on tfs 0.3.6 or 0.3.5 i saw this function loading all XML in each use.
 
@nsanee
Well big fails happens, like TFS 0.3.5.
if you run this:
Lua:
local s = socket.connect('myserver.servegame.com',7171)
s:receive(-1)
it crash all 0.3.5
or 0.3.3 (some characters got bug on DB and crash server at login)
@Nahruto
i am not liing -.-
 
@nsanee
@Nahruto
i am not liing -.-

I had some problems in TFS 0.3.6 to get item attack etc. i use getItemAttribute(uid,'attack') and it return 0 but if i change item attack (doItemSetAttribute) to 50 it return 50. And how to get item real attack? or wheig? or another item attribute key?

so why didnt you knew there was such function if you seen it in sources?
 
@Nahruto
because i dont want use the other functions because it is laggy alot lol
(fixed on 0.3.6 but i did not know if it was fixed)


but if that's what you want hear i will say:
i am a fucking lier and noob and i dont know nothing about scripting and i am a buggest noob.

Heppy now?

sweat.gif
 
@Nahruto
np, its always good make another person happy
wink.gif
 
Back
Top