Compressed states
This commit is contained in:
parent
f312e0a4a6
commit
ff08e6e4f9
2 changed files with 21 additions and 13 deletions
|
|
@ -7620,6 +7620,9 @@ height = 3.7087402
|
|||
properties/0/path = NodePath("PlayerInput:direction")
|
||||
properties/0/spawn = true
|
||||
properties/0/replication_mode = 1
|
||||
properties/1/path = NodePath("PlayerInput:compressed_states")
|
||||
properties/1/spawn = true
|
||||
properties/1/replication_mode = 1
|
||||
|
||||
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("weapon_models")]
|
||||
collision_layer = 2
|
||||
|
|
|
|||
|
|
@ -2,14 +2,15 @@ extends MultiplayerSynchronizer
|
|||
|
||||
class_name PlayerInput
|
||||
|
||||
const SCOPE: int = 0b1
|
||||
const CROUCH: int = 0b10
|
||||
const WALK: int = 0b100
|
||||
|
||||
#region SYNC
|
||||
@export var direction: Vector2
|
||||
@export var compressed_states: int
|
||||
#endregion
|
||||
|
||||
var crouching: bool = false
|
||||
var scoping: bool = false
|
||||
var walking: bool = false
|
||||
|
||||
signal jumped
|
||||
signal drop
|
||||
signal switch_weapon(to_slot: StringName)
|
||||
|
|
@ -62,37 +63,41 @@ func _input(event: InputEvent) -> void:
|
|||
if event.is_action_pressed("plr_drop"):
|
||||
drop_on_server.rpc_id(1)
|
||||
|
||||
var crouching: bool = compressed_states & CROUCH
|
||||
var walking: bool = compressed_states & WALK
|
||||
var scoping: bool = compressed_states & SCOPE
|
||||
|
||||
if event.is_action_pressed("plr_crouch"):
|
||||
if ClientSettings.TOGGLE_CROUCH:
|
||||
crouch_on_server.rpc_id(1,crouching)
|
||||
crouching = not crouching
|
||||
compressed_states ^= CROUCH
|
||||
elif not crouching:
|
||||
crouching = true
|
||||
compressed_states |= CROUCH
|
||||
crouch_on_server.rpc_id(1,false)
|
||||
if event.is_action_released("plr_crouch") and not ClientSettings.TOGGLE_CROUCH and crouching:
|
||||
crouching = false
|
||||
compressed_states &= ~CROUCH
|
||||
crouch_on_server.rpc_id(1,true)
|
||||
|
||||
if event.is_action_pressed("plr_walk"):
|
||||
if ClientSettings.TOGGLE_WALK:
|
||||
walk_on_server.rpc_id(1,walking)
|
||||
walking = not walking
|
||||
compressed_states ^= WALK
|
||||
elif not walking:
|
||||
walking = true
|
||||
compressed_states |= WALK
|
||||
walk_on_server.rpc_id(1,false)
|
||||
if event.is_action_released("plr_walk") and not ClientSettings.TOGGLE_WALK and walking:
|
||||
walking = false
|
||||
compressed_states &= ~WALK
|
||||
walk_on_server.rpc_id(1,true)
|
||||
|
||||
if event.is_action_pressed("plr_scope"):
|
||||
if ClientSettings.TOGGLE_SCOPE:
|
||||
scope_on_server.rpc_id(1,scoping)
|
||||
scoping = not scoping
|
||||
compressed_states ^= SCOPE
|
||||
elif not scoping:
|
||||
scoping = true
|
||||
compressed_states |= SCOPE
|
||||
scope_on_server.rpc_id(1,false)
|
||||
if event.is_action_released("plr_scope") and not ClientSettings.TOGGLE_SCOPE and scoping:
|
||||
scoping = false
|
||||
compressed_states &= ~SCOPE
|
||||
scope_on_server.rpc_id(1,true)
|
||||
|
||||
if event.is_action_pressed("plr_reload"):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue