73 lines
1.4 KiB
GDScript
73 lines
1.4 KiB
GDScript
extends CharacterBody3D
|
|
|
|
class_name Player
|
|
|
|
@export var team: Session.TEAMS
|
|
@export var weapon_models: Dictionary[StringName,Node3D]
|
|
|
|
var passived: bool = false
|
|
|
|
signal spawned
|
|
signal health_changed(to: int)
|
|
signal died
|
|
|
|
const MAX_HP = 100
|
|
|
|
@export var hp: int = 100:
|
|
set(value):
|
|
if value < 0:
|
|
hp = 0
|
|
else:
|
|
hp = value
|
|
health_changed.emit(hp)
|
|
if hp == 0:
|
|
die()
|
|
|
|
get:
|
|
return hp
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
if not multiplayer.is_server():
|
|
return
|
|
|
|
move_and_slide()
|
|
|
|
func die() -> void:
|
|
if (not multiplayer.is_server()):
|
|
return
|
|
Session.add_dead(team)
|
|
died.emit()
|
|
passived = true
|
|
|
|
@rpc("any_peer","call_local","reliable")
|
|
func passive() -> void:
|
|
passived = true
|
|
|
|
@rpc("any_peer","call_local","reliable")
|
|
func depassive() -> void:
|
|
passived = false
|
|
|
|
@rpc("any_peer","call_local","reliable")
|
|
func kill_request() -> void:
|
|
if multiplayer.get_remote_sender_id() != 1:
|
|
return
|
|
|
|
die()
|
|
|
|
@rpc("any_peer","call_local","reliable")
|
|
func set_after_spawn(start_position: Vector3,new_team: int):
|
|
global_position = start_position
|
|
team = new_team as Session.TEAMS
|
|
spawned.emit()
|
|
|
|
@rpc("any_peer","call_local","reliable")
|
|
func take_damage(damage: int):
|
|
hp -= damage
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if not is_multiplayer_authority():
|
|
return
|
|
if event.is_action_pressed("plr_interact"):
|
|
Session.interact()
|
|
if event.is_action_released("plr_interact"):
|
|
Session.stop_interact()
|