extends Node const PLAYER_SPAWNER: String = "res://scenes/maps/base/player_spawner/PlayerSpawner.tscn" const OBJECT_SPAWNER: String = "res://scenes/maps/base/object_spawner/ObjectSpawner.tscn" var player_spawner: Node3D var object_spawner: Node3D # Called when the node enters the scene tree for the first time. func _ready() -> void: # add player spawner var err: Error = OK err = _add_player_spawner() if err != OK: print("Couldn't load player spawner") err = _add_object_spawner() if err != OK: print("Couldn't load object spawner") # add objects spawner _spawn_player() pass # Replace with function body. # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: pass @onready var SpawnLocations: SpawnController = $SpawnLocations func _spawn_player(): var char : Node3D = null if multiplayer.is_server(): for i in GameServerManager.players: char = ResourceLoader.load("res://scenes/characters/placeholder.tscn").instantiate() char.name = "PlayerPlaceholder_" + str(GameServerManager.players[i].name) var position = SpawnLocations.get_spawner(SpawnController.Sides.BLUE) char.global_position = position char.global_position = position var spawner: MultiplayerSpawner = player_spawner.find_child("MultiplayerSpawner") var root_node: Node3D = player_spawner.find_child("Players") spawner.spawn(char) root_node.add_child(char) func _add_player_spawner() -> Error : if not ResourceLoader.exists(PLAYER_SPAWNER): return ERR_DOES_NOT_EXIST var scene: PackedScene = ResourceLoader.load(PLAYER_SPAWNER) if not scene.can_instantiate(): return ERR_CANT_OPEN var node: Node3D = scene.instantiate() add_child(node) player_spawner = node return OK func _add_object_spawner() -> Error : if not ResourceLoader.exists(OBJECT_SPAWNER): return ERR_DOES_NOT_EXIST var scene: PackedScene = ResourceLoader.load(OBJECT_SPAWNER) if not scene.can_instantiate(): return ERR_CANT_OPEN var node: Node3D = scene.instantiate() add_child(node) object_spawner = node return OK var bullet_amount: int = 0 func spawn_bullet(starting_point: Node3D, speed: int, damage: int): var node: Node3D = ResourceLoader.load("res://scenes/weapon/bullet.tscn").instantiate() node.position = starting_point.global_position node.transform.basis = starting_point.global_transform.basis node.name = str(bullet_amount) node.speed = speed node.damage = damage bullet_amount += 1 var spawner: MultiplayerSpawner = object_spawner.find_child("MultiplayerSpawner") var root_node: Node3D = object_spawner.find_child("Objects") spawner.spawn(node) root_node.add_child(node)