Bombsquad-Ballistica-Modded.../dist/ba_root/mods/features/EndVote.py

103 lines
3.6 KiB
Python
Raw Normal View History

2022-05-11 00:29:10 +05:30
# EndVote by -mr.smoothy
2022-05-08 15:22:27 +05:30
import _ba, ba
2022-09-25 16:35:32 +05:30
import ba.internal
2022-05-08 15:22:27 +05:30
import time
2022-05-08 22:06:53 +05:30
2022-05-08 15:22:27 +05:30
last_end_vote_start_time = 0
end_vote_duration = 50
2022-05-08 15:22:27 +05:30
game_started_on = 0
2022-05-11 00:29:10 +05:30
min_game_duration_to_start_end_vote = 30
2022-05-08 15:22:27 +05:30
voters = []
def vote_end(pb_id, client_id):
global voters
global last_end_vote_start_time
now = time.time()
if now > last_end_vote_start_time + end_vote_duration:
voters = []
last_end_vote_start_time = now
if now < game_started_on + min_game_duration_to_start_end_vote:
_ba.screenmessage("Seems game just started, Try again after some time", transient=True,
clients=[client_id])
2022-05-08 22:06:53 +05:30
return
2022-05-08 15:22:27 +05:30
if len(voters) == 0:
2022-09-25 20:09:46 +05:30
ba.internal.chatmessage("end vote started")
2022-05-08 15:22:27 +05:30
# clean up voters list
active_players = []
2022-09-25 16:35:32 +05:30
for player in ba.internal.get_game_roster():
2022-05-08 15:22:27 +05:30
active_players.append(player['account_id'])
for voter in voters:
if voter not in active_players:
voters.remove(voter)
if pb_id not in voters:
voters.append(pb_id)
_ba.screenmessage("Thanks for vote , encourage other players to type 'end' too.", transient=True,
clients=[client_id])
2022-05-11 00:29:10 +05:30
update_vote_text(required_votes(len(active_players)) - len(voters))
2022-05-11 22:20:06 +05:30
if required_votes(len(active_players)) - len(
voters) == 3: # lets dont spam chat/screen message with votes required , only give message when only 3 votes left
2022-09-25 20:09:46 +05:30
ba.internal.chatmessage("3 more end votes required")
2022-05-11 22:20:06 +05:30
2022-05-08 15:22:27 +05:30
if len(voters) >= required_votes(len(active_players)):
2022-09-25 20:09:46 +05:30
ba.internal.chatmessage("end vote succeed")
2022-05-08 15:22:27 +05:30
try:
with _ba.Context(_ba.get_foreground_host_activity()):
_ba.get_foreground_host_activity().end_game()
except:
pass
def required_votes(players):
if players == 2:
2022-05-11 00:29:10 +05:30
return 1
2022-05-08 15:22:27 +05:30
elif players == 3:
2022-05-11 00:29:10 +05:30
return 2
2022-05-08 15:22:27 +05:30
elif players == 4:
return 2
elif players == 5:
return 3
elif players == 6:
return 3
elif players == 7:
return 4
elif players == 8:
return 4
elif players == 10:
return 5
2022-05-08 15:22:27 +05:30
else:
2022-05-11 22:20:06 +05:30
return players - 4
2022-05-11 00:29:10 +05:30
def update_vote_text(votes_needed):
2022-05-11 22:20:06 +05:30
activity = _ba.get_foreground_host_activity()
try:
2022-05-11 00:29:10 +05:30
activity.end_vote_text.node.text = "{} more votes to end this map\ntype 'end' to vote".format(votes_needed)
2022-05-11 22:20:06 +05:30
except:
2022-05-11 00:29:10 +05:30
with _ba.Context(_ba.get_foreground_host_activity()):
2022-05-11 22:20:06 +05:30
node = ba.NodeActor(ba.newnode('text',
attrs={
'v_attach': 'top',
'h_attach': 'center',
'h_align': 'center',
'color': (1, 1, 0.5, 1),
'flatness': 0.5,
'shadow': 0.5,
'position': (-200, -30),
'scale': 0.7,
'text': '{} more votes to end this map \n type \'end\' to vote'.format(
votes_needed)
})).autoretain()
activity.end_vote_text = node
ba.timer(20, remove_vote_text)
2022-05-11 00:29:10 +05:30
def remove_vote_text():
activity = _ba.get_foreground_host_activity()
2022-05-11 22:20:06 +05:30
if hasattr(activity, "end_vote_text") and activity.end_vote_text.node.exists():
2022-05-11 00:29:10 +05:30
activity.end_vote_text.node.delete()
2022-05-11 22:20:06 +05:30