Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
the account suite.
@name AccountLoader
@inputs
@outputs
@persist Accounts:gtable
@trigger
if(first() || duped()){
fileLoad("accounts.txt")
runOnFile(1)
}elseif(fileClk()){
Accounts = gTable("accounts")
Accounts:clear()
Content = fileRead()
Carr = Content:explode("|")
Num = 0
foreach(K,V:string=Carr){
Info = V:explode(";")
Sid = Info[1, string]
Money = Info[2, string]
Accounts[Sid, number] = Money:toNumber()
Num++
#print(Sid + " : "+Money+"$")
}
print("======== Done =========")
print("Loaded "+Num+" Accounts")
signalSend("updatemoney", 0)
}
@name AccountSaver
@inputs
@outputs
@persist Accounts:gtable
@trigger
if(first() || duped()){
Accounts = gTable("accounts")
timer("save", 100)
}elseif(clk("save")){
timer("save", 60000)
Str = ""
First = 1
Count = 0
foreach(K,V:number=Accounts){
if(V <= 0){
continue
}
if(!First){
Str+="|"
}
First = 0
Str+= K+";"+V
Count++
}
if(Count > 0 && fileCanWrite()){
fileWrite("accounts.txt", Str)
print("Saved "+Count+" Accounts")
}else{
print("Warning, tried to save 0 accounts")
}
}
@name BankCommands
@inputs
@outputs
@persist Accounts:gtable
@trigger
#Commands
#
# Master: !bc
#
# getowning - returns the amount you own in total to everyone
# set (player) (amount) - sets the money of player to amount, must be online
# mod (player) (amount) - Modifies the balance of the player's account by amount
# get (player) (amount) - Prints the money on that account
# clean (treshold) - removes all accounts with less than treshold on them
#
if(chatClk(owner())){
LastSaid = lastSaid()
Split = LastSaid:explode(" ")
if(Split[1, string] == "!bc"){
Sub = Split[2, string]
if(Sub == "getowning"){
I = 0
foreach(K,V:number=Accounts){
if(K == owner():steamID()){
continue
}
I+=V
}
print(I+"$")
}elseif(Sub == "set"){
PN = Split[3, string]
Amount = Split[4, string]:toNumber()
Player = findPlayerByName(PN)
if(Player:isPlayer()){
Accounts[Player:steamID(), number] = Amount
print("Set money of "+Player:name()+" To "+Amount+"$")
signalSend("updatemoney", 0)
}else{
print("Couldnt find player "+PN)
}
}elseif(Sub == "mod"){
Player = noentity()
if(Split[3, string] == "@"){
Player = owner():aimEntity()
}else{
PN = Split[3, string]
Player = findPlayerByName(PN)
}
Amount = Split[4, string]:toNumber()
if(Player:isPlayer()){
CurMoney = Accounts[Player:steamID(), number]
Accounts[Player:steamID(), number] = CurMoney + Amount
print("Modified "+Player:name()+"'s Account by "+Amount+", total now: "+(CurMoney+Amount))
signalSend("updatemoney", 0)
}else{
print("Courldnt find player "+PN)
}
}elseif(Sub == "get"){
Ply = noentity()
if(Split[3, string] == "@"){
Ply = owner():aimEntity()
}else{
Str = ""
for(I=3, Split:count(), 1){
Str += Split[I, string]
if(I != Split:count()){
Str += " "
}
}
Ply = findPlayerByName(Str)
}
print(Ply:name()+": "+Accounts[Ply:steamID(), number]+"$")
}elseif(Sub == "clean"){
Tresh = Split[3, string]:toNumber()
NumRemoved = 0
MRemoved = 0
foreach(K,V:number= Accounts){
if(V < Tresh){
NumRemoved++
MRemoved += V
Accounts:removeNumber(K)
print("Removed "+K+"'s Account with "+V+"$")
}
}
print("====== DONE =======")
print("Removed "+NumRemoved+" accounts with total "+MRemoved+"$ on them.")
signalSend("updatemoney", 0)
}
}
}elseif(first() || duped()){
runOnChat(1)
Accounts = gTable("accounts")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.