Implemented firerate
This commit is contained in:
parent
76b8dc3a17
commit
eb99032a63
|
@ -145,10 +145,15 @@ func shot(client_id):
|
|||
var target_client_id = int(clients.find_key(target_client))
|
||||
|
||||
var current_weapon = Weapons.find_key(client["current_weapon"])
|
||||
var damage = settings["game"]["weapons"][current_weapon]["damage"];
|
||||
var current_weapon_settings = settings["game"]["weapons"][current_weapon]
|
||||
var damage = current_weapon_settings["damage"];
|
||||
var time_since_last_shot = (Time.get_ticks_msec() - client["last_shot"]) / 1000.
|
||||
|
||||
if (time_since_last_shot < current_weapon_settings["fireRate"] and client["last_shot"] > 0):
|
||||
return
|
||||
client["last_shot"] = Time.get_ticks_msec()
|
||||
|
||||
target_client["HP"] -= damage
|
||||
|
||||
if (target_client["HP"] <= 0):
|
||||
target_cb3d.teleport.rpc_id(target_client_id, Vector3(0, 10, 0))
|
||||
target_client["HP"] = 100
|
||||
|
|
|
@ -27,7 +27,8 @@ var properties = {
|
|||
internal_id = 0,
|
||||
nickname = "Unnamed",
|
||||
ready = false,
|
||||
current_weapon = 0
|
||||
current_weapon = 0,
|
||||
last_shot = 0
|
||||
}
|
||||
|
||||
var speed = 0
|
||||
|
@ -38,7 +39,8 @@ var gravity = 0
|
|||
var game_settings
|
||||
var client_settings
|
||||
var current_weapon = Weapons["knife"]
|
||||
|
||||
var can_shoot = true
|
||||
var time_since_last_shot = 0
|
||||
@onready var head = $Head
|
||||
@onready var camera = $Head/Camera
|
||||
@onready var playerCharacterBody = $"."
|
||||
|
@ -69,6 +71,19 @@ func _ready():
|
|||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
|
||||
func try_shoot():
|
||||
var current_weapon = Weapons.find_key(properties["current_weapon"])
|
||||
var current_weapon_settings = game_settings["weapons"][current_weapon]
|
||||
if Input.is_action_pressed("shoot") and current_weapon_settings["fireRate"] >= 0.5 and not Input.is_action_just_pressed("shoot"):
|
||||
return
|
||||
time_since_last_shot = (Time.get_ticks_msec() - properties["last_shot"]) / 1000.
|
||||
print("TSLS: " + str(time_since_last_shot) + " fireRate: " + str(current_weapon_settings["fireRate"]))
|
||||
|
||||
if (time_since_last_shot > current_weapon_settings["fireRate"]):
|
||||
Networking.shot.rpc_id(1, multiplayer.get_unique_id())
|
||||
properties["last_shot"] = Time.get_ticks_msec()
|
||||
print("I am shooting")
|
||||
|
||||
func _unhandled_input(event):
|
||||
if (!properties["is_playable"]): return
|
||||
|
||||
|
@ -80,9 +95,9 @@ func _unhandled_input(event):
|
|||
Networking.change_weapon.rpc_id(1, multiplayer.get_unique_id(), properties["current_weapon"])
|
||||
|
||||
change_weapon(properties["current_weapon"])
|
||||
if(event.is_action_pressed("shoot")):
|
||||
print(event.position)
|
||||
Networking.shot.rpc_id(1, multiplayer.get_unique_id())
|
||||
#if(event.is_action_pressed("shoot")):
|
||||
#print(event.position)
|
||||
|
||||
|
||||
if event is InputEventMouseMotion:
|
||||
head.rotate_y(-event.relative.x * SENSETIVITY)
|
||||
|
@ -96,13 +111,15 @@ func _physics_process(delta):
|
|||
properties["is_playable"] = false
|
||||
|
||||
healthBar.value = properties["HP"]
|
||||
if Input.is_action_pressed("shoot"):
|
||||
try_shoot()
|
||||
|
||||
if not is_on_floor():
|
||||
velocity.y -= 4 * gravity * delta
|
||||
|
||||
var input_dir = Input.get_vector("left", "right", "forward", "backward")
|
||||
var direction = (head.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
|
||||
if not is_on_floor():
|
||||
velocity.y -= 4 * gravity * delta
|
||||
|
||||
if is_on_floor():
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
velocity.y = jump
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"damage": 50,
|
||||
"reload": 3,
|
||||
"magazine": 1,
|
||||
"fireFate": 3,
|
||||
"fireRate": 3,
|
||||
"spreading": 0
|
||||
},
|
||||
"pistol": {
|
||||
|
|
Loading…
Reference in New Issue