From 0f0217713a89f2e2ca72e9b8a142161269168014 Mon Sep 17 00:00:00 2001 From: leca Date: Mon, 26 Feb 2024 13:32:26 +0300 Subject: [PATCH] Implementation of teams and it's spawnpoints and partial(basic) implementation of classes --- scenes/HUD/choose_team.tscn | 311 ++++++++++++++++++++++++++++++--- scenes/maps/OffisMi.tscn | 13 +- scenes/models/player.tscn | 2 +- scenes/special/spawnpoint.tscn | 17 ++ scripts/Networking.gd | 90 +++++++--- scripts/Player.gd | 45 +++-- scripts/Select.gd | 23 ++- scripts/team_spawnpoint.gd | 19 ++ settings/client-settings.json | 4 +- settings/server-settings.json | 2 +- 10 files changed, 445 insertions(+), 81 deletions(-) create mode 100644 scenes/special/spawnpoint.tscn create mode 100644 scripts/team_spawnpoint.gd diff --git a/scenes/HUD/choose_team.tscn b/scenes/HUD/choose_team.tscn index d6a3ed9..d92eb04 100644 --- a/scenes/HUD/choose_team.tscn +++ b/scenes/HUD/choose_team.tscn @@ -4,23 +4,40 @@ [node name="ChooseTeam" type="Control"] layout_mode = 3 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 grow_horizontal = 2 grow_vertical = 2 -[node name="CS" type="Control" parent="."] +[node name="Choose_team" type="Control" parent="."] layout_mode = 1 -anchors_preset = 4 +anchors_preset = 8 +anchor_left = 0.5 anchor_top = 0.5 +anchor_right = 0.5 anchor_bottom = 0.5 +offset_left = -20.0 offset_top = -20.0 -offset_right = 40.0 +offset_right = 20.0 offset_bottom = 20.0 +grow_horizontal = 2 grow_vertical = 2 -[node name="Closed source" type="Label" parent="CS"] +[node name="CS" type="Control" parent="Choose_team"] +layout_mode = 1 +anchors_preset = 11 +anchor_left = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = 37.0 +offset_right = 37.0 +grow_horizontal = 0 +grow_vertical = 2 + +[node name="Closed source" type="Label" parent="Choose_team/CS"] layout_mode = 0 offset_left = 100.0 offset_top = -100.0 @@ -29,7 +46,7 @@ offset_bottom = -77.0 text = "Closed source " -[node name="Select_CS" type="Button" parent="CS"] +[node name="Select_CS" type="Button" parent="Choose_team/CS"] layout_mode = 0 offset_left = 121.0 offset_right = 175.0 @@ -38,20 +55,15 @@ text = "Select " script = ExtResource("1_nua8c") -[node name="OS" type="Control" parent="."] +[node name="OS" type="Control" parent="Choose_team"] layout_mode = 1 -anchors_preset = 6 -anchor_left = 1.0 -anchor_top = 0.5 -anchor_right = 1.0 -anchor_bottom = 0.5 -offset_left = -40.0 -offset_top = -20.0 -offset_bottom = 20.0 -grow_horizontal = 0 +anchors_preset = 9 +anchor_bottom = 1.0 +offset_left = -130.0 +offset_right = -130.0 grow_vertical = 2 -[node name="Open source" type="Label" parent="OS"] +[node name="Open source" type="Label" parent="Choose_team/OS"] layout_mode = 0 offset_left = -150.0 offset_top = -100.0 @@ -60,7 +72,7 @@ offset_bottom = -77.0 text = "Open source " -[node name="Select_OS" type="Button" parent="OS"] +[node name="Select_OS" type="Button" parent="Choose_team/OS"] layout_mode = 0 offset_left = -129.0 offset_right = -75.0 @@ -68,3 +80,262 @@ offset_bottom = 31.0 text = "Select " script = ExtResource("1_nua8c") + +[node name="Spectator" type="Control" parent="Choose_team"] +layout_mode = 1 +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 0 + +[node name="Spectator" type="Label" parent="Choose_team/Spectator"] +layout_mode = 0 +offset_left = -33.0 +offset_right = 42.0 +offset_bottom = 23.0 +text = "Spectator" + +[node name="Select_SP" type="Button" parent="Choose_team/Spectator"] +layout_mode = 0 +offset_left = -21.0 +offset_top = 56.0 +offset_right = 33.0 +offset_bottom = 87.0 +text = "Select +" +script = ExtResource("1_nua8c") + +[node name="Choose_class_OS" type="Control" parent="."] +visible = false +layout_mode = 1 +anchors_preset = 0 +offset_left = -556.0 +offset_top = -139.0 +offset_right = -556.0 +offset_bottom = -139.0 + +[node name="Class 1" type="Control" parent="Choose_class_OS"] +layout_mode = 3 +anchors_preset = 0 +offset_right = 40.0 +offset_bottom = 40.0 +scale = Vector2(3.8, 3.8) + +[node name="Name" type="Label" parent="Choose_class_OS/Class 1"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 23.0 +text = "Class 1" + +[node name="Select_1" type="Button" parent="Choose_class_OS/Class 1"] +layout_mode = 0 +offset_top = 23.0 +offset_right = 54.0 +offset_bottom = 54.0 +text = "Select" +script = ExtResource("1_nua8c") + +[node name="Class 2" type="Control" parent="Choose_class_OS"] +anchors_preset = 0 +offset_left = 221.0 +offset_right = 261.0 +offset_bottom = 40.0 +scale = Vector2(3.8, 3.8) + +[node name="Name" type="Label" parent="Choose_class_OS/Class 2"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 23.0 +text = "Class 2" + +[node name="Select_2" type="Button" parent="Choose_class_OS/Class 2"] +layout_mode = 0 +offset_top = 23.0 +offset_right = 54.0 +offset_bottom = 54.0 +text = "Select" +script = ExtResource("1_nua8c") + +[node name="Class 3" type="Control" parent="Choose_class_OS"] +anchors_preset = 0 +offset_left = 445.0 +offset_right = 485.0 +offset_bottom = 40.0 +scale = Vector2(3.8, 3.8) + +[node name="Name" type="Label" parent="Choose_class_OS/Class 3"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 23.0 +text = "Class 3" + +[node name="Select_3" type="Button" parent="Choose_class_OS/Class 3"] +layout_mode = 0 +offset_top = 23.0 +offset_right = 54.0 +offset_bottom = 54.0 +text = "Select" +script = ExtResource("1_nua8c") + +[node name="Class 4" type="Control" parent="Choose_class_OS"] +anchors_preset = 0 +offset_left = 670.0 +offset_right = 710.0 +offset_bottom = 40.0 +scale = Vector2(3.8, 3.8) + +[node name="Name" type="Label" parent="Choose_class_OS/Class 4"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 23.0 +text = "Class 4" + +[node name="Select_4" type="Button" parent="Choose_class_OS/Class 4"] +layout_mode = 0 +offset_top = 23.0 +offset_right = 54.0 +offset_bottom = 54.0 +text = "Select" +script = ExtResource("1_nua8c") + +[node name="Class 5" type="Control" parent="Choose_class_OS"] +anchors_preset = 0 +offset_left = 894.0 +offset_right = 934.0 +offset_bottom = 40.0 +scale = Vector2(3.8, 3.8) + +[node name="Name" type="Label" parent="Choose_class_OS/Class 5"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 23.0 +text = "Class 5" + +[node name="Select_5" type="Button" parent="Choose_class_OS/Class 5"] +layout_mode = 0 +offset_top = 23.0 +offset_right = 54.0 +offset_bottom = 54.0 +text = "Select" +script = ExtResource("1_nua8c") + +[node name="Choose_class_CS" type="Control" parent="."] +visible = false +layout_mode = 1 +anchors_preset = 14 +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +offset_left = -560.0 +offset_top = -139.0 +offset_right = -560.0 +offset_bottom = -139.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Class -1" type="Control" parent="Choose_class_CS"] +layout_mode = 3 +anchors_preset = 0 +offset_right = 40.0 +offset_bottom = 40.0 +scale = Vector2(3.8, 3.8) + +[node name="Name" type="Label" parent="Choose_class_CS/Class -1"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 23.0 +text = "Class -1" + +[node name="Select_-1" type="Button" parent="Choose_class_CS/Class -1"] +layout_mode = 0 +offset_top = 23.0 +offset_right = 54.0 +offset_bottom = 54.0 +text = "Select" +script = ExtResource("1_nua8c") + +[node name="Class -2" type="Control" parent="Choose_class_CS"] +anchors_preset = 0 +offset_left = 221.0 +offset_right = 261.0 +offset_bottom = 40.0 +scale = Vector2(3.8, 3.8) + +[node name="Name" type="Label" parent="Choose_class_CS/Class -2"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 23.0 +text = "Class -2" + +[node name="Select_-2" type="Button" parent="Choose_class_CS/Class -2"] +layout_mode = 0 +offset_top = 23.0 +offset_right = 54.0 +offset_bottom = 54.0 +text = "Select" +script = ExtResource("1_nua8c") + +[node name="Class -3" type="Control" parent="Choose_class_CS"] +anchors_preset = 0 +offset_left = 445.0 +offset_right = 485.0 +offset_bottom = 40.0 +scale = Vector2(3.8, 3.8) + +[node name="Name" type="Label" parent="Choose_class_CS/Class -3"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 23.0 +text = "Class -3" + +[node name="Select_-3" type="Button" parent="Choose_class_CS/Class -3"] +layout_mode = 0 +offset_top = 23.0 +offset_right = 54.0 +offset_bottom = 54.0 +text = "Select" +script = ExtResource("1_nua8c") + +[node name="Class -4" type="Control" parent="Choose_class_CS"] +anchors_preset = 0 +offset_left = 670.0 +offset_right = 710.0 +offset_bottom = 40.0 +scale = Vector2(3.8, 3.8) + +[node name="Name" type="Label" parent="Choose_class_CS/Class -4"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 23.0 +text = "Class -4" + +[node name="Select_-4" type="Button" parent="Choose_class_CS/Class -4"] +layout_mode = 0 +offset_top = 23.0 +offset_right = 54.0 +offset_bottom = 54.0 +text = "Select" +script = ExtResource("1_nua8c") + +[node name="Class -5" type="Control" parent="Choose_class_CS"] +anchors_preset = 0 +offset_left = 894.0 +offset_right = 934.0 +offset_bottom = 40.0 +scale = Vector2(3.8, 3.8) + +[node name="Name" type="Label" parent="Choose_class_CS/Class -5"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 23.0 +text = "Class -5" + +[node name="Select_-5" type="Button" parent="Choose_class_CS/Class -5"] +layout_mode = 0 +offset_top = 23.0 +offset_right = 54.0 +offset_bottom = 54.0 +text = "Select" +script = ExtResource("1_nua8c") diff --git a/scenes/maps/OffisMi.tscn b/scenes/maps/OffisMi.tscn index ab8776f..4170f36 100644 --- a/scenes/maps/OffisMi.tscn +++ b/scenes/maps/OffisMi.tscn @@ -1,4 +1,6 @@ -[gd_scene load_steps=5 format=3 uid="uid://18evx7g8m824"] +[gd_scene load_steps=6 format=3 uid="uid://18evx7g8m824"] + +[ext_resource type="PackedScene" uid="uid://833q6upr0s1k" path="res://scenes/special/spawnpoint.tscn" id="1_cgcr3"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_efxfa"] @@ -18,7 +20,7 @@ tonemap_white = 4.37 [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_8g7wu"] [node name="OffisMi" type="Node3D"] -transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 26.5085, -5.99906, 0) +transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 26.508, 0, 0) [node name="WorldEnvironment" type="WorldEnvironment" parent="."] environment = SubResource("Environment_n1nic") @@ -69,3 +71,10 @@ depth = 3.72 [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] transform = Transform3D(-4.37114e-08, 0.422618, -0.906308, 0, 0.906308, 0.422618, 1, 1.84732e-08, -3.9616e-08, -68.4262, 84.9077, -2.99101e-06) + +[node name="spawnpoint" parent="." instance=ExtResource("1_cgcr3")] +transform = Transform3D(4, 0, 0, 0, 4, 0, 0, 0, 4, -16.854, 0.629008, 2.82309) +team = 1 + +[node name="spawnpoint2" parent="." instance=ExtResource("1_cgcr3")] +transform = Transform3D(4, 0, 0, 0, 4, 0, 0, 0, 4, 23.9201, 0.425767, -1.07893) diff --git a/scenes/models/player.tscn b/scenes/models/player.tscn index 81df13f..83ad235 100644 --- a/scenes/models/player.tscn +++ b/scenes/models/player.tscn @@ -11,7 +11,7 @@ [sub_resource type="CapsuleMesh" id="CapsuleMesh_jqfxo"] [node name="player" type="Node3D"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.10113, 0) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) [node name="CharacterBody3D" type="CharacterBody3D" parent="."] script = ExtResource("1_8hh2g") diff --git a/scenes/special/spawnpoint.tscn b/scenes/special/spawnpoint.tscn new file mode 100644 index 0000000..7c725bb --- /dev/null +++ b/scenes/special/spawnpoint.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=4 format=3 uid="uid://833q6upr0s1k"] + +[ext_resource type="Script" path="res://scripts/team_spawnpoint.gd" id="1_xuukx"] + +[sub_resource type="PlaneMesh" id="PlaneMesh_ic53j"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_lytgi"] +albedo_color = Color(1, 1, 0, 1) + +[node name="spawnpoint" type="Node3D"] +transform = Transform3D(4, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0) +script = ExtResource("1_xuukx") + +[node name="area" type="CSGMesh3D" parent="."] +visible = false +mesh = SubResource("PlaneMesh_ic53j") +material = SubResource("StandardMaterial3D_lytgi") diff --git a/scripts/Networking.gd b/scripts/Networking.gd index 3234eda..dc838af 100644 --- a/scripts/Networking.gd +++ b/scripts/Networking.gd @@ -11,6 +11,9 @@ var last_client_id = 1 var map_path var map_root_name +var spawnpoints_os = [] +var spawnpoints_cs = [] + func parse_arguments(): var arguments = {} for argument in OS.get_cmdline_args(): @@ -47,12 +50,11 @@ func StartServer(map_name): await get_tree().create_timer(0.1).timeout #костыль пиздец но мне похую как-то var root_node_name = (map_name.split("/")[-1]).split(".")[0] - print(str(root_node_name)) - print(str(get_tree().root.get_children())) server_map = get_tree().root.get_node(root_node_name) await get_tree().create_timer(0.5).timeout #костыль + settings = GameData.server_settings var port = int(settings["port"]) var maxclients = int(settings["maxclients"]) @@ -68,7 +70,15 @@ func StartServer(map_name): var spectator = preload("res://scenes/models/spectator.tscn").instantiate() server_map.add_child(spectator) - + var spawnpoints = server_map.find_children("spawnpoint*", "" ,true) + print(str(spawnpoints)) + for spawnpoint in spawnpoints: + print("Checking spawnpoint: " + str(spawnpoint) + ", team: " + str(spawnpoint.team)) + if spawnpoint.team == 0: # cs + spawnpoints_cs.push_back(spawnpoint) + elif spawnpoint.team > 0: # os + spawnpoints_os.push_back(spawnpoint) + func send_everyone_except(client_id, args): if (typeof(args[0]) == 4): #string for current_client_id in clients.keys(): @@ -108,10 +118,11 @@ func _Peer_Connected(client_id): last_client_id += 1 clients[client_id] = player_script.new().properties.duplicate() - clients[client_id]["position"] = Vector3(0, 10, 0) - clients[client_id]["internal_id"] = internal_id - clients[client_id]["is_playable"] = false - clients[client_id]["current_weapon"] = settings["game"]["weapons"]["knife"].duplicate() + var client = clients[client_id] + client["position"] = Vector3(0, 10, 0) + client["internal_id"] = internal_id + client["is_playable"] = false + client["current_weapon"] = settings["game"]["weapons"]["knife"].duplicate() print("New client's properties: " + str(clients[client_id])) @@ -128,11 +139,19 @@ func client_ready(client_id): send_everyone_except(client_id, ["spawn_puppet", clients[client_id]]) - clients[client_id]["ready"] = true + client["ready"] = true var client_cb3d = find_cb3d_by_internal_id(internal_id) - var class_spawnpoint = find_class_type_by_number(client["class_type"])["spawnpoint"] + if (client["class_type"] == 0): + var class_spawnpoint = find_class_type_by_number(client["class_type"])["spawnpoint"] + client["position"] = Vector3(class_spawnpoint[0], class_spawnpoint[1], class_spawnpoint[2]) + else: + var index = abs(client["class_type"]) + if (client["class_type"] > 0): + client["position"] = spawnpoints_os.pick_random().get_class_spawnpoint(index) + elif (client["class_type"] < 0): + client["position"] = spawnpoints_cs.pick_random().get_class_spawnpoint(index) client_cb3d.set_properties(client) - client_cb3d.teleport.rpc_id(client_id, Vector3(class_spawnpoint[0], class_spawnpoint[1], class_spawnpoint[2])) + client_cb3d.teleport.rpc_id(client_id, Vector3(client["position"].x, client["position"].y, client["position"].z)) func _Peer_Disconnected(client_id): print("User " + str(client_id) + " has disconnected") @@ -149,7 +168,7 @@ func get_character_properties(client_id): return var to_send = clients[client_id] rpc_id(client_id, "set_character_properties", to_send.duplicate()) - + @rpc("any_peer", "call_remote", "unreliable") func sync_client(client_id, position, rotation): var client = clients[client_id] @@ -196,8 +215,8 @@ func shot(client_id): raycast.force_update_transform() var target_point = raycast.get_collision_point() - weapon_raycast.target_position = weapon_raycast.to_local(target_point) #- weapon_raycast.position) - weapon_raycast.get_node("..").rotation.y = - atan((weapon_raycast.position.x - client_cb3d.position.x) / ((-current_weapon_settings["range"]) - (abs(weapon_raycast.position.z - client_cb3d.position.z)))) + weapon_raycast.target_position = weapon_raycast.to_local(target_point) * 1.1 + weapon_raycast.rotation.y = atan((weapon_raycast.position.x - client_cb3d.position.x) / ((-current_weapon_settings["range"]) - (abs(weapon_raycast.position.z - client_cb3d.position.z)))) weapon_raycast.target_position.y += current_weapon_settings["spreading"] * randf() * sin(randf() * 2 * PI) weapon_raycast.target_position.z += current_weapon_settings["spreading"] * randf() * cos(randf() * 2 * PI) @@ -244,7 +263,7 @@ func change_weapon(client_id, new_weapon_number): var client_cb3d = find_cb3d_by_internal_id(internal_id) client_cb3d.change_weapon(new_weapon_number) send_everyone_except(client_id, [client_cb3d.change_weapon_puppet, internal_id, new_weapon_number]) - + @rpc("any_peer", "call_remote", "reliable") func client_reloading(client_id): var client = clients[client_id] @@ -277,11 +296,21 @@ func reloading_complete(client_id, reloading_time): @rpc("reliable", "any_peer", "call_remote") func get_map(client_id): rpc_id(client_id, "receive_map", map_path) + +@rpc("reliable", "any_peer", "call_remote") +func choose_class(client_id, class_id): + var client = clients[client_id] + client["class_type"] = class_id + #here are must be checks if the teams are balanced. WIP. + switch_class.rpc_id(client_id, class_id) + ##########################################CLIENT####################### var player var menu = preload("res://scenes/HUD/menu.tscn") var current_map_instance +var choose_team_hud +var player_cb3d @rpc ("reliable", "call_remote") func set_character_properties(p): @@ -306,19 +335,28 @@ func despawn_puppet(internal_id): func receive_map(p): map_path = p map_root_name = (map_path.split("/")[-1]).split(".")[0] - + @rpc("authority", "reliable", "call_remote") -func switch_team(team): - pass +func switch_class(class_id): + print("Switching to team: " + str(class_id)) + if (class_id == 128): # team is full, you must chose another + current_map_instance.remove_child(choose_team_hud) + current_map_instance.add_child(choose_team_hud) + + player["class_type"] = class_id + rpc_id(1, "client_ready", multiplayer.get_unique_id()) + current_map_instance.remove_child(choose_team_hud) + player_cb3d.set_property("is_playable", true) + player_cb3d.set_property("ready", true) func spawn_player(): var player_node = player_model.instantiate() - var CB3D = player_node.find_child("CharacterBody3D") + player_cb3d = player_node.find_child("CharacterBody3D") var properties = player_script.new().properties.duplicate() properties = player - properties["is_playable"] = true - properties["ready"] = true - CB3D.set_properties(properties) + properties["is_playable"] = false + properties["ready"] = false + player_cb3d.set_properties(properties) current_map_instance.add_child(player_node) @@ -338,7 +376,7 @@ func _Connection_Failed(): multiplayer.multiplayer_peer = null peer = ENetMultiplayerPeer.new() multiplayer.multiplayer_peer = peer - + func _Connection_Succseeded(): print("Succsessfully connected to the server") var nickname = GameData.client_settings["nickname"] @@ -357,11 +395,9 @@ func _Connection_Succseeded(): await spawn_player() - #var choose_team_hud = preload("res://scenes/HUD/choose_team.tscn").instantiate() - #current_map_instance.add_child(choose_team_hud) - - rpc_id(1, "client_ready", multiplayer.get_unique_id()) - + choose_team_hud = preload("res://scenes/HUD/choose_team.tscn").instantiate() + current_map_instance.add_child(choose_team_hud) + func _Server_Disconnected(): print("Server has disconnected") Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) diff --git a/scripts/Player.gd b/scripts/Player.gd index e5260e4..2b77f85 100644 --- a/scripts/Player.gd +++ b/scripts/Player.gd @@ -31,7 +31,8 @@ var properties = { current_weapon_number = 0, last_shot = 0, reloading = false, - offline_mode = false + offline_mode = false, + position = Vector3(0, 5, 0) } var speed = 12 @@ -46,7 +47,7 @@ var client_settings var can_shoot = true var time_since_last_shot = 0 @onready var head = $Head -@onready var camera = $Head/Camera +@onready var camera: Camera3D = $Head/Camera @onready var playerCharacterBody = $"." var HUD var healthBar @@ -58,9 +59,14 @@ func set_properties(props): properties = props $"Head/Nickname".text = properties["nickname"] $"..".name = "player" + str(properties["internal_id"]) + position = properties["position"] if (game_settings != null): change_weapon(properties["current_weapon"]["number"]) - + +func set_property(key, value): + properties[key] = value + update_state() + func update_hud(): healthBar.value = properties["HP"] ammoLabel.text = "Ammo: " + str(properties["current_weapon"]["ammo"]) @@ -93,14 +99,15 @@ func find_current_weapon_by_number(number): break return found_weapon -func _ready(): - position = Vector3(0, 5, 0) +func update_state(): + camera.set_current(false) $"Head/Nickname".text = properties["nickname"] if (!properties["is_playable"]): return - camera.make_current() - print("I am alive") - var hud = load("res://scenes/HUD/hud.tscn").instantiate() - add_child(hud) + camera.set_current(true) + if (HUD == null): + var hud = load("res://scenes/HUD/hud.tscn").instantiate() + add_child(hud) + HUD = $"HUD" healthBar = HUD.get_node("HealthBar") ammoLabel = HUD.get_node("AmmoDisplay/Ammo") @@ -110,10 +117,11 @@ func _ready(): playerCharacterBody.up_direction = Vector3.UP; Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) +func _ready(): + update_state() + func update_weapon_raycast(): - print(str(Weapons)) var current_weapon_name = Weapons.find_key(properties["current_weapon"]) - print(current_weapon_name) if(current_weapon_name == null): current_weapon_name = "knife" var raycast:RayCast3D = get_node("Head/Camera/viewRaycast") var weapon_raycast:RayCast3D = get_node("Head/Camera/Hand/" + str(current_weapon_name) + "/raycast") @@ -123,11 +131,12 @@ func update_weapon_raycast(): func try_shoot(): var current_weapon = game_settings["weapons"].find_key(find_weapon_by_number(properties["current_weapon"]["number"])) var current_weapon_settings = game_settings["weapons"][current_weapon] + properties["reloading"] = false + if (properties["current_weapon"]["magazine"] == 0): return if Input.is_action_pressed("shoot") and current_weapon_settings["fireRate"] >= 0.5 and not Input.is_action_just_pressed("shoot"): return - properties["reloading"] = false time_since_last_shot = (Time.get_ticks_msec() - properties["last_shot"]) / 1000. if (time_since_last_shot > current_weapon_settings["fireRate"]): @@ -142,7 +151,6 @@ func reload(): var current_weapon_settings = game_settings["weapons"][current_weapon] var to_reload = current_weapon_settings["magazine"] - current_weapon_instance["magazine"] if (properties["reloading"]): - print("Succsessfully reloaded") if (to_reload <= current_weapon_instance["ammo"]): current_weapon_instance["magazine"] += to_reload current_weapon_instance["ammo"] -= to_reload @@ -228,34 +236,25 @@ func sync_puppet(i_id, p, rot): @rpc ("authority", "call_remote", "reliable") func set_hp(hp): - print("Got new hp" + str(hp)) if (!properties["is_playable"]): return properties["HP"] = hp healthBar.value = properties["HP"] @rpc ("authority", "call_remote", "reliable") func set_game_settings(s): - if(!properties["is_playable"]): return - #print("Got settings from server: " + str(s)) + #if(!properties["is_playable"]): return game_settings = s gravity = game_settings["moving"]["gravity"] walk = game_settings["moving"]["walk"] run = game_settings["moving"]["run"] jump = game_settings["moving"]["jump"] - print("Game settings weapon list: "+ str(game_settings["weapons"])) - print("Changing weapon to " + str(properties["current_weapon"]["number"])) change_weapon(properties["current_weapon"]["number"]) @rpc ("authority", "call_remote", "reliable") func teleport(pos): $".".position = pos - print("Teleporing to " + str(pos)) @rpc ("authority", "call_remote", "reliable") func change_weapon_puppet(i_id, new_weapon_number): if (int(i_id) == properties["internal_id"]): change_weapon(new_weapon_number) - -#@rpc("any_peer", "call_remote", "reliable") -#func shot_made(): - #properties["current_weapon"]["magazine"] -= 1 diff --git a/scripts/Select.gd b/scripts/Select.gd index 3965fc8..5181fa1 100644 --- a/scripts/Select.gd +++ b/scripts/Select.gd @@ -1,11 +1,26 @@ extends Button @onready var button = $"." +@onready var choose_team = $"../.." +@onready var choose_class_os = $"../../../Choose_class_OS" +@onready var choose_class_cs = $"../../../Choose_class_CS" + func _ready(): button.pressed.connect(self._button_pressed) func _button_pressed(): - if name == "Select_CS": - print("Selected CS") - elif name == "Select_OS": - print("Selected OS") + var team + match name: + "Select_CS": + choose_class_cs.visible = true + choose_class_os.visible = false + "Select_OS": + choose_class_os.visible = true + choose_class_cs.visible = false + "Select_SP": + print("Spectating") + Networking.choose_class.rpc_id(1, multiplayer.get_unique_id(), 0) + _: + var class_id = int(name.split("_")[1]) + Networking.choose_class.rpc_id(1, multiplayer.get_unique_id(), class_id) + choose_team.visible = false diff --git a/scripts/team_spawnpoint.gd b/scripts/team_spawnpoint.gd new file mode 100644 index 0000000..904a356 --- /dev/null +++ b/scripts/team_spawnpoint.gd @@ -0,0 +1,19 @@ +extends Node3D + +enum teams { + team_CS = -1, + team_OS = 1 +} + +@onready var spawnpoints = [ + Vector3(0, 1, 0), + Vector3(scale.x, 2, scale.z), + Vector3(-scale.x, 2, scale.z), + Vector3(scale.x, 2, -scale.z), + Vector3(-scale.x, 2, -scale.z) +] + +@export var team:teams + +func get_class_spawnpoint(class_id): + return position + (spawnpoints[abs(class_id) - 1]) diff --git a/settings/client-settings.json b/settings/client-settings.json index 97a1386..db8db0b 100644 --- a/settings/client-settings.json +++ b/settings/client-settings.json @@ -1,3 +1 @@ -{ - "nickname": "Unnamed" -} +{ "nickname": "Unnamed" } diff --git a/settings/server-settings.json b/settings/server-settings.json index bce81e8..30c3f6a 100644 --- a/settings/server-settings.json +++ b/settings/server-settings.json @@ -36,7 +36,7 @@ "reload": 4, "magazine": 30, "fireRate": 0.2, - "spreading": 0, + "spreading": 1, "ammo": 100, "range": 100 }