Syntax: Select all
import os.path
import pickle
from path import Path
from players.entity import PlayerEntity
from players.helpers import index_from_userid
from events import Event
from listeners.tick import TickRepeat
players_credit = {}
credit_repeat = {}
def load():
global players_credit
base_path = Path(__file__).parent
str_path = base_path + '/player_credit.db'
with open(str_path, 'rb') as player_credit:
players_credit = pickle.load(player_credit)
def unload():
save_database()
for userid in credit_repeat:
credit_repeat[userid].stop()
@Event
def player_connect(game_event):
userid = game_event.get_int('userid')
steamid = game_event.get_string('networkid')
if not steamid in players_credit:
players_credit[steamid] = {}
players_credit[steamid]['credit'] = 0
credit_repeat[userid] = TickRepeat(giveCredits, steamid)
credit_repeat[userid].start(60, 0)
@Event
def player_disconnect(game_event):
userid = game_event.get_int('userid')
credit_repeat[userid].stop()
save_database()
def save_database():
base_path = Path(__file__).parent
str_path = base_path + '/player_credit.db'
with open(str_path, 'wb') as player_credit:
pickle.dump(players_credit, player_credit)
def giveCredits(steamid):
players_credit[steamid]['credit'] += 1