Need suggestion on how to proceed

I want to make a system where I can write and edit a file that the info will be used on the client side. Right now I have it so I have a txt file and when I need the info, it reads the txt file. I would get that data and send that data to the client using usermessages. But the thing is, the data I’m sending over has over 1000 characters and possibly more will be added… How else can I do this?

Yes, I’ve thought about making the string in the client so I don’t even need to send the data over instances, but I don’t want to have to change the client side lua.

What kind of system are you talking about? Flat file saving or PData Saving? Is this some kind of money system of inventory? It would be great to know what you’re using this for to get a better idea of where to start with this.

I’m basically making a MOTD that I can change on a daily bases without having to update the FastDL stuff… Basically I have a txt file that is full of these Rules, another txt file that has a message for the week, another txt file for the admins on the server, etc.

You can probably resource.AddFile the file from the server sonthe client gets it, then read it from clientside and store it in a variable. Once that is done, delete the file so it it won’t conflict if you update the file another time.

Okay that sounds all nice and dandy but I was wondering if there was a way where no one would have to download anything more than once… I will resort to this if there’s no other way, though.

You can split the content of the data and send it to the client, which would piece it back.

What do you mean by that?

Take your giant string, chop it up into substrings and send seperate usermessages, you can probably even include some sort of index with the usermessage. Once the usermessage is received, it’ll take the index and and the string received, then peice up the original message.

Alright I thought I about doing that but thought it would be very inefficient. I guess it’s the only way and I’ll try that out, thanks!

It wouldn’t be that inefficient. The amount of time it would take to send multiple usermessages containing parts of the MoTD wouldn’t make much of an impact at all.

[lua]---------
– Server

local bitsize = 32 – I’m not sure exactly how much text can be sent alongside pointers so you can toy with this number
local bits = {}

function GetMoTD()
local txt = file.Read(“motd.txt”)
bits = {} – Clears the table in case the function is ran again (loading a new motd)
while (string.len(txt) > bitsize) do
local bit = string.sub(txt, 1, bitsize)
table.insert(bits, bit)

	txt = string.sub(txt, bitsize + 1)
end

end

function SendMoTD(pl)
for k, v in pairs(bits) do
umsg.Start(“MoTDBit”, pl)
umsg.Short(k) – k ranges from 1 to #bits and is in order because of the while function. It can serve as the pointer
umsg.Short(#bits) – Tells the client how many bits are in the entire MoTD so it knows when to stitch them
umsg.String(v)
umsg.End()
end
end


– Client

local bits = {}

usermessage.Hook(“MoTDBit”, function(u)
local bitnum = u:ReadShort()
local numbits = u:ReadShort()
local bit = u:ReadString()

bits[bitnum] = bit

if (#bits == numbits) then -- Stitch the MoTD
	local motd = table.concat(bits, "")
	
	/*	This is where
		you would put
		code to open
		the HTML	*/
	
	bits = {} -- Clear the table so the MoTD can be sent again if it's changed or needs to serve a different purpose
end

end)[/lua]

This should do it for you.

Isn’t a single character 1 byte? If it is: code’s just a bit misleading, because you’re sending 32 bytes of information, not 32 bits. Ends up being 256 bits. Either way, that’s a nice script you’ve got there.

[SUB]A practise several people have rated me dumb for defending :([/SUB]

I’ll have to toy with that to see what the highest # I can set the variable bitsize, I’ll get back to you with that answer if you’re curious, wizardsbane.

[editline]3rd May 2012[/editline]

Oh and thanks for the example code! Really appreciated

Well, by bit I mean ‘chunk’, not differentiating between bits/bytes. I see where you’re coming from though.

I’ve set up my code and haven’t had a chance to test it because my server is out of date and having trouble updating it…

ANYWAYS, I just ran into this function called SetGlobalString… I wonder, could I just use that to set the info I need into these global strings? Or is there a capacity limit (or w.e you wanna call it) on these GlobalStrings?

SetGlobalString is basically doing GetWorldEntity:SetNWString(name, value).
As you know, SetNW functions use usermessages, so it would have the same limits.

Ah, alright.

Nvm.

[editline]3rd May 2012[/editline]

Okay so I have the bitsize to 200 and when I’m doing the GetMoTD() function I made it print the bits table and it cuts out right before the end. Then when it sends that table over to the client, it pieces it together, but also cuts out a chunk of it.

Then I repeated the GetMoTD() and SendMoTD() function for seperate files ( admin list / motw ) and since those two have less characters than the bitsize it doesn’t even include any of those files… Can you help me fix it? I’m having trouble understanding each specific part itself, otherwise I’d fix it myself.

Incase it’s needed (full code):

Halp?

If you want an easily edited MOTD, here’s another solution, you always can make the MOTD a webpage, and make the webpage the MOTD. Then just edit the webpage and it will change. You need a website for this method, but a forum or something would work.

I thought about that but I have multiple servers and don’t want like 10 extra pages.

I tried to fix it myself and I came up with this:

[lua]
function GetMoTD()
local txt = file.Read(“motd/rules.txt”)
bits = {} – Clears the table in case the function is ran again (loading a new motd)
while (string.len(txt) > bitsize) do
local bit = string.sub(txt, 1, bitsize)
table.insert(bits, bit)

    txt = string.sub(txt, bitsize + 1)
	if string.len(txt) <= bitsize then
		local bit = string.sub(txt, 1, bitsize)
		table.insert(bits, bit)
	end
end

end
[/lua]

That fixed the cutting off part when receiving the string… but still for some reason the MOTD Derma doesn’t want to want to put the string in… It cuts out after like the 1100 - 1200th character. :S

[editline]4th May 2012[/editline]

Does Derma have a limit on characters allowed in each “DLabel” ?