I am recently trying to make a gamemode that has to do with a money variable. I am new to Lua so I have a few questions.
1. How do I create a new variable such as money
2. How would I insert a variable into a string such as "You have $(money)!"
3. Where would the code for the variable go? (init, cl_init, shared)
4. Where would the code for the HUD that displays money go?(init, cl_init, shared)
this tutorial will help you: [url]http://wiki.garrysmod.com/?title=LUA:Money_System_Part_1[/url]
2) "You have $" .. moneyvar;
4) Clientside.
You're trying to do stuff with networking variables - money should be set on the server but also used on the client. You should probably look at Networked Variables or Usermessages.
[lua]local money = 500;
print("You have $" .. money .. "!");
-- alternatively, you could use string.format
print(string.format("You have %s!",money)); -- something like this
[/lua]
However, I'm going to assume that if you're making a money system you're going to want a variable that is unique to each player. Take a look at the simple money system I made for an example: [url]http://entoros.pastebin.com/f2e88e84a[/url]
The money stuff goes serverside, but a HUD would go clientside.
HUDs are clientside so the code will go in your cl_init file, you can use this tut and edit the code a bit to get a HUD object that displays your money: [url]http://wiki.garrysmod.com/?title=Kill_Counter[/url]
Sorry, you need to Log In to post a reply to this thread.