-
Notifications
You must be signed in to change notification settings - Fork 4
/
ogsr_items_anims.script
229 lines (199 loc) · 8.05 KB
/
ogsr_items_anims.script
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
local ANIMS_ENABLED = get_bool("options","animated_items", true)
local cfg = {
["eat_health"] = function(v) db.actor.health = v end,
["eat_power"] = function(v) db.actor.power = v end,
["eat_radiation"] = function(v) db.actor.radiation = v end,
["eat_satiety"] = function(v) db.actor.satiety = v end,
["eat_thirst"] = function(v) db.actor.thirst = v end,
["eat_alcohol"] = function(v) db.actor.alcohol = v end,
["eat_psy_health"] = function(v) db.actor.psy_health = v end,
["wounds_heal_perc"]= function(v) db.actor:heal_wounds( v ) end,
}
local function apply_item( sect )
if sect == "bipsizon" then
ogse_healing.use_bipsizon(sect)
return
elseif sect == "yod" then
ogse_healing.use_B190(sect)
return
elseif sect == "dix" then
ogse_healing.use_dix(sect)
return
elseif string.find(sect, "^medkit") then
if ogse_healing.slow_medicine then
ogse_healing.use_medkit(sect)
return
end
elseif sect == "kolba_zombie" then
tasks_functor.use_kolba_zombie()
return
elseif sect == "kordon_samogon" then
db.actor:give_info_portion("kordon_samogon_forsage")
elseif sect == "glassful" then
jekan_update.pervach_use()
end
for line, func in pairs( cfg ) do
local val = get_float( sect, line )
if val ~= 0 then
func(val)
end
end
if sect == "voda" then
ogse_healing.use_voda(sect)
elseif sect == "vodka" then
ogse_healing.use_vodka(sect)
end
end
local function respawn_item(obj)
obj:zero_effects()
alife():create( obj:section(), db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id() )
end
local snd_in_use = false
local function play_use_sound(sect, snd_name)
local snd = snd_name or get_string( sect, "snd_use" )
if snd then
if snd_in_use then
snd_in_use:stop()
end
snd_in_use = sound_object( snd )
snd_in_use:play( db.actor, 0, sound_object.s2d )
end
end
local function play_item_use(item)
local anim = ( string.find(item, "^bandage") and math.random() > 0.5 ) and "anm_use_alt" or "anm_use"
local item_hud = get_string(item, "hud")
local cam_effect = get_string(item, "cam_effect")
local used_time = get_u32(item, "item_used_timing")
local snd = get_string(item, "snd_use_anm")
local outfit = db.actor:item_in_slot(6)
if outfit then
if string.find(outfit:section(), "_exo") and ( string.find(item, "^medkit") or item == "antirad" ) then
item_hud = get_string(item, "hud_exo")
used_time = get_string(item, "item_used_timing_exo")
snd = get_string(item, "snd_use_exo_anm")
cam_effect = get_string(item, "cam_effect_exo")
elseif (outfit:section() == "scientific_outfit" or outfit:section() == "ecolog_outfit" or outfit:section() == "protection_outfit") and string.find(item, "^medkit") then
anim = "anm_use_alt"
end
end
if level.get_inventory_wnd():IsShown() then
level.start_stop_menu(level.get_inventory_wnd(), true)
elseif level.get_car_body_wnd():IsShown() then
level.start_stop_menu(level.get_car_body_wnd(), true)
end
level.only_allow_movekeys(true)
level.set_actor_allow_ladder(false)
local act_it = db.actor:active_item()
local act_it_slot = act_it and get_u32(act_it:section(), "slot", false) or false
local is_det_active = get_actor_obj():IsDetectorActive()
local prev_active_slot = db.actor:active_slot()
db.actor:activate_slot(255)
dsh.wait_condition(function() return not db.actor:active_item() end, function()
snd_in_use = sound_object(snd)
snd_in_use:play(db.actor, 0, sound_object.s2d)
local anm_start = time_global()
local anm_duration = game.play_hud_motion(2, item_hud, anim, true, 1, true)
level.add_cam_effector(cam_effect, 7538, false, "", 0, false)
local hud = get_hud()
local anim_hud = hud:GetCustomStatic("static_anim") or hud:AddCustomStatic("static_anim", true)
local anim_hud_wnd = anim_hud:wnd()
local xml = CScriptXmlInit()
xml:ParseFile("ui_custom_msgs.xml")
anim_hud_wnd:SetText(game.translate_string("st_item_used")..": "..game.translate_string(news_manager.get_inv_name(item)))
local anim_progress = xml:InitProgressBar("static_anim:anim_progress", anim_hud_wnd)
anim_progress:Show(true)
dsh.timeout(used_time, function()
apply_item(item)
end)
local tmr = dsh.timeout(anm_duration, function()
level.only_allow_movekeys(false)
level.set_actor_allow_ladder(true)
-- когда в руке длинное оружие и детектор одновременно, если использовать анимированный предмет (аптечку например),
-- и во время применения переключаться на бег к примеру и ещё в некоторых случаях,
-- детектор не возвращается и левая рука исчезает вообще, чтоб появилась надо убрать детектор из слота и вернуть обратно.
if is_det_active and act_it and not (act_it_slot == 0 or act_it_slot == 1 or act_it_slot == 5) then
local det = db.actor:item_in_slot(8)
if det then
db.actor:move_to_ruck(det)
db.actor:move_to_slot(det, true)
end
end
db.actor:activate_slot(prev_active_slot)
hud:RemoveCustomStatic("static_anim")
anim_progress = false
end)
dsh.wait_condition(function() return not tmr.slot_desc end, function() end, function()
if anim_progress then
anim_progress:SetProgressPos( 100 - 100 * ( ((anm_start + anm_duration) - time_global()) / anm_duration ) )
end
end)
end)
end
local function use_item_without_anim(obj, sobj, sect)
if sect == "kolba_zombie" then
if tasks_functor.can_use_kolba_zombie() then
tasks_functor.use_kolba_zombie()
else
respawn_item(obj)
end
elseif sect == "kordon_samogon" then
db.actor:give_info_portion("kordon_samogon_forsage")
elseif sect == "glassful" then
jekan_update.pervach_use()
elseif ogse_healing.on_before_use_item(obj, sobj) then
play_use_sound(sect)
else
play_use_sound(sect)
end
end
local function on_actor_before_use( obj, sobj )
local sect = obj:section()
if ANIMS_ENABLED then
if not get_string(sect, "snd_use_anm") then --лучше всего отсекать не анимационные предметы по наличию этой строки, потому что строка hud есть у многих предметов без худа почему то.
return
elseif db.actor:has_info("ui_talk") then -- Нужно для того что бы диалог не обрывался если мы решили выпить\перекусить с собеседником
use_item_without_anim(obj, sobj, sect)
elseif ogsr_actor_animation.allow_animation() then
if sect == "yod" then
if not ogse_healing.can_use_B190() then
respawn_item(obj)
return
end
elseif string.find(sect, "^medkit") then
if not ogse_healing.can_use_medkit() then
respawn_item(obj)
return
end
elseif sect == "dix" then
if not ogse_healing.can_use_dix() then
respawn_item(obj)
return
end
elseif sect == "bipsizon" then
if not ogse_healing.can_use_bipsizon() then
respawn_item(obj)
return
end
elseif sect == "kolba_zombie" then
if not tasks_functor.can_use_kolba_zombie() then
respawn_item(obj)
return
end
end
obj:zero_effects()
play_item_use(sect)
else
respawn_item(obj) --Это важно!
end
else
use_item_without_anim(obj, sobj, sect)
end
end
local function animation_off()
level.only_allow_movekeys(false)
level.set_actor_allow_ladder(true)
end
function attach( sm )
sm:subscribe({ signal = "on_actor_before_use", fun = on_actor_before_use })
sm:subscribe({ signal = "on_first_update", fun = animation_off })
end