added role , rank tag to spaz node

This commit is contained in:
Ayush Saini 2021-04-05 22:13:52 +05:30
parent 8d95248166
commit 14007f0b0e
11 changed files with 119 additions and 20 deletions

View file

@ -81,11 +81,22 @@ def change_role_tag(role,tag):
return "role not exists" return "role not exists"
def commit(): def commit(_roles):
global roles global roles
if _roles=={}:
return
f=open("roles.json",'w') f=open("roles.json",'w')
json.dump(roles,f,indent=4) json.dump(_roles,f,indent=4)
f.close() f.close()
roles=_roles
def get_role(acc_id):
global roles
_roles =roles()
for role in _roles:
if acc_id in role["ids"]:
return role
#======================= CUSTOM EFFECTS/TAGS =============== #======================= CUSTOM EFFECTS/TAGS ===============

View file

@ -4,5 +4,6 @@
"top watermark":"Welcome to server \n ip 192.168.0.1", "top watermark":"Welcome to server \n ip 192.168.0.1",
"bottom left watermark":"join discord for fun", "bottom left watermark":"join discord for fun",
"center highlights":["message 1","message 2","message 3"] "center highlights":["message 1","message 2","message 3"]
} },
"enabletags":true
} }

View file

@ -22,12 +22,3 @@ def sendError(msg: str, ID: int = None):
else: else:
ba.screenmessage(msg, color=(1,0,0), transient=True) ba.screenmessage(msg, color=(1,0,0), transient=True)
def getStats():
try:
f = open(statsFile, 'r')
a = json.loads(f.read())
f.close()
return a
except:
print("Stats not found")
return {}

View file

@ -1,5 +0,0 @@

View file

21
dist/ba_root/mods/spazmod/modifyspaz.py vendored Normal file
View file

@ -0,0 +1,21 @@
import tag
import effects
import setting
# all activites related to modify spaz by any how will be here
def main(node,player):
_setting=setting.get_setting()
if _setting['enabletags']:
tag.addtag(node,player)
if _setting['enablerank']:
tag.addrank(node,player)
if _setting['enableeffects']:
effects.addeffect(node,player)

68
dist/ba_root/mods/spazmod/tag.py vendored Normal file
View file

@ -0,0 +1,68 @@
import pdata
def addtag(node,player):
session_player=player.sessionplayer
account_id=session_player.get_account_id()
customtag=pdata.custom()['customtag']
roles=pdata.roles()
role=pdata.get_role(account_id)
tag=None
if account_id in customtag:
tag=customtag[account_id]
elif role:
tag=roles[role]['tag']
tag(node,tag)
def addrank(node,player):
class tag(object):
def __init__(owner=None,tag="somthing"):
mnode = ba.newnode('math',
owner=self.node,
attrs={
'input1': (0, 1.4, 0),
'operation': 'add'
})
self.node.connectattr('torso_position', mnode, 'input2')
self.tag_text = ba.newnode('text',
owner=self.node,
attrs={
'text': tag,
'in_world': True,
'shadow': 1.0,
'flatness': 1.0,
'color': (1,1,1),
'scale': 0.02,
'h_align': 'center'
})
mnode.connectattr('output', self.tag_text, 'position')
class rank(object):
def __init__(owner=None,rank=1):
mnode = ba.newnode('math',
owner=self.node,
attrs={
'input1': (0, 1.4, 0),
'operation': 'add'
})
self.node.connectattr('torso_position', mnode, 'input2')
self.rank_text = ba.newnode('text',
owner=self.node,
attrs={
'text': str(rank),
'in_world': True,
'shadow': 1.0,
'flatness': 1.0,
'color': (1,1,1),
'scale': 0.02,
'h_align': 'center'
})
mnode.connectattr('output', self.rank_text, 'position')

View file

@ -4,7 +4,7 @@ damage_data = {}
mystats module for BombSquad version 1.5.29 mystats module for BombSquad version 1.5.29
Provides functionality for dumping player stats to disk between rounds. Provides functionality for dumping player stats to disk between rounds.
""" """
ranks=[]
import threading,json,os,urllib.request,ba,_ba,setting import threading,json,os,urllib.request,ba,_ba,setting
from ba._activity import Activity from ba._activity import Activity
from ba._music import setmusic, MusicType from ba._music import setmusic, MusicType
@ -56,6 +56,7 @@ def refreshStats():
toppers = {} toppers = {}
pStats = stats pStats = stats
toppersIDs=[] toppersIDs=[]
_ranks=[]
for entry in entries: for entry in entries:
if True: if True:
rank += 1 rank += 1
@ -85,6 +86,9 @@ def refreshStats():
dmg = damage_data[aid] dmg = damage_data[aid]
dmg = str(str(dmg).split('.')[0] + '.' + str(dmg).split('.')[1][:3]) dmg = str(str(dmg).split('.')[0] + '.' + str(dmg).split('.')[1][:3])
else: dmg = 0 else: dmg = 0
_ranks.append(aid)
pStats[str(aid)]["rank"] = int(rank) pStats[str(aid)]["rank"] = int(rank)
pStats[str(aid)]["scores"] = int(scores) pStats[str(aid)]["scores"] = int(scores)
pStats[str(aid)]["total_damage"] += float(dmg) #not working properly pStats[str(aid)]["total_damage"] += float(dmg) #not working properly
@ -110,7 +114,8 @@ def refreshStats():
</body> </body>
</html>''') </html>''')
f.close() f.close()
global ranks
ranks=_ranks
f2 = open(statsfile, "w") f2 = open(statsfile, "w")
f2.write(json.dumps(pStats, indent=4)) f2.write(json.dumps(pStats, indent=4))
f2.close() f2.close()
@ -202,3 +207,10 @@ class UpdateThread(threading.Thread):
update_time = now.strftime("%S:%M:%H - %d %b %y") update_time = now.strftime("%S:%M:%H - %d %b %y")
print(f"Added {str(len(self._account_kills))} account's stats entries. || {str(update_time)}") print(f"Added {str(len(self._account_kills))} account's stats entries. || {str(update_time)}")
refreshStats() refreshStats()
def getRank(acc_id):
global ranks
if ranks==[]:
refreshStats()
if acc_id in ranks:
return ranks.index(acc_id)