Author Topic: Cash System?  (Read 13003 times)

0 Members and 2 Guests are viewing this topic.

Offline spbogie

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 456
  • Karma: 41
Re: Cash System?
« Reply #15 on: June 22, 2007, 02:48:06 PM »
GD, if you are just using SteamID to store how much money people have, use UniqueID instead.
I have not failed. I've just found 10,000 ways that won't work. - Thomas A. Edison
I reject your reality and substitute my own. - Adam Savage

Offline Golden-Death

  • Hero Member
  • *****
  • Posts: 751
  • Karma: 0
  • Honored Lua Scripter
    • BlueFire
Re: Cash System?
« Reply #16 on: June 22, 2007, 03:02:52 PM »
It's all good. I just stored their ID to their name as soon as it becomes available.


Offline TomatoSoup

  • Newbie
  • *
  • Posts: 40
  • Karma: 3
Re: Cash System?
« Reply #17 on: June 24, 2007, 06:19:36 PM »
No, the point of this is just so that players can trade with each other, things like resources.

Something like this, "Hey, I need to top off my ships energy real quick like, 2000 cash for 5000 energy?"

Or, if someone owns a rapid transport system, they can say "hey, 50 cash to get me to the city."

Yeah, the point of this is for the clients to be able to use this cash, and I don't want any other portion of RP. Just the cash, for the win.

One more idea, needs to have a variable built into it for like, how much cash you get daily. Real time days.

And no, not a permanent HUD.

And make sure that the Admins can't use take and award, SuperAdmin only.

I trust my admins, but I'm sure they will give themselves bonuses while I'm away.

EDIT by Megiddo: Merged triple post
« Last Edit: June 24, 2007, 06:31:05 PM by Megiddo »

Offline Golden-Death

  • Hero Member
  • *****
  • Posts: 751
  • Karma: 0
  • Honored Lua Scripter
    • BlueFire
Re: Cash System?
« Reply #18 on: June 30, 2007, 03:53:40 PM »
I made the HUD toggle-able since I already went to the trouble of making it ().

If I can fix the give command it will be ready to release.

Edit: Ready! Try it out and let me know what you think. Just install it into addons and get ingame and enter !gcash help

« Last Edit: June 30, 2007, 04:51:36 PM by Golden-Death »


Offline TomatoSoup

  • Newbie
  • *
  • Posts: 40
  • Karma: 3
Re: Cash System?
« Reply #19 on: July 01, 2007, 09:21:01 AM »
TomatoSoup is Pleased.

I would test it right away, but the guys are like "Rawr, no restart for you! we building!"

Does this start everyone out with 200 cashes?

Offline TomatoSoup

  • Newbie
  • *
  • Posts: 40
  • Karma: 3
Re: Cash System?
« Reply #20 on: July 01, 2007, 09:33:36 AM »
Hmm, I used !gcash help, and that worked. None of the other commands work after that. And !gcash help even failed for other people.

So one command works, and then it dies...
« Last Edit: July 01, 2007, 09:37:42 AM by TomatoSoup »

Offline TomatoSoup

  • Newbie
  • *
  • Posts: 40
  • Karma: 3
Re: Cash System?
« Reply #21 on: July 01, 2007, 09:34:38 AM »
ERROR: Hook 'Cash Command' Failed: CashSystem/goldencash.lua:166: attempt to concatenate field '?' (a nil value)
Removing Hook 'Cash Command'

Offline Golden-Death

  • Hero Member
  • *****
  • Posts: 751
  • Karma: 0
  • Honored Lua Scripter
    • BlueFire
Re: Cash System?
« Reply #22 on: July 01, 2007, 10:18:15 AM »
Weird, I'll look into it.


Offline TomatoSoup

  • Newbie
  • *
  • Posts: 40
  • Karma: 3
Re: Cash System?
« Reply #23 on: July 01, 2007, 11:45:18 AM »
!gcash check is what breaks it, every command worked until then.

Rather, Hud worked, and award worked.

And even then, the Hud never appeared, even if I did !gcash hud show.

Offline Golden-Death

  • Hero Member
  • *****
  • Posts: 751
  • Karma: 0
  • Honored Lua Scripter
    • BlueFire
Re: Cash System?
« Reply #24 on: July 01, 2007, 03:09:08 PM »
Alright, thanks for the testing


Offline Golden-Death

  • Hero Member
  • *****
  • Posts: 751
  • Karma: 0
  • Honored Lua Scripter
    • BlueFire
Re: Cash System?
« Reply #25 on: July 01, 2007, 07:30:27 PM »
I don't really know what the problem is. It seems to be thinking one of my variables is nil, but that same variable works fine with everything else, if you are correct in saying everything else works. I don't know why the HUD wouldn't be showing.

See if you have the clientside file (golden_cl.lua) in your lua folder, and check to make sure that garrysmod/data/Data Cash/(your steam id)_pref.txt says "true" inside. Hmmm.


Offline TomatoSoup

  • Newbie
  • *
  • Posts: 40
  • Karma: 3
Re: Cash System?
« Reply #26 on: July 02, 2007, 07:27:29 AM »
Maybe my CustomHud overwrites the existing hud?

And just before it calls the variable, do a

variable = variable or 0, I do that whenever I get an error, and it tends to eliminate the error, yet continue to function perfectly.

Offline TomatoSoup

  • Newbie
  • *
  • Posts: 40
  • Karma: 3
Re: Cash System?
« Reply #27 on: July 02, 2007, 07:32:26 AM »
Theres nothing in data/datacash. I awarded myself 100 just as a test, and it didn't save that?

Maybe it's returning nil because it doesn't have anything to check? In that case, still do the variable = variable or 0 so we don't loose the hook.

Offline Golden-Death

  • Hero Member
  • *****
  • Posts: 751
  • Karma: 0
  • Honored Lua Scripter
    • BlueFire
Re: Cash System?
« Reply #28 on: July 02, 2007, 12:38:11 PM »
I'll add some more debug messages so I can see where it's hanging up for you.

Alright try this, and connect to your server. Then try out all the stuff and give me the full console log so I know what's up with it.

If this doesn't work, I could also try running a listen server to test it, if my router isn't messed up.

The best thing to do, if you still want it, would be for me to recode it. It's a bit hacky, which is probably why it has so many issues.


Replace goldencash.lua
Code: [Select]
--Goldencash System By Golden-Death. Duuuh. --

AddCSLuaFile( "golden_cl.lua" )
include("golden_cl.lua")


GCashDefaultStartMoney = 200


PlyCash = {}
PlayID = {}

function GCashInit(ply)
local id = ply:SteamID()
PlayID[ply] = id
if PlayID[ply] == nil then
Msg("ERROR: Player: "..ply:Nick().."'s ID was nil!\n")
else
Msg("No problems! Stored "..ply:Nick().."'s ID as "..PlayID[ply].."\n")
end
if (not file.IsDir("datacash")) then
  file.CreateDir("datacash")
  Msg("Data directory not found. Creating one now.\n")
end

 if not file.Exists("datacash/"..PlayID[ply]..".txt") then
  file.Write("datacash/"..PlayID[ply]..".txt",GCashDefaultStartMoney)
  Msg("Data for "..PlayID[ply].." not found. Creating one now.\n")
 end
  if file.Exists("datacash/"..PlayID[ply]..".txt") then
  Msg("Data for "..PlayID[ply].." found. Loading.\n")
  local gdata = file.Read("datacash/"..PlayID[ply]..".txt")
  GCashLoad(ply, PlayID[ply], gdata)
  Msg("Loaded data.\n")
 end
local rp = RecipientFilter() // Grab a RecipientFilter object
rp = rp:AddPlayer(ply)
umsg.Start("updatecash", rp)
umsg.Long(PlyCash[PlayID[ply]])
umsg.End()
GCashPrefLoad(ply)
Msg("Now sending cash to client and updating prefs\n")
end

function GCashPrefLoad(ply)
 if not file.Exists("datacash/"..PlayID[ply].."_prefs.txt") then
  file.Write("datacash/"..PlayID[ply].."_prefs.txt", "true")
  Msg("Preferences for "..PlayID[ply].." not found. Creating one now.\n")
 end
  if file.Exists("datacash/"..PlayID[ply].."_prefs.txt") then
  Msg("Preferences for "..PlayID[ply].." found. Loading.\n")
  local gp = file.Read("datacash/"..PlayID[ply].."_prefs.txt")
  if gp == "false" then
  ply:PrintMessage(HUD_PRINTTALK, "[GCash] Your HUD for GCash is hidden. Type !gcash hud show to bring it back.")
  end
local rp = RecipientFilter() // Grab a RecipientFilter object
rp = rp:AddPlayer(ply)
umsg.Start("updateprefs", rp)
umsg.String(gp)
umsg.End()
Msg("Successfully sent preferences to client\n")
 end
end



function GCashLoad(ply, id, cash)
Msg("Recieved player: "..id.."\nCash: "..cash.."\n")
PlyCash[id] = cash
end

function GCashAdd(ply, rec, id, cash)
PlyCash[id] = PlyCash[id] + math.Round(cash)
rec:PrintMessage(HUD_PRINTTALK, "[GCash] "..ply:Nick().." has awarded you "..math.Round(cash).." dollars.\n")
GCashStore(rec)
end
--(ply, v, PlayID[v], PlayID[ply], stt[4])
function GCashTrade(ply, rec, recid, plyid, cash)
PlyCash[recid] = PlyCash[recid] + math.Round(cash)
PlyCash[plyid] = PlyCash[plyid] - math.Round(cash)
rec:PrintMessage(HUD_PRINTTALK, "[GCash] "..ply:Nick().." has given you "..math.Round(cash).." dollars.\n")
GCashStore(rec)
end

function GCashSub(ply, rec, id, cash)
PlyCash[id] = PlyCash[id] - math.Round(cash)
rec:PrintMessage(HUD_PRINTTALK, "[GCash] "..ply:Nick().." has taken "..math.Round(cash).." dollars from you.\n")
GCashStore(rec)
end

function GCashStore(ply)
--for k,v in pairs(player.GetAll()) do
Msg("Saving cash...\n")
file.Write("datacash/"..PlayID[ply]..".txt", PlyCash[PlayID[ply]])
local rp = RecipientFilter() // Grab a RecipientFilter object
rp = rp:AddPlayer(ply)
umsg.Start("updatecash", rp)
umsg.Long(PlyCash[PlayID[ply]])
umsg.End()
Msg("Saved data for "..PlayID[ply].."\nSaved "..PlyCash[PlayID[ply]].."\n")
end
--end

function GCashPrefSave(ply, opt)
if not file.Exists("datacash/"..PlayID[ply].."_prefs.txt") then
  file.Write("datacash/"..PlayID[ply].."_prefs.txt", opt)
  Msg("Preferences for "..PlayID[ply].." not found. Creating one now.\n")
 end
  if file.Exists("datacash/"..PlayID[ply].."_prefs.txt") then
  Msg("Preferences for "..PlayID[ply].." found. Loading.\n")
file.Write("datacash/"..PlayID[ply].."_prefs.txt", opt)
 end
end


function GCCommand( ply, cmd )
    --Award Command--
if (string.find(cmd, "!gcash award")) then
if not ply:IsSuperAdmin( ) then
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Only admins can use this command.")
return "";end
local stt = string.Explode( " ", cmd )
if stt[3] == nil or stt[4] == nil then
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Not enough arguments were passed! (!gcash give player amount)")
return "";end
if tonumber(stt[4]) == nil then
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Error: Something was wrong with the amount you tried to award.")
return "";end
for k,v in pairs(player.GetAll()) do
local ns = string.lower(v:GetName())
if (string.find(ns, stt[3])) then
GCashAdd(ply, v, PlayID[v],stt[4])
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Awarding "..math.Round(stt[4]).." dollars to "..v:Nick()..".")
end
return ""
end
end

--Give Command--
if (string.find(cmd, "!gcash give")) then
local stt = string.Explode( " ", cmd )
if stt[3] == nil or stt[4] == nil then
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Not enough arguments were passed! (!gcash give player amount)")
return "";end
if tonumber(stt[4]) == nil then
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Error: Something was wrong with the amount you tried to give.")
return "";end
for k,v in pairs(player.GetAll()) do
local ns = string.lower(v:GetName())
if (string.find(ns, stt[3])) then
if tonumber(PlyCash[PlayID[ply]]) < tonumber(stt[4]) then
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Sorry "..ply:Nick()..", but you only have "..PlyCash[PlayID[ply]].." dollars. You cannot give "..v:Nick().." "..math.Round(stt[4]).." dollars.")
return "";end
if tonumber(stt[4]) < 1 then
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Sorry "..ply:Nick()..", but you cannot give players negative cash. Duh.")
return "";end
GCashTrade(ply, v, PlayID[v], PlayID[ply], stt[4])
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Giving "..math.Round(stt[4]).." of your dollars to "..v:Nick()..".")
end
return ""
end
end

--Save Command--
if (string.find(cmd, "!gcash save")) then
GCashStore(ply)
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Your cash has been saved. ("..PlyCash[PlayID[ply]]..")")
return ""
end

--Check Command--
if (string.find(cmd, "!gcash check")) then
PlyCash[PlayID[ply]] = PlyCash[PlayID[ply]] or 0
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Your cash is: "..PlyCash[PlayID[ply]])
return ""
end

--Pref Command-
if (string.find(cmd, "!gcash hud")) then
local stt = string.Explode( " ", cmd )
if stt[3] == nil then
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Not enough arguments were passed! (!gcash hud show or hide)")
return "";end
if stt[3] == "show" then
ply:PrintMessage(HUD_PRINTTALK, "[GCash] HUD on.")
local rp = RecipientFilter() // Grab a RecipientFilter object
rp = rp:AddPlayer(ply)
umsg.Start("updateprefs", rp)
umsg.String("true")
umsg.End()
GCashPrefSave(ply, "true")
Msg("Successfully sent pref to client to show\n")
end
if stt[3] == "hide" then
ply:PrintMessage(HUD_PRINTTALK, "[GCash] HUD off.")
local rp = RecipientFilter() // Grab a RecipientFilter object
rp = rp:AddPlayer(ply)
umsg.Start("updateprefs", rp)
umsg.String("false")
umsg.End()
GCashPrefSave(ply, "false")
Msg("Successfully sent pref to client to hide\n")
end
return ""
end

--Help Command--
if (string.find(cmd, "!gcash help")) then
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Help - Say the following for the desired effect:\n!gcash award (player) (amount) - Awards a player money*")
ply:PrintMessage(HUD_PRINTTALK, "!gcash take (player) (amount) - Removes money from a player*\n!gcash list - Lists player's money")
ply:PrintMessage(HUD_PRINTTALK, "!gcash give (player) (amount) - Gives some of your money to another player\n!gcash check - Shows your money")
ply:PrintMessage(HUD_PRINTTALK, "!gcash hud (hide or show) - Toggle the HUD. Your choice is saved for later logins.\n!gcash help - Displays this help")
ply:PrintMessage(HUD_PRINTTALK, "--GCash System made by Golden-Death--   (* Admin only)")
return ""
end

--List Command--
if (string.find(cmd, "!gcash list")) then
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Displaying money for connected players:")
for k,v in pairs(player.GetAll()) do
ply:PrintMessage(HUD_PRINTTALK, v:Nick()..": "..PlyCash[PlayID[v]].." dollars.")
end
return ""
end


--Subtract Command--
if (string.find(cmd, "!gcash take")) then
if not ply:IsSuperAdmin( ) then
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Only admins can use this command.")
return "";end
local stt = string.Explode( " ", cmd )
if stt[3] == nil or stt[4] == nil then
ply:PrintMessage(HUD_PRINTTALK, "Not enough arguments were passed! (!gcash give player amount)")
return "";end
if tonumber(stt[4]) == nil then
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Error: Something was wrong with the amount you tried to take.")
return "";end
for k,v in pairs(player.GetAll()) do
local ns = string.lower(v:GetName())
if (string.find(ns, stt[3])) then
GCashSub(ply, v, PlayID[v],stt[4])
ply:PrintMessage(HUD_PRINTTALK, "[GCash] Taking "..math.Round(stt[4]).." dollars from "..v:Nick()..".")
end
return ""
end
end
end

concommand.Add("gcstore",GCashStore)
concommand.Add("gcc",GCashInit)
hook.Add ( "PlayerInitialSpawn", "Init spawn", GCashInit )
hook.Add ( "PlayerSay", "Cash Command", GCCommand )
hook.Add ( "PlayerDisconnected ", "Cash Quit", GCashStore )
« Last Edit: July 02, 2007, 01:35:14 PM by Golden-Death »


Offline TomatoSoup

  • Newbie
  • *
  • Posts: 40
  • Karma: 3
Re: Cash System?
« Reply #29 on: July 02, 2007, 01:49:13 PM »
Yeah, it would be best if you just recode the whole thing, because as is, it breaks the Contraption Saver.