Fixed weapon

This commit is contained in:
leca 2024-03-10 01:01:27 +03:00
parent a1dbbb72a9
commit fb839f3467
4 changed files with 48 additions and 17 deletions

View File

@ -29,7 +29,7 @@ var properties_example = {
nickname = "Unnamed", nickname = "Unnamed",
ready = false, ready = false,
current_weapon = Weapons["knife"].duplicate(), current_weapon = Weapons["knife"].duplicate(),
current_weapon_number = 0, weapons = Weapons.duplicate(),
last_shot = 0, last_shot = 0,
reloading = false, reloading = false,
position = Vector3(0, 5, 0) position = Vector3(0, 5, 0)

View File

@ -206,13 +206,10 @@ func change_weapon(client_id, new_weapon_number):
var client = clients[client_id] var client = clients[client_id]
client["reloading"] = false client["reloading"] = false
var internal_id = str(client["internal_id"]) var internal_id = str(client["internal_id"])
for weapon in GameData.Weapons.keys(): client["current_weapon"] = client["weapons"][ServerUtils.find_weapon_name_by_number(new_weapon_number)]
if (GameData.server_settings["game"]["weapons"][weapon]["number"] == new_weapon_number):
client["current_weapon"] = GameData.server_settings["game"]["weapons"][weapon].duplicate()
break
var client_playermodel = ServerUtils.find_playermodel_by_internal_id(internal_id) var client_playermodel = ServerUtils.find_playermodel_by_internal_id(internal_id)
client_playermodel.change_weapon(new_weapon_number) client_playermodel.change_weapon(new_weapon_number)
#NetUtils.send_everyone_except(client_id, ["change_weapon_puppet", internal_id, new_weapon_number]) client_playermodel.change_weapon.rpc_id(client_id, new_weapon_number)
NetUtils.send_everyone_except(client_id, [client_playermodel.change_weapon_puppet, internal_id, new_weapon_number]) NetUtils.send_everyone_except(client_id, [client_playermodel.change_weapon_puppet, internal_id, new_weapon_number])
@rpc("any_peer", "call_remote", "reliable") @rpc("any_peer", "call_remote", "reliable")

View File

@ -112,12 +112,36 @@ func update_hud():
osScoreGameLabel.text = str(round_status["os_game_score"]) osScoreGameLabel.text = str(round_status["os_game_score"])
roundNumberLabel.text = "Round " + str(round_status["round_number"]) roundNumberLabel.text = "Round " + str(round_status["round_number"])
func find_weapon_name_by_number(number):
var name = ""
for weapon in game_settings["weapons"].keys():
if (game_settings["weapons"][weapon].number == number):
name = weapon
return name
@rpc("authority", "call_local", "reliable")
func change_weapon(new_weapon_number): func change_weapon(new_weapon_number):
properties["reloading"] = false
var weapons = $"Head/Camera/Hand".get_children() var weapons = $"Head/Camera/Hand".get_children()
for weapon in weapons: for weapon in weapons:
weapon.visible = false weapon.visible = false
weapons[new_weapon_number].visible = true weapons[new_weapon_number].visible = true
print("Changing weapon: " + str(new_weapon_number))
#if (properties["is_playable"]):
#properties["current_weapon"] = properties["weapons"][find_weapon_name_by_number(new_weapon_number)]
#properties["reloading"] = false
func find_weapon_in_inventory(number):
var found_weapon
print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa: " + str(properties["weapons"]))
for weapon in properties["weapons"].values():
#var a:Dictionary = properties["weapons"]
#a.
print("Checking: " + str(weapon))
if weapon["number"] == number:
found_weapon = weapon
break
return found_weapon
func find_weapon_by_number(number): func find_weapon_by_number(number):
var found_weapon var found_weapon
@ -162,7 +186,9 @@ func update_weapon_raycast():
weapon_raycast.target_position = weapon_raycast.to_local(raycast.to_global(raycast.target_position) - weapon_raycast.position) weapon_raycast.target_position = weapon_raycast.to_local(raycast.to_global(raycast.target_position) - weapon_raycast.position)
func try_shoot(): func try_shoot():
var current_weapon = game_settings["weapons"].find_key(find_weapon_by_number(properties["current_weapon"]["number"])) print(str(properties["current_weapon"]))
#var current_weapon = game_settings["weapons"].find_key(find_weapon_by_number(properties["current_weapon"]["number"]))
var current_weapon = find_weapon_name_by_number(properties["current_weapon"]["number"])#game_settings["weapons"].find_key(find_weapon_by_number(properties["current_weapon"]["number"]))
var current_weapon_settings = game_settings["weapons"][current_weapon] var current_weapon_settings = game_settings["weapons"][current_weapon]
properties["reloading"] = false properties["reloading"] = false
@ -196,16 +222,17 @@ func reload():
func _unhandled_input(event): func _unhandled_input(event):
if (!properties["is_playable"]): return if (!properties["is_playable"]): return
var weapon_change = 0
if Input.is_action_pressed("MWU"): if Input.is_action_pressed("MWU"):
var weapon_number = wrap(properties["current_weapon"]["number"] + 1, 0, game_settings["weapons"].size()) weapon_change = 1
properties["current_weapon"] = find_current_weapon_by_number(weapon_number)
if (!properties["offline_mode"]): Networking.change_weapon.rpc_id(1, multiplayer.get_unique_id(), properties["current_weapon"]["number"])
change_weapon(properties["current_weapon"]["number"])
if Input.is_action_pressed("MWD"): if Input.is_action_pressed("MWD"):
var weapon_number = wrap(properties["current_weapon"]["number"] - 1, 0, game_settings["weapons"].size()) weapon_change = -1
properties["current_weapon"] = find_current_weapon_by_number(weapon_number) if (weapon_change != 0):
if (!properties["offline_mode"]): Networking.change_weapon.rpc_id(1, multiplayer.get_unique_id(), properties["current_weapon"]["number"]) var new_weapon_number = wrap(properties["current_weapon"]["number"] + weapon_change, 0, game_settings["weapons"].size())
change_weapon(properties["current_weapon"]["number"]) properties["current_weapon"] = find_weapon_in_inventory(new_weapon_number)
print(str(properties["current_weapon"]))
Networking.change_weapon.rpc_id(1, multiplayer.get_unique_id(), properties["current_weapon"]["number"])
if event is InputEventMouseMotion: if event is InputEventMouseMotion:
rotate_y(-event.relative.x * SENSETIVITY) rotate_y(-event.relative.x * SENSETIVITY)
@ -232,7 +259,7 @@ func _physics_process(delta):
if Input.is_action_just_pressed("reload"): if Input.is_action_just_pressed("reload"):
var current_weapon = game_settings["weapons"].find_key(find_weapon_by_number(properties["current_weapon"]["number"])) var current_weapon = game_settings["weapons"].find_key(find_weapon_by_number(properties["current_weapon"]["number"]))
if (!properties["offline_mode"]): Networking.client_reloading.rpc_id(1, multiplayer.get_unique_id()) Networking.client_reloading.rpc_id(1, multiplayer.get_unique_id())
properties["reloading"] = true properties["reloading"] = true
get_tree().create_timer(game_settings["weapons"][current_weapon]["reload"]).connect("timeout", reload) get_tree().create_timer(game_settings["weapons"][current_weapon]["reload"]).connect("timeout", reload)

View File

@ -44,6 +44,13 @@ func check_gamemode_availability(gm):
return true return true
return false return false
func find_weapon_name_by_number(number):
var name = ""
for weapon in GameData.server_settings["game"]["weapons"].keys():
if (GameData.server_settings["game"]["weapons"][weapon].number == number):
name = weapon
return name
func find_weapon_by_number(number): func find_weapon_by_number(number):
var found_weapon var found_weapon
for weapon in GameData.server_settings["game"]["weapons"].keys(): for weapon in GameData.server_settings["game"]["weapons"].keys():