From 76647fc2fcad1e82916d012bbc936143fe414b64 Mon Sep 17 00:00:00 2001 From: Rendo Date: Wed, 3 Dec 2025 12:40:32 +0500 Subject: [PATCH] Player input is now client-side --- scripts/multiplayer/player_input.gd | 72 +++++++++++++++++++++++++ scripts/multiplayer/player_input.gd.uid | 1 + scripts/weapon_system/weapon_system.gd | 37 ------------- 3 files changed, 73 insertions(+), 37 deletions(-) create mode 100644 scripts/multiplayer/player_input.gd create mode 100644 scripts/multiplayer/player_input.gd.uid diff --git a/scripts/multiplayer/player_input.gd b/scripts/multiplayer/player_input.gd new file mode 100644 index 0000000..d37a85e --- /dev/null +++ b/scripts/multiplayer/player_input.gd @@ -0,0 +1,72 @@ +extends MultiplayerSynchronizer + +var direction: Vector2 + +signal drop +signal switch_weapon(to_slot: StringName) +signal fire_begin +signal fire_end +signal alternate_state +signal switch_firemode + +func _input(event: InputEvent) -> void: + if not is_multiplayer_authority(): return + direction = Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward") + + if event.is_action_pressed("plr_ult"): + switch_on_server.rpc_id(1,"ultimate") + elif event.is_action_pressed("plr_bomb"): + switch_on_server.rpc_id(1,"bomb") + elif event.is_action_pressed("plr_primary"): + switch_on_server.rpc_id(1,"primary") + elif event.is_action_pressed("plr_active_first"): + switch_on_server.rpc_id(1,"ability_first") + elif event.is_action_pressed("plr_active_second"): + switch_on_server.rpc_id(1,"ability_second") + elif event.is_action_pressed("plr_active_third"): + switch_on_server.rpc_id(1,"ability_third") + elif event.is_action_pressed("plr_secondary"): + switch_on_server.rpc_id(1,"secondary") + elif event.is_action_pressed("plr_knife"): + switch_on_server.rpc_id(1,"knife") + + if event.is_action_pressed("plr_fire"): + fire_on_server.rpc_id(1,false) + if event.is_action_released("plr_fire"): + fire_on_server.rpc_id(1,true) + if event.is_action_pressed("plr_scope"): + alternate_state_on_server.rpc_id(1) + if event.is_action_pressed("plr_firemode"): + switch_firemode_on_server.rpc_id(1) + + if event.is_action_pressed("plr_drop"): + drop_on_server.rpc_id(1) + +@rpc("authority","call_local","reliable") +func switch_on_server(slot: StringName) -> void: + if not multiplayer.is_server(): return + switch_weapon.emit(slot) + +@rpc("authority","call_local","reliable") +func drop_on_server() -> void: + if not multiplayer.is_server(): return + drop.emit() + +@rpc("authority","call_local","reliable") +func fire_on_server(end: bool) -> void: + if not multiplayer.is_server(): return + if end: + fire_end.emit() + else: + fire_begin.emit() + +@rpc("authority","call_local","reliable") +func alternate_state_on_server() -> void: + if not multiplayer.is_server(): return + alternate_state.emit() + +@rpc("authority","call_local","reliable") +func switch_firemode_on_server() -> void: + if not multiplayer.is_server(): return + switch_firemode.emit() + diff --git a/scripts/multiplayer/player_input.gd.uid b/scripts/multiplayer/player_input.gd.uid new file mode 100644 index 0000000..b86efb9 --- /dev/null +++ b/scripts/multiplayer/player_input.gd.uid @@ -0,0 +1 @@ +uid://dfvnx8f1v6m5g diff --git a/scripts/weapon_system/weapon_system.gd b/scripts/weapon_system/weapon_system.gd index 7dcaeb6..6c63a6d 100644 --- a/scripts/weapon_system/weapon_system.gd +++ b/scripts/weapon_system/weapon_system.gd @@ -172,40 +172,3 @@ func _physics_process(delta: float) -> void: if current_state == null or disabled: return current_state.physics_update(delta) - -func _input(event: InputEvent) -> void: - if is_multiplayer_authority() == false or disabled: return - - if current_state != null: - current_state.state_input(event) - - if event.is_action_pressed("plr_ult"): - switch("ultimate") - elif event.is_action_pressed("plr_bomb"): - switch("bomb") - elif event.is_action_pressed("plr_primary"): - switch("primary") - elif event.is_action_pressed("plr_active_first"): - switch("ability_first") - elif event.is_action_pressed("plr_active_second"): - switch("ability_second") - elif event.is_action_pressed("plr_active_third"): - switch("ability_third") - elif event.is_action_pressed("plr_secondary"): - switch("secondary") - elif event.is_action_pressed("plr_knife"): - switch("knife") - - if not Session.round_state == Session.ROUND_STATES.BUY and not player.passived: - if event.is_action_pressed("plr_fire"): - current_state.use_begin.rpc() - if event.is_action_released("plr_fire"): - current_state.use_end.rpc() - if event.is_action_pressed("plr_scope"): - current_state.alternate_state() - if event.is_action_pressed("plr_firemode"): - current_state.switch_mode() - - if event.is_action_pressed("plr_drop"): - drop_current() -