--Banking Script --By Looter --July 5th, 07 BankCMD = { } function BankCMD.CreateBank() if not file.IsDir("Bank") then file.CreateDir("Bank") end; local info = { } info.ru = 300 info.lasthistory = tostring( os.date() ) local fpath = "Bank/bank.txt" file.Write(fpath, util.TableToKeyValues(info)); LogAdv("Bank/BankLog.txt","Bank created on ".. info.lasthistory ) print("Bank Created."); end concommand.Add( "debug_bank_create", BankCMD.CreateBank ); function BankCMD.AddMoney( args ) if( args == "" ) then return ""; end local amt = tonumber( args ); --File Reading/Creating local bpath = "Bank/bank.txt" if not file.Exists(bpath) then BankCMD.CreateBank() end --Handling the money. local info = util.KeyValuesToTable(file.Read(bpath)) --Defining our args. local newamount = amt + info.ru --Add it all up info.ru = newamount info.lasthistory = tostring( os.date() ) --Write new data file.Write(bpath, util.TableToKeyValues(info)); print("Added ".. info.ru .." To the Bank, On ".. info.lasthistory ); LogAdv("Bank/BankLog.txt","Added ".. info.ru .." To the Bank, On ".. info.lasthistory ) end function BankCMD.CanAfford( args ) local bpath = "Bank/bank.txt" local info = util.KeyValuesToTable(file.Read(bpath)) if( args == "" ) then return ""; end local amt = tonumber( args ); if amt > info.ru then return false; else return true; end end function BankCMD.RemoveMoney( args ) if( args == "" ) then return ""; end local amt = tonumber( args ); if( amt > 500 ) then return false; end --File Reading/Creating local bpath = "Bank/bank.txt" if not file.Exists(bpath) then BankCMD.CreateBank() end --Handling the money. local info = util.KeyValuesToTable(file.Read(bpath)) --Defining our args. local newamount = info.ru - amt --Add it all up info.ru = newamount info.lasthistory = tostring( os.date() ) --Write new data file.Write(bpath, util.TableToKeyValues(info)); print("Removed ".. info.ru .." From the Bank, On ".. info.lasthistory ); LogAdv("Bank/BankLog.txt","Removed ".. info.ru .." From the Bank, On ".. info.lasthistory ) end function BankCMD.Withdraw(ply, args) if( args == "" ) then return ""; end local amt = tonumber( args ); local bpath = "Bank/bank.txt" if not file.Exists(bpath) then BankCMD.CreateBank() end if( ply:GetNWString( "faction" ) == "Traders" ) then if( BankCMD.CanAfford( amt ) ) then if( amt > 500 ) then ply:PrintMessage(3, "The amount cannot be over 500 RU." ); end ply:AddMoney( amt ); BankCMD.RemoveMoney( args ); SilentSave(ply); LogAdv("Bank/BankLog.txt","SteamID: ".. ply:SteamID() .."\nName: ".. ply:Nick() .."\n Withdrawed ".. amt .." RU") print( amt .." Withdrawn from bank, By ".. ply:Nick() ); ply:PrintMessage(3, amt .." RU - Withdrawn from bank, This action has been logged, Failure to pay or abuse of this will be punished."); else ply:PrintMessage(3, "Not enough Funds in bank!"); end else ply:PrintMessage(3, "Only traders can Deposit and Withdraw from UTU Bank." ); end return ""; end AddChatCommand( "/withdraw", BankCMD.Withdraw ); function BankCMD.Deposit( ply, args ) if( args == "" ) then return ""; end local amt = tonumber( args ); local bpath = "Bank/bank.txt" if not file.Exists(bpath) then BankCMD.CreateBank() end if( ply:GetNWString( "faction" ) == "Traders" ) then if( not ply:CanAfford( amt ) ) then ply:PrintMessage(3, "You cannot afford to deposit ".. amt ); end if( amt < 500 ) then ply:PrintMessage(3, "The amount cannot be over 500 RU." ); ply:AddMoney( amt * -1 ); BankCMD.AddMoney( args ); SilentSave(ply); LogAdv("Bank/BankLog.txt","SteamID: ".. ply:SteamID() .."\nName: ".. ply:Nick() .."\n Deposited ".. amt .." RU") print( amt .." Added to bank, By ".. ply:Nick() ); ply:PrintMessage(3, amt .." RU - Added to bank, Thankyou for your contribution."); else ply:PrintMessage(3, "The amount cannot be over 500 RU." ); end else ply:PrintMessage(3, "Only traders can Deposit and Withdraw from UTU Bank." ); end return ""; end AddChatCommand( "/deposit", BankCMD.Deposit ); function BankCMD.GetData( ply ) if( not Admins[ply:SteamID()] ) then ply:PrintMessage(2, "Not a valid command" ); end local curlog = file.Read( "Bank/bank.txt" ) local curtable = { } table.insert(curtable,curlog); for k,v in pairs(curtable) do ply:PrintMessage(2, v ); end end concommand.Add( "bank_getdata", BankCMD.GetData ) --Saving Script --By Looter --June 28th, 07 function ListChar( ply ) local i = ply:SteamID() local list = file.Find("stalker_profiles/"..string.gsub(i, ":", "_").."_*.txt") ply:PrintMessage(2, "Characters:\n") if( list ) then for _, f in pairs(list) do ply:PrintMessage(2, f .."\n" ) end end end concommand.Add( "character_list", ListChar ); function CharHelp( ply ) ply:PrintMessage( 2, "\n\n--Character Help--" ); ply:PrintMessage( 2, "-Console Commands" ); ply:PrintMessage( 2, "character_save (Saves character, /save)" ); ply:PrintMessage( 2, "character_load (Loads character, /load)" ); ply:PrintMessage( 2, "character_list (Displays list of characters)" ); ply:PrintMessage( 2, "character_remove (Removes a character, EG. character_remove ".. ply:Nick() ..")" ); ply:PrintMessage( 2, "character_data (Displays current weapons saved to character)" ); ply:PrintMessage( 2, "-Chat Commands" ); ply:PrintMessage( 2, "/save (Saves your character)" ); ply:PrintMessage( 2, "/load (Loads your character)" ); ply:PrintMessage( 2, "\n--How Do I work this?--" ); ply:PrintMessage( 2, "-Basic Info" ); ply:PrintMessage( 2, "To make a new character, change your name, then /load." ); ply:PrintMessage( 2, "If it says you have to many characters, remove some!, You can only have 4." ); ply:PrintMessage( 2, "Ask an admin/regular player for anymore help you might need." ); ply:PrintMessage( 2, "Report bugs to Looter.\n" ); end concommand.Add( "character_help", CharHelp ); function RemoveChar( ply, cmd, args ) local i = ply:SteamID() local char = args[1] if file.Exists("stalker_profiles/"..string.gsub(i, ":", "_").."_".. char ..".txt") then file.Delete("stalker_profiles/"..string.gsub(i, ":", "_").."_".. char ..".txt") file.Delete("stalker_profiles/"..string.gsub(i, ":", "_").."_".. char .."_hard-data.txt") ply:PrintMessage( 3, "Character - ".. char .." Deleted." ); ply.Characters = ply.Characters - 1 Log("Character ".. ply:Nick() .." Removed!"); if( char == ply:Nick() ) then ply:SilentKill() LoadChar( ply ) end else ply:PrintMessage( 3, "Character - ".. char .." Does not exist." ); end end concommand.Add( "character_remove", RemoveChar ); function NewCharacter( ply ) local i = ply:SteamID() local chars = ply:GetNWInt( "Characters" ) local info = { } local data = { } if( chars > 4 ) then ply:PrintMessage( 3, "[GameGuard] To many characters to this account! You cannot make anymore characters!" ); ply:PrintMessage( 3, "[GameGuard] Change your name back to an existing character please." ); else info.name = ply:Nick() info.ru = 300 info.rank = "Novice" info.job = "S.T.A.L.K.E.R" info.faction = "STALKERs" info.characters = ply:GetNWInt( "Characters" ) data.weapons = {"keys","gravgun","physgun"} data.model = ply:GetModel(); info.weapons = {} for k,v in pairs( ply:GetWeapons() ) do info.weapons[k] = v:GetClass() end Log("[GameGuard] New Character '".. ply:Nick() .."' Created!"); local fpath = "stalker_profiles/"..string.gsub(i, ":", "_").."_".. ply:Nick() ..".txt" local dpath = "stalker_profiles/"..string.gsub(i, ":", "_").."_".. ply:Nick() .."_hard-data.txt" file.Write(fpath, util.TableToKeyValues(info)); file.Write(dpath, util.TableToKeyValues(data)); ply:PrintMessage( 3, "[GameGuard] New Character - ".. ply:Nick() .." Created." ); print("\n[GameGuard] Character '".. ply:Nick() .."' Created."); LoadChar( ply ); ply:KillSilent() end return ""; end concommand.Add( "character_new", NewCharacter ); function GetData( ply ) local i = ply:SteamID() local fpath = "stalker_profiles/"..string.gsub(i, ":", "_").."_".. ply:Nick() ..".txt" local info = util.KeyValuesToTable(file.Read(fpath)) for k,v in pairs(info.weapons) do ply:PrintMessage(2, v ); end end concommand.Add( "character_data", GetData) function LoadChar( ply ) local i = ply:SteamID() local fpath = "stalker_profiles/"..string.gsub(i, ":", "_").."_".. ply:Nick() ..".txt" local dpath = "stalker_profiles/"..string.gsub(i, ":", "_").."_".. ply:Nick() .."_hard-data.txt" if not file.Exists(fpath) then NewCharacter( ply ) else local info = util.KeyValuesToTable(file.Read(fpath)) local data = util.KeyValuesToTable(file.Read(dpath)) ply:SetNWString( "job", info.job ) ply:SetNWString( "Rank", info.rank ) ply:SetNWString( "faction", info.faction ) ply:SetNWInt( "money", info.ru ); ply:SetNWInt( "Characters", info.characters ) ply:GetTable().PlayerModel = data.model; ply:SetModel(data.model); if info.weapons then for k,v in pairs( info.weapons ) do ply:GiveWeapon( v ) print( v ); end end Log( ply:SteamID() .." Loaded ".. ply:Nick() ); ply:PrintMessage( 3, "Character Data for ".. ply:Nick() .." Loaded." ); end return ""; end AddChatCommand( "/load", LoadChar ); concommand.Add( "character_load", LoadChar ); function PlayerSave( ply ) if not file.IsDir("stalker_profiles") then file.CreateDir("stalker_profiles") end; local i = ply:SteamID() local ru = ply:GetNWInt( "money" ) local rank = ply:GetNWString( "Rank" ) local plyjob = ply:GetNWString( "job" ) local faction = ply:GetNWString( "faction" ) local info = { } info.name = ply:Nick() info.ru = ru info.rank = rank info.job = plyjob info.faction = faction info.characters = ply:GetNWInt( "Characters" ) local data = { } data.weapons = { } data.model = ply:GetModel(); info.weapons = {} for k,v in pairs( ply:GetWeapons() ) do info.weapons[k] = v:GetClass() print(v:GetClass()) end Log( ply:SteamID() .." Saved ".. ply:Nick() ); local fpath = "stalker_profiles/"..string.gsub(i, ":", "_").."_".. ply:Nick() ..".txt" file.Write("stalker_profiles/"..string.gsub(i, ":", "_").."_".. ply:Nick() .."_hard-data.txt", util.TableToKeyValues(data)) file.Write("stalker_profiles/"..string.gsub(i, ":", "_").."_".. ply:Nick() ..".txt", util.TableToKeyValues(info)) ply:PrintMessage( 3, "Character ".. ply:Nick() .." Saved." ); print(tostring(info) .."\n\n Saved to '".. fpath .."'"); return ""; end AddChatCommand( "/save", PlayerSave ); concommand.Add( "character_save", PlayerSave ); function SilentSave( ply ) if not file.IsDir("stalker_profiles") then file.CreateDir("stalker_profiles") end; local i = ply:SteamID() local ru = ply:GetNWInt( "money" ) local rank = ply:GetNWString( "Rank" ) local plyjob = ply:GetNWString( "job" ) local faction = ply:GetNWString( "faction" ) local info = { } info.name = ply:Nick() info.ru = ru info.rank = rank info.job = plyjob info.faction = faction local data = { } data.model = ply:GetModel(); info.weapons = {} for k,v in pairs( ply:GetWeapons() ) do info.weapons[k] = v:GetClass() end local fpath = "stalker_profiles/"..string.gsub(i, ":", "_").."_".. ply:Nick() ..".txt" file.Write(fpath, util.TableToKeyValues(info)); file.Write("stalker_profiles/"..string.gsub(i, ":", "_").."_".. ply:Nick() .."_hard-data.txt", util.TableToKeyValues(data)) return ""; end function GlobalSave( ply ) if( Admins[ply:SteamID()] ) then for _, ply in pairs( player.GetAll() ) do SilentSave( ply ); Log("Global save executed."); ply:PrintMessage( 2, "Data for \n".. tostring(ply) .."\n Saved!."); end else ply:PrintMessage(2, "Not a valid command."); end end concommand.Add( "globalsave", GlobalSave)