-
Notifications
You must be signed in to change notification settings - Fork 33
/
health_indicator.py
79 lines (62 loc) · 2.3 KB
/
health_indicator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""Health Indicator mod v1.2
Made by Cross Joy
For 1.7.20+"""
# ----------------------
# v1.2 update
# Enhance compatibility with other mods.
# Fixed the health is not displaying accurately.
# ----------------------
# You can contact me through discord:
# My Discord Id: Cross Joy#0721
# My BS Discord Server: https://discord.gg/JyBY6haARJ
# Add a simple health indicator on every player and bot.
# ba_meta require api 8
from __future__ import annotations
import babase
import bascenev1lib.actor.spaz
from bascenev1lib.actor.spaz import Spaz
import bascenev1 as bs
import bascenev1lib
def new_init_spaz_(func):
def wrapper(*args, **kwargs):
func(*args, **kwargs)
m = bs.newnode('math',
owner=args[0].node,
attrs={'input1': (0, 0.7, 0),
'operation': 'add'})
args[0].node.connectattr('position', m, 'input2')
args[0]._hitpoint_text = bs.newnode(
'text',
owner=args[0].node,
attrs={'text': "\ue047" + str(args[0].hitpoints),
'in_world': True,
'shadow': 1.0,
'flatness': 1.0,
'color': (1, 1, 1),
'scale': 0.0,
'h_align': 'center'})
m.connectattr('output', args[0]._hitpoint_text, 'position')
bs.animate(args[0]._hitpoint_text, 'scale', {0: 0.0, 1.0: 0.01})
return wrapper
def new_handlemessage_spaz_(func):
def wrapper(*args, **kwargs):
def update_hitpoint_text(spaz):
spaz._hitpoint_text.text = "\ue047" + str(spaz.hitpoints)
r = spaz.hitpoints / 1000
spaz._hitpoint_text.color = (1, r, r, 1)
func(*args, **kwargs)
if isinstance(args[1], bs.PowerupMessage):
if args[1].poweruptype == 'health':
update_hitpoint_text(args[0])
if isinstance(
args[1], bs.HitMessage) or isinstance(
args[1], bs.ImpactDamageMessage):
update_hitpoint_text(args[0])
return wrapper
# ba_meta export plugin
class ByCrossJoy(babase.Plugin):
def __init__(self):
pass
def on_app_running(self) -> None:
Spaz.__init__ = new_init_spaz_(Spaz.__init__)
Spaz.handlemessage = new_handlemessage_spaz_(Spaz.handlemessage)