FINISHED DAMN DROP SYSTEM

This commit is contained in:
Rendo 2025-11-28 18:03:30 +05:00
commit 100afe5e51
17 changed files with 151 additions and 25 deletions

View file

@ -28,6 +28,7 @@ signal switched_to(state: WeaponSubStateMachine)
func _ready() -> void:
current_state = default_pistol
add(default_pistol,"secondary")
add(default_knife,"knife")
current_state.enter()
$WeaponSpawner.spawn_function = pick_up_weapon
$WeaponSpawner.spawned.connect(on_weapon_added)
@ -55,7 +56,7 @@ func add(state: WeaponSubStateMachine, slot: StringName) -> void:
state.request_return.connect(return_to_previous)
func switch(to: StringName):
if slots.has(to) == false or slots[to] == null or slots[to] == current_state:
if slots.has(to) == false or slots[to] == null or slots[to] == current_state or is_multiplayer_authority() == false:
return
current_state.exit()
if current_state.can_be_previous:
@ -69,7 +70,23 @@ func switch(to: StringName):
update_remotes.rpc(to)
func drop(): pass
func drop():
if slots.find_key(current_state) == "knife":
return
var drop_data: Dictionary = {}
drop_data.scene = current_state.droppable
drop_data.ammo = current_state.ammo
drop_data.remaining_ammo = current_state.remaining_ammo
drop_data.slot = current_state.slot
drop_data.position = camera.global_position
drop_data.impulse = -camera.global_basis.z * 10
Session.spawn(drop_data)
$"../PickupRange".start_temp_ignore()
Session.despawn(current_state.get_path())
return_to_previous()
# Spawn function
# Data should be a dictionary with these keys:
@ -91,6 +108,8 @@ func on_weapon_added(weapon: Node):
func return_to_previous():
if last_slot != "":
switch(last_slot)
else:
switch("knife")
@rpc("authority","call_remote","reliable")
func update_remotes(to: StringName):
@ -143,4 +162,7 @@ func _input(event: InputEvent) -> void:
current_state.alternate_state()
if event.is_action_pressed("plr_firemode"):
current_state.switch_mode()
if event.is_action_pressed("plr_drop"):
drop()