forked from lhofhansl/rangedweapons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cooldown_stuff.lua
102 lines (71 loc) · 3.04 KB
/
cooldown_stuff.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
rangedweapons_set_hud(player, "scopehud",true)
else
rangedweapons_set_hud(player, "scopehud",false)
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
rangedweapons_set_hud(player, "scopehud",false)
if player:get_inventory():contains_item(
"main", "binoculars:binoculars") then
local new_zoom_fov = 10
if player:get_properties().zoom_fov ~= new_zoom_fov then
player:set_properties({zoom_fov = new_zoom_fov})
end
else
local new_zoom_fov = 0
if player:get_properties().zoom_fov ~= new_zoom_fov then
player:set_properties({zoom_fov = new_zoom_fov})
end
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
minetest.sound_play(itemstack:get_definition().loaded_sound, {pos = player:get_pos()}, true)
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
minetest.sound_play(itemstack:get_definition().load_sound, {pos = player:get_pos()}, true)
end
local gunMeta = itemstack:get_meta()
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)