Cash + Inventory System

Hi! i would like to know, if it’s possible to make a Script which earns you money over time, different from each ranks of course, and then you could buy some special stuff from a shop. Like a car E.G

(I know there are inventory systems, but they aren’t like want them to be)


It’s certainly possible. Most basic money systems use networked variables to store data; NWVars are basically a number or entity or something unique to each player. To use this, for example:

This gives everyone $1000 at the start if they have no money.
[lua]function StartWithMoney(pl)
if pl:GetNWInt(“cash”) == 0 then
pl:SetNWInt(“cash”,1000) – We give them $1000 to begin with if they don’t have any

And this lets the player buy an item (or doesn’t let them if they can’t afford it):
[lua]function BuyItem(pl,amt)
local money = pl:GetNWInt(“cash”)
if money < amt then
pl:ChatPrint(“You can’t afford this!”)
– If their cash is less than the purchase then we tell them NO!

pl:SetNWInt("cash",money - amt) -- Take away their money


Don’t we need to declare thoose NWVars before using them?


Do they remain after the server restarts, etc?

Entoros’ method could be abused, spending all your money then rejoining gives you back 1000

Yeah, I mean it’s not perfect. You would have to create a database for who’s been on the server before and all that jazz, but it’s meant to be a basic idea JSharpe.

Emperus, you don’t need to declare NWInts, they’re by default 0. If I said


It would print 0.

And no, they don’t remain after the server restarts. You need to use text files or SQLite to save the values.

Ah yeah i see, Entoros. Thanks for coming up with it =)