• Money System Hud Help.
    9 replies, posted
Hey guys, I made an Money System with lua, because i'm planning to make my own, basic gamemode. But, I got some problems with the HUD, I've been puzzling around, but I cant seem to fix the error. ERROR: GAMEMODE:'HUDPaint' Failed: GmodHotel/gamemode/cl_init.lua:55: bad argument #1 to 'DrawText' (string expected, got nil) Here is my HUD script: function GM:HUDPaint() self.BaseClass:HUDPaint() local person = LocalPlayer() surface.CreateFont("coolvetica",16,400,false,false,"moneh") surface.SetTextColor( 255, 255, 255, 255 ) surface.SetTextPos( 34, (ScrH()/2)+(ScrH()/4) ) surface.SetFont("moneh") surface.DrawText( Money ) end After this I was puzzled.. I had to add "tostring(LocalPlayer():GetMoney())" Can I please, get any help? I appreciate it if you help. -Staneh
You should post your code in [noparse][lua][/lua][/noparse] tags. Where is Money defined?
[QUOTE=MakeR;21248548]You should post your code in [noparse][lua][/lua][/noparse] tags. Where is Money defined?[/QUOTE] Oh, I'm sorry. i'll post the file. [lua] local meta = FindMetaTable("Player") --Get the meta table of player function meta:AddMoney(amount) local current_cash = self:GetMoney() self:SetMoney( current_cash + amount ) end function meta:SetMoney(amount) self:SetNetworkedInt( "Money", amount ) self:SaveMoney() end function meta:SaveMoney() local cash = self:GetMoney() self:SetPData("money", cash) end function meta:SaveMoneyTXT() file.Write(gmod.GetGamemode().Name .."/Money/".. string.gsub(self:SteamID(), ":", "_") ..".txt", self:GetMoneyString()) end function meta:TakeMoney(amount) --Add money function here self:AddMoney(-amount) end function meta:GetMoney() return self:GetNetworkedInt( "Money" ) end [/lua] Here it is, the file is called sh_player.lua by the way.
I don't need to see that file to be able to say that you are using the variable Money when it hasn't been defined anywhere. So when you pass it to surface.DrawText, it is a nil value. surface.DrawText expects a string to be passed.
[QUOTE=MakeR;21249042]I don't need to see that file to be able to say that you are using the variable Money when it hasn't been defined anywhere. So when you pass it to surface.DrawText, it is a nil value. surface.DrawText expects a string to be passed.[/QUOTE] But.. I dont really seem to understand how to fix this still..
Pass a string to surface.DrawText instead of a nil value? You said in your first post that you used tostring(LocalPlayer():GetMoney()), what was wrong with that?
[QUOTE=MakeR;21249086]Pass a string to surface.DrawText instead of a nil value? You said in your first post that you used tostring(LocalPlayer():GetMoney()), what was wrong with that?[/QUOTE] Well, where should I put it, above surface.DrawText? or? Thanks for helping me by the way..
[lua] local Money = LocalPlayer():GetMoney() [/lua] Put that before the DrawText somewhere.
[QUOTE=Staneh;21249108]Well, where should I put it, above surface.DrawText? or? Thanks for helping me by the way..[/QUOTE] Pretty sure you should use it like that [lua] function GM:HUDPaint() self.BaseClass:HUDPaint() local person = LocalPlayer() surface.CreateFont("coolvetica",16,400,false,false,"moneh") surface.SetTextColor( 255, 255, 255, 255 ) surface.SetTextPos( 34, (ScrH()/2)+(ScrH()/4) ) surface.SetFont("moneh") surface.DrawText( person:GetMoney() ) end [/lua] Ninja'd :3 Mine works, and his do to.
[QUOTE=Trivkz;21249156]Pretty sure you should use it like that [lua] function GM:HUDPaint() self.BaseClass:HUDPaint() local person = LocalPlayer() surface.CreateFont("coolvetica",16,400,false,false,"moneh") surface.SetTextColor( 255, 255, 255, 255 ) surface.SetTextPos( 34, (ScrH()/2)+(ScrH()/4) ) surface.SetFont("moneh") surface.DrawText( person:GetMoney() ) end [/lua] Ninja'd :3 Mine works, and his do to.[/QUOTE] Thanks. xD I already thought someone would ninja it, but its no problem, since its just from the first page u get from google when u type in ''Money System Lua'' xD lol
Sorry, you need to Log In to post a reply to this thread.