Player input is now client-side
This commit is contained in:
parent
fb4e1e5737
commit
76647fc2fc
3 changed files with 73 additions and 37 deletions
72
scripts/multiplayer/player_input.gd
Normal file
72
scripts/multiplayer/player_input.gd
Normal file
|
|
@ -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()
|
||||
|
||||
1
scripts/multiplayer/player_input.gd.uid
Normal file
1
scripts/multiplayer/player_input.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dfvnx8f1v6m5g
|
||||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue