rangedweapons/cooldown_stuff.lua

103 lines
3.1 KiB
Lua
Raw Permalink Normal View History

2022-01-22 19:21:21 +01:00
minetest.register_globalstep(function(dtime, player)
for _, player in pairs(minetest.get_connected_players()) do
local w_item = player:get_wielded_item()
local controls = player:get_player_control()
if w_item:get_definition().weapon_zoom ~= nil then
if controls.zoom then
player:hud_change(scope_hud, "text", "rangedweapons_scopehud.png")
else
player:hud_change(scope_hud, "text", "rangedweapons_empty_icon.png")
end
local wpn_zoom = w_item:get_definition().weapon_zoom
if player:get_properties().zoom_fov ~= wpn_zoom then
player:set_properties({zoom_fov = wpn_zoom})
end
end
if w_item:get_definition().weapon_zoom == nil then
2022-03-05 06:06:22 +01:00
player:hud_change(scope_hud, "text", "rangedweapons_empty_icon.png")
2022-01-22 19:21:21 +01:00
if player:get_inventory():contains_item(
"main", "binoculars:binoculars") then
2022-03-05 06:06:22 +01:00
local new_zoom_fov = 10
if player:get_properties().zoom_fov ~= new_zoom_fov then
player:set_properties({zoom_fov = new_zoom_fov})
end
2022-01-22 19:21:21 +01:00
else
2022-03-05 06:06:22 +01:00
local new_zoom_fov = 0
if player:get_properties().zoom_fov ~= new_zoom_fov then
player:set_properties({zoom_fov = new_zoom_fov})
end
2022-01-22 19:21:21 +01:00
end
end
local u_meta = player:get_meta()
local cool_down = u_meta:get_float("rw_cooldown") or 0
if u_meta:get_float("rw_cooldown") > 0 then
u_meta:set_float("rw_cooldown", cool_down - dtime)
end
local itemstack = player:get_wielded_item()
if controls.LMB then
if player:get_wielded_item():get_definition().RW_gun_capabilities then
if
player:get_wielded_item():get_definition().RW_gun_capabilities.automatic_gun and player:get_wielded_item():get_definition().RW_gun_capabilities.automatic_gun > 0 then
rangedweapons_shoot_gun(itemstack, player)
player:set_wielded_item(itemstack)
end end
if player:get_wielded_item():get_definition().RW_powergun_capabilities then
if player:get_wielded_item():get_definition().RW_powergun_capabilities.automatic_gun and player:get_wielded_item():get_definition().RW_powergun_capabilities.automatic_gun > 0 then
rangedweapons_shoot_powergun(itemstack, player)
player:set_wielded_item(itemstack)
end end
end
--minetest.chat_send_all(u_meta:get_float("rw_cooldown"))
if u_meta:get_float("rw_cooldown") <= 0 then
if player:get_wielded_item():get_definition().loaded_gun ~= nil then
local itemstack = player:get_wielded_item()
if player:get_wielded_item():get_definition().loaded_sound ~= nil then
2022-02-11 21:41:08 +01:00
minetest.sound_play(itemstack:get_definition().loaded_sound, {pos = player:get_pos()})
2022-01-22 19:21:21 +01:00
end
itemstack:set_name(player:get_wielded_item():get_definition().loaded_gun)
player:set_wielded_item(itemstack)
end
if player:get_wielded_item():get_definition().rw_next_reload ~= nil then
local itemstack = player:get_wielded_item()
if itemstack:get_definition().load_sound ~= nil then
2022-02-11 21:41:08 +01:00
minetest.sound_play(itemstack:get_definition().load_sound, {pos = player:get_pos()})
2022-01-22 19:21:21 +01:00
end
2022-03-05 06:06:22 +01:00
local gunMeta = itemstack:get_meta()
2022-01-22 19:21:21 +01:00
u_meta:set_float("rw_cooldown",gunMeta:get_float("RW_reload_delay"))
itemstack:set_name(player:get_wielded_item():get_definition().rw_next_reload)
player:set_wielded_item(itemstack)
end
end
end end)