mirror of
https://github.com/imayushsaini/Bombsquad-Ballistica-Modded-Server.git
synced 2025-10-20 00:00:39 +00:00
added good base for currency system
This commit is contained in:
parent
38cd45f379
commit
b582230e7e
15 changed files with 161 additions and 0 deletions
BIN
dist/ba_root/mods/Currency/Commands/Command_Objects/__pycache__/data_functions.cpython-38.opt-1.pyc
vendored
Normal file
BIN
dist/ba_root/mods/Currency/Commands/Command_Objects/__pycache__/data_functions.cpython-38.opt-1.pyc
vendored
Normal file
Binary file not shown.
BIN
dist/ba_root/mods/Currency/Commands/Command_Objects/__pycache__/fun.cpython-38.opt-1.pyc
vendored
Normal file
BIN
dist/ba_root/mods/Currency/Commands/Command_Objects/__pycache__/fun.cpython-38.opt-1.pyc
vendored
Normal file
Binary file not shown.
42
dist/ba_root/mods/Currency/Commands/Command_Objects/data_functions.py
vendored
Normal file
42
dist/ba_root/mods/Currency/Commands/Command_Objects/data_functions.py
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
""" store functions executed when chat command are called """
|
||||||
|
import ba, _ba, json, random
|
||||||
|
from _ba import chatmessage as send
|
||||||
|
from _ba import screenmessage as screenmsg
|
||||||
|
from Currency.Handlers.bank_handler import *
|
||||||
|
from Currency.Handlers.ba_get_player_data import *
|
||||||
|
from Currency.Handlers.cooldown_manager import *
|
||||||
|
from .fun import get_random_donator, get_random_cash
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def balance_call(userid, clientid):
|
||||||
|
open_account(userid)
|
||||||
|
|
||||||
|
users = get_bank_data()
|
||||||
|
name = client_to_name(clientid)
|
||||||
|
|
||||||
|
cash_amt = users[str(userid)]["cash"]
|
||||||
|
bank_cash_amt = users[str(userid)]["bank_cash"]
|
||||||
|
bank_space = users[str(userid)]["bank_space"]
|
||||||
|
|
||||||
|
balance = '|| {} | Cash - {} | Bank- {}/{} ||'.format(str(name), str(cash_amt), str(bank_cash_amt), str(bank_space))
|
||||||
|
send(balance)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def beg_call(userid):
|
||||||
|
open_account(userid)
|
||||||
|
earned = get_random_cash()
|
||||||
|
|
||||||
|
users = get_bank_data()
|
||||||
|
user = users[str(userid)]
|
||||||
|
|
||||||
|
user["cash"] += earned
|
||||||
|
cash_amt = user["cash"]
|
||||||
|
donator = get_random_donator()
|
||||||
|
send(f'{donator} gave you {earned} now you have {cash_amt} coins')
|
||||||
|
|
||||||
|
commit(users)
|
||||||
|
|
||||||
|
|
||||||
17
dist/ba_root/mods/Currency/Commands/Command_Objects/fun.py
vendored
Normal file
17
dist/ba_root/mods/Currency/Commands/Command_Objects/fun.py
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
import random
|
||||||
|
|
||||||
|
donators_list = [
|
||||||
|
'Eggs broke and',
|
||||||
|
'pranav',
|
||||||
|
'your mom',
|
||||||
|
'saitama',
|
||||||
|
'one simp',
|
||||||
|
'idiot',
|
||||||
|
'mr smoothy'
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_random_donator():
|
||||||
|
return random.choice(donators_list)
|
||||||
|
|
||||||
|
def get_random_cash():
|
||||||
|
return random.randrange(80)
|
||||||
BIN
dist/ba_root/mods/Currency/Commands/__pycache__/chat_commands.cpython-38.opt-1.pyc
vendored
Normal file
BIN
dist/ba_root/mods/Currency/Commands/__pycache__/chat_commands.cpython-38.opt-1.pyc
vendored
Normal file
Binary file not shown.
13
dist/ba_root/mods/Currency/Commands/chat_commands.py
vendored
Normal file
13
dist/ba_root/mods/Currency/Commands/chat_commands.py
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
""" check given command and executive the the cmd function from data functions"""
|
||||||
|
|
||||||
|
import ba, _ba
|
||||||
|
from .Command_Objects.data_functions import *
|
||||||
|
|
||||||
|
|
||||||
|
def on_command(cmd, args, accountid, clientid):
|
||||||
|
|
||||||
|
if cmd in ['coins', 'bal', 'balance', 'me']:
|
||||||
|
balance_call(accountid, clientid)
|
||||||
|
|
||||||
|
elif cmd == 'beg':
|
||||||
|
beg_call(accountid)
|
||||||
12
dist/ba_root/mods/Currency/Data/bank.json
vendored
Normal file
12
dist/ba_root/mods/Currency/Data/bank.json
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"None": {
|
||||||
|
"cash": 1421,
|
||||||
|
"bank_space": 100,
|
||||||
|
"bank_cash": 0
|
||||||
|
},
|
||||||
|
"pb-IF4VAk4a": {
|
||||||
|
"cash": 297,
|
||||||
|
"bank_space": 100,
|
||||||
|
"bank_cash": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
dist/ba_root/mods/Currency/Handlers/__pycache__/ba_get_player_data.cpython-38.opt-1.pyc
vendored
Normal file
BIN
dist/ba_root/mods/Currency/Handlers/__pycache__/ba_get_player_data.cpython-38.opt-1.pyc
vendored
Normal file
Binary file not shown.
BIN
dist/ba_root/mods/Currency/Handlers/__pycache__/bank_handler.cpython-38.opt-1.pyc
vendored
Normal file
BIN
dist/ba_root/mods/Currency/Handlers/__pycache__/bank_handler.cpython-38.opt-1.pyc
vendored
Normal file
Binary file not shown.
BIN
dist/ba_root/mods/Currency/Handlers/__pycache__/cooldown_manager.cpython-38.opt-1.pyc
vendored
Normal file
BIN
dist/ba_root/mods/Currency/Handlers/__pycache__/cooldown_manager.cpython-38.opt-1.pyc
vendored
Normal file
Binary file not shown.
24
dist/ba_root/mods/Currency/Handlers/ba_get_player_data.py
vendored
Normal file
24
dist/ba_root/mods/Currency/Handlers/ba_get_player_data.py
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
""" retruns information of given user using client_id """
|
||||||
|
import ba, _ba
|
||||||
|
|
||||||
|
def client_to_account(client_id):
|
||||||
|
rost = _ba.get_game_roster()
|
||||||
|
for i in rost:
|
||||||
|
if i['client_id'] == client_id:
|
||||||
|
return i['account_id']
|
||||||
|
return None
|
||||||
|
|
||||||
|
def client_to_name(client_id):
|
||||||
|
rost = _ba.get_game_roster()
|
||||||
|
for i in rost:
|
||||||
|
if i['client_id'] == client_id:
|
||||||
|
return i['players'][0]['name_full']
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def client_to_display_string(client_id):
|
||||||
|
rost = _ba.get_game_roster()
|
||||||
|
for i in rost:
|
||||||
|
if i['client_id'] == client_id:
|
||||||
|
return i['display_string']
|
||||||
|
return None
|
||||||
38
dist/ba_root/mods/Currency/Handlers/bank_handler.py
vendored
Normal file
38
dist/ba_root/mods/Currency/Handlers/bank_handler.py
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
""" helperfunctions for save lot of lines of code """
|
||||||
|
|
||||||
|
import ba, _ba, json
|
||||||
|
|
||||||
|
|
||||||
|
bank_path = _ba.env()['python_directory_user']+'/Currency/Data/bank.json'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def open_account(accountid):
|
||||||
|
users = get_bank_data()
|
||||||
|
|
||||||
|
if str(accountid) in users:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
users[str(accountid)] = {}
|
||||||
|
users[str(accountid)]["cash"] = 0
|
||||||
|
users[str(accountid)]["bank_space"] = 100
|
||||||
|
users[str(accountid)]["bank_cash"] = 0
|
||||||
|
commit(users)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_bank_data():
|
||||||
|
with open(bank_path, 'r') as f:
|
||||||
|
users = json.load(f)
|
||||||
|
return users
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def commit(data):
|
||||||
|
with open(bank_path, "w") as f:
|
||||||
|
json.dump(data, f, indent=2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1
dist/ba_root/mods/Currency/Handlers/cooldown_manager.py
vendored
Normal file
1
dist/ba_root/mods/Currency/Handlers/cooldown_manager.py
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
""" cooldown manager """"
|
||||||
14
dist/ba_root/mods/Currency/__init__.py
vendored
Normal file
14
dist/ba_root/mods/Currency/__init__.py
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
from .Commands import chat_commands
|
||||||
|
from .Handlers.ba_get_player_data import client_to_account
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def main(msg, client_id):
|
||||||
|
command = msg.split(" ")[0]
|
||||||
|
|
||||||
|
if command.startswith("."):
|
||||||
|
command = command.split(".")[1]
|
||||||
|
arguments = msg.split(" ")[1:]
|
||||||
|
accountid = client_to_account(client_id)
|
||||||
|
|
||||||
|
chat_commands.on_command(command, arguments, accountid, client_id)
|
||||||
BIN
dist/ba_root/mods/Currency/__pycache__/__init__.cpython-38.opt-1.pyc
vendored
Normal file
BIN
dist/ba_root/mods/Currency/__pycache__/__init__.cpython-38.opt-1.pyc
vendored
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue