Crouch, walking and scoping support, deleted unnecessary Session rpcs

This commit is contained in:
Rendo 2025-12-03 13:08:32 +05:00
commit d79db8a8d8
6 changed files with 4513 additions and 4456 deletions

View file

@ -1,6 +1,12 @@
extends MultiplayerSynchronizer
#region SYNC
var direction: Vector2
#endregion
var crouching: bool = false
var scoping: bool = false
var walking: bool = false
signal drop
signal switch_weapon(to_slot: StringName)
@ -8,6 +14,16 @@ signal fire_begin
signal fire_end
signal alternate_state
signal switch_firemode
signal reload
signal scope_begin
signal scope_end
signal crouch_begin
signal crouch_end
signal walk_begin
signal walk_end
func _ready() -> void:
set_multiplayer_authority(int(get_parent().name))
func _input(event: InputEvent) -> void:
if not is_multiplayer_authority(): return
@ -41,6 +57,40 @@ func _input(event: InputEvent) -> void:
if event.is_action_pressed("plr_drop"):
drop_on_server.rpc_id(1)
if event.is_action_pressed("plr_crouch"):
if ClientSettings.TOGGLE_CROUCH:
crouch_on_server(crouching)
crouching = not crouching
elif not crouching:
crouching = true
crouch_on_server(false)
if event.is_action_released("plr_crouch") and not ClientSettings.TOGGLE_CROUCH and crouching:
crouching = false
crouch_on_server(false)
if event.is_action_pressed("plr_walk"):
if ClientSettings.TOGGLE_WALK:
walk_on_server(walking)
walking = not walking
elif not walking:
walking = true
walk_on_server(false)
if event.is_action_released("plr_walk") and not ClientSettings.TOGGLE_WALK and walking:
walking = false
walk_on_server(false)
if event.is_action_pressed("plr_scope"):
if ClientSettings.TOGGLE_SCOPE:
scope_on_server(scoping)
scoping = not scoping
elif not scoping:
scoping = true
scope_on_server(false)
if event.is_action_released("plr_scope") and not ClientSettings.TOGGLE_SCOPE and scoping:
scoping = false
scope_on_server(false)
@rpc("authority","call_local","reliable")
func switch_on_server(slot: StringName) -> void:
@ -69,4 +119,32 @@ func alternate_state_on_server() -> void:
func switch_firemode_on_server() -> void:
if not multiplayer.is_server(): return
switch_firemode.emit()
@rpc("authority","call_local","reliable")
func crouch_on_server(end: bool) -> void:
if not multiplayer.is_server(): return
if end:
crouch_end.emit()
else:
crouch_begin.emit()
@rpc("authority","call_local","reliable")
func walk_on_server(end: bool) -> void:
if not multiplayer.is_server(): return
if end:
walk_end.emit()
else:
walk_begin.emit()
@rpc("authority","call_local","reliable")
func scope_on_server(end: bool) -> void:
if not multiplayer.is_server(): return
if end:
scope_end.emit()
else:
scope_begin.emit()
@rpc("authority","call_local","reliable")
func reload_on_server() -> void:
if not multiplayer.is_server(): return
reload.emit()