Hello there, ive been working on a money system using NWInts as money, however, i have been told that they use up a lot of bandwidth from the server, and im asking if there
is a good alternative to em?
Thanks in advance.
Usermessages.
Usermessages.
Okies, thanks for the reply, however im a little uncertain on how to tunr it into an effective system.
Would the values themselves be saved as integers inside a table on the server and sent via usermessages when a clients needs it?
The server sends the usermessages, the client doesn't ask for them, please post your code.
I havent actually started coding yet, still gathering information about usermessages.
You would do this:
[lua]
if SERVER then
function SendStuffToPlayer()
umsg.Start("AnUniqueName") --Start an usermessage for all the players
umsg.String("A string") --Send a string
umsg.End() --This actually sends the usermessage to the clients
end
else --On the client
local text = ""
local function RecieveUsermessageString(um)
text = um:ReadString() --Read the string from the usermessage object (in this case um)
end
usermessage.Hook("AnUniqueName", RecieveUsermessageString) --This tells the client that when we recieve an usermessage with the identifier "AnUniqueName" it trigs the RecieveUsermessageFunction
--do stuff with the text variable
[/lua]
I also suggest you the look up the wiki for more info about usermessages.
Why would you send the amount of money to all players?
[lua]-- Server-side
local Player = FindMetaTable "Player"
-- Call this whenever the amount of money is changed
function Player:SendMoney()
SendUserMessage( "MoneyUpdate", self, self.Money )
end
return
end
-- Client-side
usermessage.Hook( "MoneyUpdate", function( um )
LocalPlayer().Money = um:ReadLong()
end )[/lua]
Above code looks neat for HUD updating.
I thinking of keeping the money values stored in a table on the server, which i will save using
file.Write("Tables/MoneyTable.txt" , glon.encode(Money))
Why would you encode an integer?
You're better off with
[lua]file.Write("Tables/MoneyTable", Money)[/lua]
My bad, "money" is a server table i use to store all the players money values using
[lua]
meta = FindMetaTable("Player")
function meta:SetMoney(amount)
local usr = self:UniqueID()
Money[usr] = amount
self:SendMoney()
end
[/lua]
etc etc etc
I came to questions to look up whether or not to use NWvars or usmg for a currency system, and this was the top thread xD. Thank you guys.
Sorry, you need to Log In to post a reply to this thread.