bombsquad-plugin-manager/plugins/utilities/xyz_tool.py

99 lines
3.7 KiB
Python
Raw Normal View History

2024-02-01 11:57:50 +03:00
# Released under the MIT License. See LICENSE for details.
2025-01-22 00:14:27 +05:30
# ba_meta require api 9
2024-02-01 11:57:50 +03:00
from __future__ import annotations
from typing import TYPE_CHECKING
from bascenev1lib.actor.playerspaz import PlayerSpaz
from bascenev1lib.actor.spazfactory import SpazFactory
import babase
import bauiv1 as bui
import bascenev1 as bs
import os
import _babase
if TYPE_CHECKING:
2025-01-22 00:14:27 +05:30
from typing import Sequence
2024-02-01 11:57:50 +03:00
DECIMAL_LIMIT = 7
PlayerSpaz.supershit = PlayerSpaz.__init__
2024-02-01 08:58:54 +00:00
2024-02-01 11:57:50 +03:00
def ShitInit(self,
2024-02-01 08:58:54 +00:00
player: bs.Player,
2025-01-22 00:14:27 +05:30
*,
2024-02-01 08:58:54 +00:00
color: Sequence[float] = (1.0, 1.0, 1.0),
highlight: Sequence[float] = (0.5, 0.5, 0.5),
character: str = 'Spaz',
powerups_expire: bool = True) -> None:
2025-01-22 00:14:27 +05:30
self.supershit(player,
color=color,
highlight=highlight,
character=character,
powerups_expire=powerups_expire)
2024-02-01 08:58:54 +00:00
self.offt = bs.newnode('math', owner=self.node, attrs={
'input1': (1.2, 1.8, -0.7), 'operation': 'add'})
2024-02-01 11:57:50 +03:00
self.node.connectattr('torso_position', self.offt, 'input2')
2024-02-01 08:58:54 +00:00
self.txt = bs.newnode('text', owner=self.node, attrs={'text': '3.0', 'in_world': True, 'text': '0', 'shadow': 1.0, 'color': (
1, 0, 0), 'flatness': 0.5, 'scale': 0.01, 'h_align': 'right'})
2024-02-01 11:57:50 +03:00
p = self.node.position
self.xyz = 0
self.txt.text = "X: " + str(p[0]) + "\nY: " + str(p[1]) + "\nZ: " + str(p[2])
self.offt.connectattr('output', self.txt, 'position')
2024-02-01 08:58:54 +00:00
2024-02-01 11:57:50 +03:00
def update():
p = self.node.position
is_moving = abs(self.node.move_up_down) >= 0.01 or abs(self.node.move_left_right) >= 0.01
if is_moving:
2024-02-01 08:58:54 +00:00
self.xyz = (p[0], p[1], p[2])
self.txt.text = "X: " + str(round(self.xyz[0], DECIMAL_LIMIT)) + "\nY: " + str(
round(self.xyz[1], DECIMAL_LIMIT)) + "\nZ: " + str(round(self.xyz[2], DECIMAL_LIMIT))
bs.timer(0.1, update, repeat=True)
2024-02-01 11:57:50 +03:00
def replaceable_punch(self) -> None:
"""
Called to 'press punch' on this spaz;
used for player or AI connections.
"""
if not self.node or self.frozen or self.node.knockout > 0.0:
return
index = 0
path_aid = _babase.env()['python_directory_user'] + '/Saved XYZ'
path, dirs, files = next(os.walk(path_aid))
index += len(files)
c27 = str(index + 1)
with open(path_aid + '/coords' + c27 + '.txt', 'w') as gg:
2024-02-01 08:58:54 +00:00
gg.write("X: " + str(round(self.xyz[0], DECIMAL_LIMIT)) + "\nY: " + str(round(self.xyz[1], DECIMAL_LIMIT)) + "\nZ: " + str(round(self.xyz[2], DECIMAL_LIMIT)) +
'\n\n' + '(' + str(round(self.xyz[0], DECIMAL_LIMIT)) + ', ' + str(round(self.xyz[1], DECIMAL_LIMIT)) + ', ' + str(round(self.xyz[2], DECIMAL_LIMIT)) + ')')
2024-02-01 11:57:50 +03:00
bui.screenmessage("Coordinates saved in: " + "BombSquad/Saved XYZ/" + "coords" + c27)
if _babase.app.classic.platform == 'android':
2024-02-01 08:58:54 +00:00
_babase.android_media_scan_file(path_aid)
2024-02-01 11:57:50 +03:00
t_ms = bs.time() * 1000
assert isinstance(t_ms, int)
if t_ms - self.last_punch_time_ms >= self._punch_cooldown:
if self.punch_callback is not None:
self.punch_callback(self)
self._punched_nodes = set() # Reset this.
self.last_punch_time_ms = t_ms
self.node.punch_pressed = True
if not self.node.hold_node:
bs.timer(
2024-02-01 08:58:54 +00:00
0.1,
bs.WeakCall(self._safe_play_sound,
SpazFactory.get().swish_sound, 0.8))
2024-02-01 11:57:50 +03:00
self._turbo_filter_add_press('punch')
# ba_meta export plugin
2024-02-01 08:58:54 +00:00
2024-02-01 11:57:50 +03:00
class ragingspeedhorn(babase.Plugin):
try:
2024-02-01 08:58:54 +00:00
oath = _babase.env()['python_directory_user'] + '/Saved XYZ'
os.makedirs(oath, exist_ok=False)
except:
pass
2024-02-01 11:57:50 +03:00
PlayerSpaz.on_punch_press = replaceable_punch
PlayerSpaz.__init__ = ShitInit
2025-01-21 18:44:52 +00:00
PlayerSpaz.xyz = 0