Net Library > Economy System

Evening all.
Before it is mentioned, I do know that I have made a similar post here (http://forum.facepunch.com/showthread.php?t=1224616&highlight=).

I’ve picked up the project again but having a success rate of absolutely 0.
I am eager to learn, how ever being told to “read the net library wiki” isn’t as useful for a newcomer as it may seem.
I’m not asking for anyone to code for me, I just need a walkthrough.

All I wish to do is implement a Net based money/economy system (steering away from NWInts). I want to be able to learn the new Net system, and use it accordingly.

What am I having trouble with? Everything. Simply put, I just don’t understand.
I’m sure a 1 on 1 conversation for 10 minutes will put this thread to a cease, just after that person to take 10 minutes of there time through a steam chat to help a fellow member.

Regards,
NintendoEKS

I don’t see why you want to steer away from networked variables. It’s the best option IMO. If you are doing this to try and understand the net library, I would probably suggest a better project.

When ever I’m scrolling through the forum, I see quite often how excessive amounts of networked variables creates lag.
I figured this would be a good learning method.

While excessive numbers of networked variables may cause excessive lag, a few of them won’t and are actually better than having hundreds of net messages.

The networked variable system is actually designed specifically for storing variables like money on both the client and server, while a net message system would require you constantly send (different and unique) messages back and forth to update variables.

Thank you Zyler for the specific explanation.
What should I keep in mind when using net messages?
When is it okay and when is it nit okay to use them?

When I think of creating a system that allows players to keep track of their own currency, this is the model that usually comes to mind:

Serverside
[lua]
util.AddNetworkString( “UpdateCurrency” );

local Player = getmetatable( “Player” );

function Player:GetCurrency()
return self.m_iCurrency;
end

function Player:SetCurrency( iAmount )
self.m_iCurrency = iAmount;
net.Start( “UpdateCurrency” );
net.WriteInt( self.m_iCurrency, 32 );
net.Send( self );
end

–[[
To add:
Player:ModCurrency( 10 );

To Remove:
	Player:ModCurrency( -10 );

]]–
function Player:ModCurrency( iAmount )
self:SetCurrency( self.m_iCurrency + iAmount );
end[/lua]

Clientside
[lua]–[[
Usage can be just GetCurrency(). (It’s a global function)
]]–
function _G.GetCurrency( )
return _G.m_iCurrency or 0;
end

net.Receive( “UpdateCurrency”, function( iLen )
_G.m_iCurrency = net.ReadInt( 32 );
end );[/lua]

Although having a global function called GetCurrency may be messy, this isn’t an actual script used in-game. It should work theoretically but I just wrote it up without testing it. So use it as an example.