Fixed weapon
This commit is contained in:
parent
a1dbbb72a9
commit
fb839f3467
|
@ -29,7 +29,7 @@ var properties_example = {
|
|||
nickname = "Unnamed",
|
||||
ready = false,
|
||||
current_weapon = Weapons["knife"].duplicate(),
|
||||
current_weapon_number = 0,
|
||||
weapons = Weapons.duplicate(),
|
||||
last_shot = 0,
|
||||
reloading = false,
|
||||
position = Vector3(0, 5, 0)
|
||||
|
|
|
@ -206,13 +206,10 @@ func change_weapon(client_id, new_weapon_number):
|
|||
var client = clients[client_id]
|
||||
client["reloading"] = false
|
||||
var internal_id = str(client["internal_id"])
|
||||
for weapon in GameData.Weapons.keys():
|
||||
if (GameData.server_settings["game"]["weapons"][weapon]["number"] == new_weapon_number):
|
||||
client["current_weapon"] = GameData.server_settings["game"]["weapons"][weapon].duplicate()
|
||||
break
|
||||
client["current_weapon"] = client["weapons"][ServerUtils.find_weapon_name_by_number(new_weapon_number)]
|
||||
var client_playermodel = ServerUtils.find_playermodel_by_internal_id(internal_id)
|
||||
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])
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
|
|
|
@ -112,12 +112,36 @@ func update_hud():
|
|||
osScoreGameLabel.text = str(round_status["os_game_score"])
|
||||
|
||||
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):
|
||||
properties["reloading"] = false
|
||||
var weapons = $"Head/Camera/Hand".get_children()
|
||||
for weapon in weapons:
|
||||
weapon.visible = false
|
||||
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):
|
||||
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)
|
||||
|
||||
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]
|
||||
properties["reloading"] = false
|
||||
|
||||
|
@ -196,16 +222,17 @@ func reload():
|
|||
func _unhandled_input(event):
|
||||
if (!properties["is_playable"]): return
|
||||
|
||||
var weapon_change = 0
|
||||
if Input.is_action_pressed("MWU"):
|
||||
var weapon_number = wrap(properties["current_weapon"]["number"] + 1, 0, game_settings["weapons"].size())
|
||||
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"])
|
||||
weapon_change = 1
|
||||
if Input.is_action_pressed("MWD"):
|
||||
var weapon_number = wrap(properties["current_weapon"]["number"] - 1, 0, game_settings["weapons"].size())
|
||||
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"])
|
||||
weapon_change = -1
|
||||
if (weapon_change != 0):
|
||||
var new_weapon_number = wrap(properties["current_weapon"]["number"] + weapon_change, 0, game_settings["weapons"].size())
|
||||
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:
|
||||
rotate_y(-event.relative.x * SENSETIVITY)
|
||||
|
@ -232,7 +259,7 @@ func _physics_process(delta):
|
|||
|
||||
if Input.is_action_just_pressed("reload"):
|
||||
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
|
||||
get_tree().create_timer(game_settings["weapons"][current_weapon]["reload"]).connect("timeout", reload)
|
||||
|
||||
|
|
|
@ -44,6 +44,13 @@ func check_gamemode_availability(gm):
|
|||
return true
|
||||
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):
|
||||
var found_weapon
|
||||
for weapon in GameData.server_settings["game"]["weapons"].keys():
|
||||
|
|
Loading…
Reference in New Issue