Hello all, I'm using a usermessage, this is the part on the client:
local wtsa_keywords_string_cl = ""
local function WTSA_Save_Keywords_CL( wtsa_usermessage )
local wtsa_usermessage_string = wtsa_usermessage:ReadString()
if wtsa_usermessage_string != "ULib_autocomplete" then
if wtsa_usermessage_string != "WTSA_UMSG_END" then
wtsa_keywords_string_cl = wtsa_keywords_string_cl .. wtsa_usermessage_string
WTSA_Debug("wtsa_keywords_string_cl = \n" .. wtsa_keywords_string_cl )
else
WTSA_Debug("writing\n" .. wtsa_keywords_string_cl .."in file..")
file.Write("wtsa_keywords.txt", wtsa_keywords_string_cl)
wtsa_keywords_string_cl = ""
end
end
end
usermessage.Hook( "wtsa_save_keywords_um", WTSA_Save_Keywords_CL )
Notice the line: if wtsa_usermessage_string != "ULib_autocomplete" then
I needed to do that because for an unknow reason, i retrieve this string each time i use my usermessage :/
By that i mean that: WTSA_Debug("wtsa_keywords_string_cl = \n" .. wtsa_keywords_string_cl )
will print:
wtsa_keywords_string_cl = ULib_autocomplete
if i don't put that IF statement.
Any idea why?
Here is the server part as well, if needed:
function WTSA_Save_Keywords_SV(ply)
local plyid = ply:UniqueID() -- foutre ca apres if()
if ply and ply:IsPlayer() and PlayerCustomsKeywords[plyid] != nil then
local wtsa_keywords_string_sv = ""
local RF = RecipientFilter()
RF:AddPlayer( ply )
for k, v in pairs(PlayerCustomsKeywords[plyid]) do
wtsa_keywords_string_sv = k .. "=" .. v .. "\n"
umsg.Start( "wtsa_save_keywords_um", RF)
umsg.String(wtsa_keywords_string_sv)
umsg.End()
end
umsg.Start( "wtsa_save_keywords_um", RF)
umsg.String("WTSA_UMSG_END")
umsg.End()
WTSA_Debug(ply:Nick() .. "'s keywords are saved.")
end
end
concommand.Add("wtsa_savekeywords", WTSA_Save_Keywords_SV)
I don't think i do something wrong, i believe this is because i use it in a concommand..?
Also, while i posted this code..any idea how to make it more efficient ? I'm not satisfied, all that to save a table from server to a client file, 1 line = 1 usermessage..what is umsg.PoolString, should i use that?
Thanks for helping me