Okay, I am not seeing much on this topic I have so much so far, but i need to add more.
function buy ()
if ply:money () == #
then ply: TakeMoney (100)
ply:Give("-WEAPON-")
ply:ChatPrint("you purchased -WEAPON-")
else
ply:ChatPrint("You do not have enough cash")
end
^^^
I need like meta examples for things like-
Save players money
get money
buy/sell (Loose/gain) - both
set money
and add money
If you can contribute and help please do so, I am looking at tutorials now, but mine is a bit off from the tuts I am seeing.
Please help thanks, nathien20
P.S. I will add the exp part soon, I may be able to convert the cash part into the exp though.
How would you like this being saved? MySQL, SQLitle, PData, Text?
[lua]
local meta = FindMetaTable("Player");
function meta:AddMoney( amount )
self:SetNetworkedInt("money", amount)
end[/lua]
[QUOTE=c-unitV2;29579243][lua]
local meta = FindMetaTable("Player");
function meta:AddMoney( amount )
self:SetNetworkedInt("money", amount)
end[/lua][/QUOTE]
Not very useful, this is the questions section and he's meant to know how to use NetWorkVars?
Also, this does not save anything or do anything to his use.
PData or text would both work I believe, I know very little on MySQL.
Ok well I've just climbed in bed so I'll do this for you tomorrow.
I don't wanna type from my phone cause I can't comment easily and organise it.
[lua]local meta = FindMetaTable("Player")
function meta:SetCurrency( intAmount )
self:SetNetworkedInt("currency", intAmount)
self:UpdateCurrency()
end
function meta:UpdateCurrency()
self:SetNetworkedInt("currency", self:GetCurrency())
end
function meta:GetCurrency()
return self:GetNetworkedInt("currency");
end
function meta:AddCurrency( intAmount )
self:SetCurrency( self:GetCurrency() + intAmount )
end
function meta:TakeCurrency( intAmount )
self:SetCurrency( self:GetCurrency() - intAmount )
end
function meta:SaveCurrency()
cig = self:GetCurrency()
s_id = self:SteamID()
data = "SELECT cig FROM player_currency WHERE s_id = '"..s_id.."'"
if( sql.Query( data ) != 0 ) then
sql.Query("UPDATE player_currency SET cig = ".. cig .." WHERE s_id = '"..s_id.."'")
else
sql.Query("INSERT INTO player_currency ('s_id', 'cig') VALUES ('"..s_id.."', '"..cig.."')")
end
print("Query updated!")
end[/lua]
you will have to change the values yourself if you dont like them cig being the money and s_id is the steam id
[lua]--Made By Aperture (Science)
local meta = FindMetaTable("Player") -- Sets The Player Meta Table
--===SetMoney Usage===
--calling on a player use the following
--player:SetMoney( 100 )
--This sets the players money to 100
function meta:SetMoney( am )
self:SetPData("money", am )
end
--===GiveMoney Usage===
--calling on a player use the following
--player:~GiveMoney( 100 )
--This gives the player $100 or what ever currency
function meta:GiveMoney( am )
local curG = self:GetPData("money")
self:SetPData("money", curG + am )
end
--===TakeMoney Usage===
--calling on a player use the following
--player:TakeMoney( 100 )
--This removes $100 or what ever currency from the players money
function meta:TakeMoney( am )
local curT = self:GetPData("money")
self:SetPData("money", curT - am )
end
--===CanAffford Usage===
--calling on a player use the following
--player:CanAfford( 100 )
--This will check if the player has at least 100 and return
--true if he does or false if he has less than $100
function meta:CanAfford( am )
local curA = self:GetPData("money")
if curA >= am then return true else return false end
end
--===BuyWeapon Usage===
--calling on a player use the following
--player:BuyWeapon( 100, "gmod_tool")
--This will check if the player can afford $100
--then remove $100 and give them a toolgun
function meta:BuyWeapon( am, wep )
if !wep or !am then return end
local curM = self:GetPData("money")
if CurM >= am then self:TakeMoney( am ); self:Give( wep ) end
end
[/lua]
Everything is documented inside the file.
It automatically saves everything on change.
[I]Stupid Multiline comments are broken so i changed them for ease of read for you.[/I]
[lua]if SERVER then
local PAY_PAYDAY = 100
for _,ply in pairs (player.GetAll()) do
ply:GiveMoney( PAY_PAYDAY )
umsg.Start("Payday", ply)
umsg.Long( PAY_PAYDAY )
umsg.End();
end
end
if CLIENT then
usermessage.Hook("Payday", function ( um )
local Am = um:ReadLong()
chat.AddText(Color(255,0,0),"[Payday] ",Color(255,255,255),"You have been given $",Color(0,255,0), tostring(Am),Color(255,255,255),"!")
end)
end[/lua]
This example prints to everyones chat [B][Payday] You have been given $100![/B]
What do I have to do to show the money in a menu or HUD?
[code]function meta:hasmoney -- this is the wanted function, do I need to make a separate one to show money?[/code] what would I be able to put after that? I am using the one Science gave.
[edit] I figured I would add Science is getting credit for the currency/money.. So thanks Science, by the way this is for a game-mode and possibly an add-on.
Use a network variable with a long or float value to print the money to a players hud.
[QUOTE=Science;29588910]Use a network variable with a long or float value to print the money to a players hud.[/QUOTE]
Ew. Just make it serverside and usermessage it to the client when it changes.
C-Unit.
SetCurrency sets the NWInt and runs UpdateCurrency.
UpdateCurrency sets the var to itself. I call overcomplicating.
Everyone in this thread should be ashamed of their self by just spoon feeding the OP you have doomed him to fail, we are now going to get threads for every feature of his gamemode.
[editline]3rd May 2011[/editline]
I love how Science rated me agree when he is one of the people
[QUOTE=King Flawless;29590579]Everyone in this thread should be ashamed of their self by just spoon feeding the OP you have doomed him to fail, we are now going to get threads for every feature of his gamemode.
[editline]3rd May 2011[/editline]
I love how Science rated me agree when he is one of the people[/QUOTE]
I thought exactly the same. I reccomended him to look at DarkRP and see how things work there, it'd be loads easier.
Goodluck tho.
or he could copy and paste right off the wiki
[QUOTE=c-unitV2;29592477]or he could copy and paste right off the wiki[/QUOTE]
And this helps him in what way?
Also, what reason is there to rate my post dumb cause from what i can read down to, you are upset i outdone you so you rated me dumb. Well played good sir.
[QUOTE=Science;29593081]And this helps him in what way?
Also, what reason is there to rate my post dumb cause from what i can read down to, you are upset i outdone you so you rated me dumb. Well played good sir.[/QUOTE]
1. It helps him because the wiki sqlite tutorials and money system will be just fine for what he needs instead of using code spoonfed code from facepunch( since flawless bought it up, he will learn more if he writes it himself )
2. I rate you dumb because your post is dumb, and in no way will you ever "outdo" me. Come try, anything you do i will do 5x better :).
3. My code networks and saves the data while yours will only save it, thus mine has more features making your code obsolete( aside from the UpdateCurrency() function, which he can fix ).
4. Saying good sir after everytime you think you zing someone just makes you look like a bigger dumbfuck then you really are, so stop.
[QUOTE=Science;29593081]And this helps him in what way?
Also, what reason is there to rate my post dumb cause from what i can read down to, you are upset i outdone you so you rated me dumb. Well played good sir.[/QUOTE]
You seem to do your self no favours as soon as you start to seem less idiotic you jump right back in with a post like this.
[QUOTE=beasty;29611508][img_thumb]http://i52.tinypic.com/5e5zte.png[/img_thumb]
Lol'd[/QUOTE]
Wow, do you really not know how to crop pictures?
So what, i agree with him.
Also, Funny ratings are there for a reason.
Inb4 Backseat Moderation.
[QUOTE=Science;29611756]Wow, do you really not know how to crop pictures?
So what, i agree with him.
Also, Funny ratings are there for a reason.
Inb4 Backseat Moderation.[/QUOTE]
1st. Asking him if he doesnt know how to crop pictures makes you look pathetic.
2nd. You agree with him that you make yourself look dumb every chance you get?
3rd. you arent as cool as 4chan
[QUOTE=c-unitV2;29614090]1st. Asking him if he doesnt know how to crop pictures makes you look pathetic.
2nd. You agree with him that you make yourself look dumb every chance you get?
3rd. you arent as cool as 4chan[/QUOTE]
4chan is now cool?
Also i dont agree that i look dumb at every chance, just most.
trust me, you always look dumb
[QUOTE=c-unitV2;29614757]trust me, you always look dumb[/QUOTE]
Well so do you making this post.
Wanna carry this on? PM me then.
[sp]You aint no flawless, give the fuck up will ya[/sp]
OP, was your question answered?
Do you need anymore help on the matter?
[QUOTE=Commander11;29624898]OP, was your question answered?
Do you need anymore help on the matter?[/QUOTE]
OP is away.
Just like half the board, people make an account, ask a question, we answer, they forget.
[QUOTE=Science;29627304]OP is away.
Just like half the board, people make an account, ask a question, we answer, they forget.[/QUOTE]
By 'we' I hope you mean users who know how to script in lua
[editline]5th May 2011[/editline]
normally i don't condone noobie bashing however for you it's a whole 'nother story..
[QUOTE=c-unitV2;29627331]By 'we' I hope you mean users who know how to script in lua
[editline]5th May 2011[/editline]
normally i don't condone noobie bashing however for you it's a whole 'nother story..[/QUOTE]
Yea ok... Insulting me over the Internet, how cool are you.
By 'we' I mean the board and it's posters and I think you will find that I can script, not the best but by far not the worst.
[QUOTE=Science;29627383]Yea ok... Insulting me over the Internet, how cool are you.
By 'we' I mean the board and it's posters and I think you will find that I can script, [b]not the best but by far not the worst.[/b][/QUOTE]
So far i haven't seen you post any useful code anywhere
Third post in this thread.
And the few others I've helped, you must really be blind.
Sorry, you need to Log In to post a reply to this thread.