51 lines
933 B
GDScript
51 lines
933 B
GDScript
extends CharacterBody3D
|
|
|
|
class_name Player
|
|
|
|
@export var team: Session.TEAMS
|
|
@export var weapon_models: Dictionary[StringName,Node3D]
|
|
|
|
signal spawned
|
|
|
|
const MAX_HP = 100
|
|
|
|
@export var hp: int = 100:
|
|
set(value):
|
|
if value < 0:
|
|
hp = 0
|
|
else:
|
|
hp = value
|
|
if hp == 0:
|
|
die()
|
|
|
|
get:
|
|
return hp
|
|
|
|
var TEMP_start_pos
|
|
|
|
func _enter_tree() -> void:
|
|
set_multiplayer_authority(str(name).to_int())
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
if not is_multiplayer_authority():
|
|
return
|
|
|
|
move_and_slide()
|
|
|
|
func die() -> void:
|
|
if not is_multiplayer_authority():
|
|
return
|
|
|
|
global_position = TEMP_start_pos
|
|
hp = MAX_HP
|
|
|
|
@rpc("any_peer","call_local","reliable")
|
|
func set_after_spawn(start_position: Vector3,new_team: int):
|
|
global_position = start_position
|
|
TEMP_start_pos = global_position
|
|
team = new_team as Session.TEAMS
|
|
spawned.emit()
|
|
|
|
@rpc("any_peer","call_local","reliable")
|
|
func take_damage(damage: int):
|
|
hp -= damage
|