Hello OTLand.
I'm with some problems with extendedOpCodes.
I'm using TFS 1.1
I'm with two problems:
first:
sometimes this happens:
but, sometimes it works fine (without change anything).
Why this happens?
second problem:
When I want to send a table from server to client, I've got an error, so I transformed all the table into a string and this works fine for send, but, how to get the string back into a table? (I tried using loadstring but it isn't working ='( )
talkaction:
Client-side:
Thanks for help.
I'm with some problems with extendedOpCodes.
I'm using TFS 1.1
I'm with two problems:
first:
sometimes this happens:
Code:
ERROR: ProtocolGame parse message exception (0 bytes unread, last opcode is 50, prev opcode is -1): InputMessage eof reached
ERROR: ProtocolGame parse message exception (0 bytes unread, last opcode is 50, prev opcode is -1): InputMessage eof reached
but, sometimes it works fine (without change anything).
Code:
Buffer:
{{level="8",words="exori min flam",groupcooldown="2000",group="attack",exhaustion="2000",name="Apprentice's Strike",mana="6"},{level="23",words="utevo res ina",groupcooldown="2000",group="support",exhaustion="2000",name="Creature Illusion",mana="100"},{level="30",words="exana flam",groupcooldown="1000",group="healing",exhaustion="6000",name="Cure Burning",mana="30"},{level="22",words="exana vis",groupcooldown="1000",group="healing",exhaustion="6000",name="Cure Electrification",mana="30"},{level="10",words="exana pox",groupcooldown="1000",group="healing",exhaustion="6000",name="Cure Poison",mana="30"},{level="16",words="exori mort",groupcooldown="2000",group="attack",exhaustion="2000",name="Death Strike",mana="20"},{level="23",words="exevo vis lux",groupcooldown="2000",group="attack",exhaustion="4000",name="Energy Beam",mana="40"},{level="12",words="exori vis",groupcooldown="2000",group="attack",exhaustion="2000",name="Energy Strike",mana="20"},{level="8",words="exiva",groupcooldown="2000",group="support",exhaustion="2000",name="Find Person",mana="20"},{level="18",words="exevo flam hur",groupcooldown="2000",group="attack",exhaustion="4000",name="Fire Wave",mana="25"},{level="14",words="exori flam",groupcooldown="2000",group="attack",exhaustion="2000",name="Flame Strike",mana="20"},{level="14",words="exevo pan",groupcooldown="2000",group="support",exhaustion="2000",name="Food",mana="120"},{level="13",words="utevo gran lux",groupcooldown="2000",group="support",exhaustion="2000",name="Great Light",mana="60"},{level="14",words="utani hur",groupcooldown="2000",group="support",exhaustion="2000",name="Haste",mana="60"},{level="15",words="exori frigo",groupcooldown="2000",group="attack",exhaustion="2000",name="Ice Strike",mana="20"},{level="18",words="exevo frigo hur",groupcooldown="2000",group="attack",exhaustion="4000",name="Ice Wave",mana="25"},{level="20",words="exura gran",groupcooldown="1000",group="healing",exhaustion="1000",name="Intense Healing",mana="70"},{level="35",words="utana vid",groupcooldown="2000",group="support",exhaustion="2000",name="Invisibility",mana="440"},{level="12",words="exani hur",groupcooldown="2000",group="support",exhaustion="2000",name="Levitate",mana="50"},{level="8",words="utevo lux",groupcooldown="2000",group="support",exhaustion="2000",name="Light",mana="20"},{level="8",words="exura",groupcooldown="1000",group="healing",exhaustion="1000",name="Light Healing",mana="20"},{level="9",words="exani tera",groupcooldown="2000",group="support",exhaustion="2000",name="Magic Rope",mana="20"},{level="14",words="utamo vita",groupcooldown="2000",group="support",exhaustion="2000",name="Magic Shield",mana="50"},{level="16",words="exori moe ico",groupcooldown="2000",group="attack",exhaustion="2000",name="Physical Strike",mana="20"},{level="20",words="utani gran hur",groupcooldown="2000",group="support",exhaustion="2000",name="Strong Haste",mana="100"},{level="13",words="exori tera",groupcooldown="2000",group="attack",exhaustion="2000",name="Terra Strike",mana="20"},{level="26",words="utevo vis lux",groupcooldown="2000",group="support",exhaustion="2000",name="Ultimate Light",mana="140"}}
tamanho:0
Why this happens?
second problem:
When I want to send a table from server to client, I've got an error, so I transformed all the table into a string and this works fine for send, but, how to get the string back into a table? (I tried using loadstring but it isn't working ='( )
talkaction:
Code:
function table.val_to_str ( v )
if "string" == type( v ) then
v = string.gsub( v, "\n", "\\n" )
if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then
return "'" .. v .. "'"
end
return '"' .. string.gsub(v,'"', '\\"' ) .. '"'
else
return "table" == type( v ) and table.tostring( v ) or
tostring( v )
end
end
function table.key_to_str ( k )
if "string" == type( k ) and string.match( k, "^[_%a][_%a%d]*$" ) then
return k
else
return "[" .. table.val_to_str( k ) .. "]"
end
end
function table.tostring( tbl )
local result, done = {}, {}
for k, v in ipairs( tbl ) do
table.insert( result, table.val_to_str( v ) )
done[ k ] = true
end
for k, v in pairs( tbl ) do
if not done[ k ] then
table.insert( result,
table.key_to_str( k ) .. "=" .. table.val_to_str( v ) )
end
end
return "{" .. table.concat( result, "," ) .. "}"
end
local spells = {}
function getSpells(player)
local selfVocation = player:getVocation():getName()
local dir = "data/spells/spells.xml"
local spell = io.open(dir, "r")
for i in spell:read("*a"):gmatch('<instant(.-)</instant>') do
local spellVoc = i:find('vocation name="'..selfVocation..'"')
if (spellVoc) then
local spellName = i:match('name="(.-)"')
local spellNeedlearn = "0"
spellNeedlearn = i:match('needlearn="(.-)"')
if player:hasLearnedSpell(spellName) or tonumber(spellNeedlearn) == 0 then
local spellLevel = i:match('lvl="(.-)"')
local spellWords = i:match('words="(.-)"')
local spellMana = i:match('mana="(.-)"')
local spellGroup = i:match('group="(.-)"')
local spellExhaustion = i:match('exhaustion="(.-)"')
local spellGroupcooldown = i:match('groupcooldown="(.-)"')
if player:getLevel() >= tonumber(spellLevel) then
local temp = {name=spellName,words=spellWords,level=spellLevel,group=spellGroup, groupcooldown=spellGroupcooldown, exhaustion=spellExhaustion, mana=spellMana}
table.insert(spells,temp)
end
end
end
end
end
function onSay(player, words, param)
getSpells(player)
for i = 1,#spells do
--print(spells[i].words)
end
local text = table.tostring(spells)
--print("\n\n\n\n"..text)
Player.sendExtendedOpcode(player, 53, text)
end
Client-side:
Code:
function init()
ProtocolGame.registerExtendedOpcode(GameServerOpcodes.GameSpellBarOpcode, opCodes) -- opcode 53
end
function terminate()
ProtocolGame.unregisterExtendedOpcode(GameServerOpcodes.GameSpellBarOpcode) -- 53
end
local spells = {}
function opCodes(self, opcode, buffer)
spells = {}
print("Buffer: \n\n"..buffer.."\n\n")
loadstring("spells = " ..buffer)()
--table.sort(spells, function(a, b) return (a.level < b.level) end)
print("tamanho:" .. #spells)
end
Thanks for help.