2023-07-28 17:03:36 +05:30
# Ported by your friend: Freaku
2022-09-01 16:06:01 +05:30
2023-07-28 17:03:36 +05:30
#Join BCS:
2022-09-01 16:06:01 +05:30
# https://discord.gg/ucyaesh
2023-07-28 17:03:36 +05:30
#My GitHub:
2022-09-01 16:06:01 +05:30
# https://github.com/Freaku17/BombSquad-Mods-byFreaku
2023-07-28 17:03:36 +05:30
# ba_meta require api 8
2022-09-01 16:06:01 +05:30
from __future__ import annotations
from typing import TYPE_CHECKING
2023-07-28 17:03:36 +05:30
import _babase , babase , random , math
import bauiv1 as bui
import bascenev1 as bs
from bascenev1lib . gameutils import SharedObjects
from bascenev1lib . actor . bomb import Bomb
from bascenev1lib . actor . popuptext import PopupText
from bauiv1lib . party import PartyWindow
2022-09-01 16:06:01 +05:30
if TYPE_CHECKING :
from typing import Optional
2023-07-28 17:03:36 +05:30
class Floater ( bs . Actor ) :
2022-09-01 16:06:01 +05:30
def __init__ ( self , bounds ) :
super ( ) . __init__ ( )
shared = SharedObjects . get ( )
self . controlled = False
self . source_player = None
2023-07-28 17:03:36 +05:30
self . floaterMaterial = bs . Material ( )
2022-09-01 16:06:01 +05:30
self . floaterMaterial . add_actions (
conditions = ( ' they_have_material ' ,
shared . player_material ) ,
actions = ( ( ' modify_node_collision ' , ' collide ' , True ) ,
( ' modify_part_collision ' , ' physical ' , True ) ) )
self . floaterMaterial . add_actions (
conditions = ( ( ' they_have_material ' ,
shared . object_material ) , ' or ' ,
( ' they_have_material ' ,
shared . footing_material ) , ' or ' ,
( ' they_have_material ' ,
self . floaterMaterial ) ) ,
actions = ( ' modify_part_collision ' , ' physical ' , False ) )
self . pos = bounds
self . px = " random.uniform(self.pos[0],self.pos[3]) "
self . py = " random.uniform(self.pos[1],self.pos[4]) "
self . pz = " random.uniform(self.pos[2],self.pos[5]) "
2023-07-28 17:03:36 +05:30
self . node = bs . newnode (
2022-09-01 16:06:01 +05:30
' prop ' ,
delegate = self ,
owner = None ,
attrs = {
' position ' : ( eval ( self . px ) , eval ( self . py ) , eval ( self . pz ) ) ,
2023-07-28 17:03:36 +05:30
' mesh ' :
bs . getmesh ( ' landMine ' ) ,
' light_mesh ' :
bs . getmesh ( ' landMine ' ) ,
2022-09-01 16:06:01 +05:30
' body ' :
' landMine ' ,
' body_scale ' :
3 ,
2023-07-28 17:03:36 +05:30
' mesh_scale ' :
2022-09-01 16:06:01 +05:30
3.1 ,
' shadow_size ' :
0.25 ,
' density ' :
999999 ,
' gravity_scale ' :
0.0 ,
' color_texture ' :
2023-07-28 17:03:36 +05:30
bs . gettexture ( ' achievementFlawlessVictory ' ) ,
2022-09-01 16:06:01 +05:30
' reflection ' :
' soft ' ,
' reflection_scale ' : [ 0.25 ] ,
' materials ' :
[ shared . footing_material , self . floaterMaterial ]
} )
2023-07-28 17:03:36 +05:30
self . node2 = bs . newnode (
2022-09-01 16:06:01 +05:30
' prop ' ,
owner = self . node ,
attrs = {
' position ' : ( 0 , 0 , 0 ) ,
' body ' :
' sphere ' ,
2023-07-28 17:03:36 +05:30
' mesh ' :
2022-09-01 16:06:01 +05:30
None ,
' color_texture ' :
None ,
' body_scale ' :
1.0 ,
' reflection ' :
' powerup ' ,
' density ' :
999999 ,
' reflection_scale ' : [ 1.0 ] ,
2023-07-28 17:03:36 +05:30
' mesh_scale ' :
2022-09-01 16:06:01 +05:30
1.0 ,
' gravity_scale ' :
0 ,
' shadow_size ' :
0.1 ,
' is_area_of_interest ' :
True ,
' materials ' :
[ shared . object_material , self . floaterMaterial ]
} )
self . node . connectattr ( ' position ' , self . node2 , ' position ' )
2023-07-28 17:03:36 +05:30
def pop ( self ) : PopupText ( text = " Ported by \ue048 Freaku " , scale = 1.3 , position = ( self . node . position [ 0 ] , self . node . position [ 1 ] - 1 , self . node . position [ 2 ] ) , color = ( 0 , 1 , 1 ) ) . autoretain ( )
2022-09-01 16:06:01 +05:30
def checkCanControl ( self ) :
if not self . node . exists ( ) :
return False
if not self . source_player . is_alive ( ) :
self . dis ( )
return False
return True
def con ( self ) :
self . controlled = True
self . checkPlayerDie ( )
def up ( self ) :
if not self . checkCanControl ( ) :
return
v = self . node . velocity
self . node . velocity = ( v [ 0 ] , 5 , v [ 2 ] )
def upR ( self ) :
if not self . checkCanControl ( ) :
return
v = self . node . velocity
self . node . velocity = ( v [ 0 ] , 0 , v [ 2 ] )
def down ( self ) :
if not self . checkCanControl ( ) :
return
v = self . node . velocity
self . node . velocity = ( v [ 0 ] , - 5 , v [ 2 ] )
def downR ( self ) :
if not self . checkCanControl ( ) :
return
v = self . node . velocity
self . node . velocity = ( v [ 0 ] , 0 , v [ 2 ] )
def leftright ( self , value ) :
if not self . checkCanControl ( ) :
return
v = self . node . velocity
self . node . velocity = ( 5 * value , v [ 1 ] , v [ 2 ] )
def updown ( self , value ) :
if not self . checkCanControl ( ) :
return
v = self . node . velocity
self . node . velocity = ( v [ 0 ] , v [ 1 ] , - 5 * value )
def dis ( self ) :
if self . node . exists ( ) :
self . controlled = False
self . node . velocity = ( 0 , 0 , 0 )
self . move ( )
def checkPlayerDie ( self ) :
if not self . controlled :
return
if self . source_player is None :
return
if self . source_player . is_alive ( ) :
2023-07-28 17:03:36 +05:30
bs . timer ( 1 , self . checkPlayerDie )
2022-09-01 16:06:01 +05:30
return
else :
self . dis ( )
def distance ( self , x1 , y1 , z1 , x2 , y2 , z2 ) :
d = math . sqrt ( math . pow ( x2 - x1 , 2 ) + math . pow ( y2 - y1 , 2 ) + math . pow ( z2 - z1 , 2 ) )
return d
def drop ( self ) :
try :
np = self . node . position
except :
np = ( 0 , 0 , 0 )
2023-07-28 17:03:36 +05:30
self . b = Bomb ( bomb_type = random . choice ( [ ' normal ' , ' ice ' , ' sticky ' , ' impact ' , ' land_mine ' , ' tnt ' ] ) , source_player = self . source_player , position = ( np [ 0 ] , np [ 1 ] - 1 , np [ 2 ] ) , velocity = ( 0 , - 1 , 0 ) ) . autoretain ( )
2022-09-01 16:06:01 +05:30
if self . b . bomb_type in [ ' impact ' , ' land_mine ' ] :
self . b . arm ( )
def move ( self ) :
px = eval ( self . px )
py = eval ( self . py )
pz = eval ( self . pz )
if self . node . exists ( ) and not self . controlled :
pn = self . node . position
dist = self . distance ( pn [ 0 ] , pn [ 1 ] , pn [ 2 ] , px , py , pz )
self . node . velocity = ( ( px - pn [ 0 ] ) / dist , ( py - pn [ 1 ] ) / dist , ( pz - pn [ 2 ] ) / dist )
2023-07-28 17:03:36 +05:30
bs . timer ( dist - 1 , bs . WeakCall ( self . move ) ) #suppress_format_warning=True)
2022-09-01 16:06:01 +05:30
def handlemessage ( self , msg ) :
2023-07-28 17:03:36 +05:30
if isinstance ( msg , bs . DieMessage ) :
2022-09-01 16:06:01 +05:30
self . node . delete ( )
self . node2 . delete ( )
self . controlled = False
2023-07-28 17:03:36 +05:30
elif isinstance ( msg , bs . OutOfBoundsMessage ) :
self . handlemessage ( bs . DieMessage ( ) )
2022-09-01 16:06:01 +05:30
else :
super ( ) . handlemessage ( msg )
2023-07-28 17:03:36 +05:30
2022-09-01 16:06:01 +05:30
def assignFloInputs ( clientID : int ) :
2023-07-28 17:03:36 +05:30
activity = bs . get_foreground_host_activity ( )
with activity . context :
2022-09-01 16:06:01 +05:30
if not hasattr ( activity , ' flo ' ) or not activity . flo . node . exists ( ) :
2023-07-28 17:03:36 +05:30
try : activity . flo = Floater ( activity . map . get_def_bound_box ( ' map_bounds ' ) )
except : return #Perhaps using in main-menu/score-screen
2022-09-01 16:06:01 +05:30
floater = activity . flo
if floater . controlled :
2023-07-28 17:03:36 +05:30
bs . broadcastmessage ( ' Floater is already being controlled ' , color = ( 1 , 0 , 0 ) , transient = True , clients = [ clientID ] )
2022-09-01 16:06:01 +05:30
return
2023-07-28 17:03:36 +05:30
bs . broadcastmessage ( ' You Gained Control Over The Floater! \n Press Bomb to Throw Bombs and Punch to leave! ' , clients = [ clientID ] , transient = True , color = ( 0 , 1 , 1 ) )
2022-09-01 16:06:01 +05:30
2023-07-28 17:03:36 +05:30
for i in activity . players :
2022-09-01 16:06:01 +05:30
if i . sessionplayer . inputdevice . client_id == clientID :
def dis ( i , floater ) :
i . actor . node . invincible = False
i . resetinput ( )
i . actor . connect_controls_to_player ( )
floater . dis ( )
ps = i . actor . node . position
i . actor . node . invincible = True
floater . node . position = ( ps [ 0 ] , ps [ 1 ] + 1.0 , ps [ 2 ] )
2023-07-28 17:03:36 +05:30
bs . timer ( 1 , floater . pop )
i . actor . node . hold_node = bs . Node ( None )
2022-09-01 16:06:01 +05:30
i . actor . node . hold_node = floater . node2
i . actor . connect_controls_to_player ( )
i . actor . disconnect_controls_from_player ( )
i . resetinput ( )
floater . source_player = i
floater . con ( )
2023-07-28 17:03:36 +05:30
i . assigninput ( babase . InputType . PICK_UP_PRESS , floater . up )
i . assigninput ( babase . InputType . PICK_UP_RELEASE , floater . upR )
i . assigninput ( babase . InputType . JUMP_PRESS , floater . down )
i . assigninput ( babase . InputType . BOMB_PRESS , floater . drop )
i . assigninput ( babase . InputType . PUNCH_PRESS , babase . Call ( dis , i , floater ) )
i . assigninput ( babase . InputType . UP_DOWN , floater . updown )
i . assigninput ( babase . InputType . LEFT_RIGHT , floater . leftright )
2022-09-01 16:06:01 +05:30
2023-07-28 17:03:36 +05:30
# Display chat icon, but if user open/close gather it may disappear
bui . set_party_icon_always_visible ( True )
2022-09-01 16:06:01 +05:30
2023-07-28 17:03:36 +05:30
old_piv = bui . set_party_icon_always_visible
def new_piv ( * args , * * kwargs ) :
# Do not let chat icon go away
old_piv ( True )
bui . set_party_icon_always_visible = new_piv
2022-09-01 12:56:24 +00:00
2023-07-28 17:03:36 +05:30
old_fcm = bs . chatmessage
def new_chat_message ( * args , * * kwargs ) :
old_fcm ( * args , * * kwargs )
if args [ 0 ] == ' /floater ' :
try : assignFloInputs ( - 1 )
except : pass
bs . chatmessage = new_chat_message
2022-09-01 16:06:01 +05:30
# ba_meta export plugin
2023-07-28 17:03:36 +05:30
class byFreaku ( babase . Plugin ) :
def __init__ ( self ) : pass