• RP money system!
    8 replies, posted
I am working on a RP Gamemode from the start i dont wanna use DarkRP or something else i want to create a mod from 0 lines to xxxxx but i have a problem how to create a money system that gives all player money and so its keeping i dont know anything about it so pls help i have seen some codes from DarkRP. they says [Lua] function meta:CanAfford(amount) if math.floor(amount) < 0 or DB.RetrieveMoney(self) - math.floor(amount) < 0 then return false end return true end ------------------------------------------------------------------------------------------- function meta:AddMoney(amount) DB.StoreMoney(self, DB.RetrieveMoney(self) + math.floor(amount)) end [/lua] thats the codes i found and my lua cooding frind the guy who created The Rebel-Tech RP mod said that it has something to do whit the money thing in DarkRP so pls help me!
First, this belongs to the lua help section. Now, if you want the money to save on disconnect and be there, your going to have to create an sql database to keep all the data in. The first function you specified there will check if you can afford the thing you are buying. The second will indeed let you add money. I don't mean anything harmful, but i don't think you have the knowledge to make a completly new gamemode yet, i suggest you start off by editing dark rp a little, and then moving on to creating samll scripts.
yes but how to do all this?
First off, go to thi link and read up on LUA syntaxes, values and some basic commands. you dont have to read it all. [url]http://www.lua.org/pil/[/url] After you have gotten to about part 1, chapter 9, you can try and start making basic scripts in garrys mod using these small tuts. [url]http://wiki.garrysmod.com/?title=Lua_Tutorial_Series[/url] Hope i was to any help.
ok thanks but i still need to read alot of stuff
[lua]local pmeta = FindMetaTable("Player") function pmeta:CanAfford( amount ) if ( self:GetNWInt("Money") - math.floor(amount) < 0 ) then return false else return true end end function MoneyInitialSpawn( ply ) local Money = "Money/" .. ply:UniqueID() .. ".txt" if file.Exists( Money ) then ply:SetNWInt( "Money", tonumber( file.Read( Money ) ) ) else file.Write( Money, 0 ) end end hook.Add( "PlayerInitialSpawn", "MoneyInitialSpawn", MoneyInitialSpawn ) function pmeta:AddMoney( amount ) self:SetNWInt( "Money", self:GetNWInt("Money") + math.floor(amount or 0) ) file.Write( "Money/" .. self:UniqueID() .. ".txt" , self:GetNWInt("Money") ) end[/lua]
Please use Lua tags.
[QUOTE=thoron174;19684977][lua]local pmeta = FindMetaTable("Player") function pmeta:CanAfford( amount ) if ( self:GetNWInt("Money") - math.floor(amount) < 0 ) then return false else return true end end function MoneyInitialSpawn( ply ) local Money = "Money/" .. ply:UniqueID() .. ".txt" if file.Exists( Money ) then ply:SetNWInt( "Money", tonumber( file.Read( Money ) ) ) else file.Write( Money, 0 ) end end hook.Add( "PlayerInitialSpawn", "MoneyInitialSpawn", MoneyInitialSpawn ) function pmeta:AddMoney( amount ) self:SetNWInt( "Money", self:GetNWInt("Money") + math.floor(amount or 0) ) file.Write( "Money/" .. self:UniqueID() .. ".txt" , self:GetNWInt("Money") ) end[/lua][/QUOTE] [lua]local pmeta = _R.Player function pmeta:CanAfford(amount) return self:GetPData("Money") >= amount end hook.Add("PlayerInitialSpawn", "MoneyInitialSpawn", function(ply) ply:SetPData("Money", ply:GetPData("Money") or 0) end) function pmeta:AddMoney(amount) self:SetPData("Money", self:GetPData("Money") + math.floor(amount or 0)) end[/lua]
I think thorons mpost was the most usefull :D
Sorry, you need to Log In to post a reply to this thread.