Перейти к содержанию
Hardtmuth

Создание полоски здоровья, меняющей цвет

Рекомендуемые сообщения

 

Создание полоски здоровья, меняющей цвет

Для этого нам понадобятся стандартные файлы:

  • config/ui/maingame.xml
  • config/ui/ui_custom_msgs.xml
  • scripts/bind_stalker.script


1. Создаём файл new_hud_health.script в папке gamedata/scripts и пишем в него:

Спойлер

local hud_name = "hud_health"

-- записываем переменную
function save_variable(variable_name, value)
xr_logic.pstor_store(db.actor, variable_name, value)
end

-- загружаем переменную
function load_variable(variable_name, value_if_not_found)
return xr_logic.pstor_retrieve(db.actor, variable_name, value_if_not_found)
end

-- удаляем переменную
function del_variable(variable_name)
if db.storage[db.actor:id()].pstor[variable_name] then
db.storage[db.actor:id()].pstor[variable_name] = nil
end
end

-- координаты(параметры) x, y, width, height
local pbg = {x=0,y=0,w=0,h=0} --/ bg
local plv = {x=0,y=0,w=0,h=0} --/ lv

local skl_w = -1 --/ текущая длина шкалы
local wide = false --/ текущий режим экрана

local color = 0
local change_color = false
local change_wpn = false
local hud_show = false

function update(bShow)
local hud = get_hud()
local cs_bg = hud:GetCustomStatic("hud_health_bg")
local cs_lv = hud:GetCustomStatic("hud_health_lv")

if (load_variable("opt_hp",true) == false or bShow == false) then
if cs_bg then hud:RemoveCustomStatic("hud_health_bg") end
if cs_lv then hud:RemoveCustomStatic("hud_health_lv") end
return
save_variable("opt_hp",false)
end

local hp = db.actor.health

if (hp == nil or hp == 0) then
if hud_show == false then --/ рамку можно не стирать при смене оружия
if cs_bg then hud:RemoveCustomStatic("hud_health_bg") end
end
if cs_lv then hud:RemoveCustomStatic("hud_health_lv") end
return
end

-- проверка смены режима экрана
if wide ~= db.wide then
wide = db.wide
if cs_bg then hud:RemoveCustomStatic("hud_health_bg") end
if cs_lv then hud:RemoveCustomStatic("hud_health_lv") end
cs_bg, cs_lv = nil, nil
end

local cur_hud = "hud_health_bg"
if cs_bg == nil then
hud:AddCustomStatic(cur_hud, true)
cs_bg = hud:GetCustomStatic(cur_hud)
local wnd = cs_bg:wnd()
if wnd then
pbg = read_params(cur_hud)
wnd:SetWndPos(pbg.x,pbg.y)
wnd:SetWidth (pbg.w)
wnd:SetHeight(pbg.h)
wnd:SetAutoDelete(true)
end
end

cur_hud = "hud_health_lv"
if cs_lv == nil then
hud:AddCustomStatic(cur_hud, true)
cs_lv = hud:GetCustomStatic(cur_hud)
local wnd = cs_lv:wnd()
if wnd ~= nil then
plv = read_params(cur_hud)
wnd:SetWndPos(pbg.x+plv.x,pbg.y+plv.y)
wnd:SetWidth (skl_w)
wnd:SetHeight(plv.h)
wnd:SetAutoDelete(true)
change_color = true --/ смена цвета
end
end

if cs_lv ~= nil then
local hp_w = math.floor(hp * plv.w)
if hp_w ~= skl_w then
if hp_w < 1 then
skl_w = -1
else
skl_w = hp_w
end
end
local texture_c = get_texture(hp)
local wnd = cs_lv:wnd()
wnd:SetWidth(skl_w) --/ Set Level Condition
wnd:InitTexture(texture_c) --/ Set ColorTexture
wnd:SetText(string.format(math.floor(hp*100+0.0001)).."%")
end

end

function read_params(cur_hud)
local ltx = ini_file("scripts\\new_hud_health.ltx")
local section = cur_hud
if wide then section = section.."_wide" end
if ltx and ltx:section_exist(section) then
local p = {x=0,y=0,w=0,h=0}
local result, idx, value, i
for i=0, ltx:line_count(section)-1 do
result, idx, value = ltx:r_line(section, i, "", "")
if idx == "x" then
p.x = tonumber(value)
elseif idx == "y" then
p.y = tonumber(value)
elseif idx == "width" then
p.w = tonumber(value)
elseif idx == "height" then
p.h = tonumber(value)
end
end
return p
end
end

function get_texture(hp)
local textures = {
[0] = "ui_mg_progress_efficiency_full", --/ зеленая
[1] = "ui_hud_shk_car", --/ оранжевая
[2] = "ui_hud_shk_health" --/ красная
}
local clr = 0 --/ current color
if hp > 0.7 then clr = 0
elseif hp > 0.3 then clr = 1
elseif hp < 0.3 then clr = 2
end
if color ~= clr then
color = clr
change_color = true
else
change_color = false
end
return textures[color]
end

2. Создаём файл new_hud_health.ltx в папке gamedata/config/scripts и пишем в него:

Спойлер

[hud_health_bg]
x = 860
y = 660
width = 155
height = 34

[hud_health_lv]
x = 33
y = 5
width = 110
height = 10

[hud_health_bg_wide]
x = 900
y = 660
width = 123
height = 34

[hud_health_lv_wide]
x = 24
y = 5
width = 84
height = 10

3. В файле ui_custom_msgs.xml прописываем:

Спойлер

<hud_health_bg x="0" y="0" width="1" height="1" stretch="1" complex_mode="1">
<texture>ui_hud_shkala_health</texture>
</hud_health_bg>
<hud_health_lv x="0" y="0" stretch="1" complex_mode="1">
<texture><!-- заглушка --></texture>
<text x="85" y="0" font="arial_14" r="255" g="255" b="255" a="255" ttl="8" complex_mode="1"/>
</hud_health_lv>

 

4. Открываем файл maingame.xml и находим строчки:

Спойлер

<static_health ....>
.....
</static_health>

и


<progress_bar_health ...>
....
</progress_bar_health>

Выделяем и заменяем на следующее:


<static_health x="860" y="660" width="155" height="34">
<texture></texture>
<auto_static x="5" y="10" width="19" height="18">
<texture></texture>
</auto_static>
</static_health>
<progress_bar_health x="33" y="5" width="110" height="10" horz="1" min="0" max="100" pos="0">
<progress>
<texture></texture>
</progress>
</progress_bar_health>

 

5. Открываем файл bind_stalker.script и пишем после:

Спойлер

.....
level_tasks.add_lchanger_location()

self.bCheckStart = false
end

следующее:


new_hud_health.update()

после этой строчки должно стоять end, проверьте.

 

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

Здравствуйте 

Тестировал на ТЧ, все делал по статье, но стандартная полоска здоровья осталась, а за ней находится полоска здоровья, меняющая цвет. И при приближении бинокля или прицела винтовки, все пропадает, а полоска, меняющая цвет остается. Так же увеличилась иконка патронов и кол-во патронов, оставшихся в магазине не видно. Подскажите пожалуйста что не так?

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

Askar то, что полоса не пропадает - нужно редактировать движок, потому что показ/скрытие ОСНОВНЫХ UI элементов в игре происходит именно там. Я пробовал сделать что-то подобное и пришёл к выводу, что нужно редактировать движок. Поэтому я отказался от новых элементов.

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

xorda Разве это не внешние элементы интерфейса?

Просто насколько мне известно разрабы сделали так что игра отдельно сценарий пишется, а движок отдельно работает и вроде бы должно работать отдельно, возможно в самом уроке ошибка?

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

Для публикации сообщений создайте учётную запись или авторизуйтесь

Вы должны быть пользователем, чтобы оставить комментарий

Создать учетную запись

Зарегистрируйте новую учётную запись в нашем сообществе. Это очень просто!

Регистрация нового пользователя

Войти

Уже есть аккаунт? Войти в систему.

Войти

  • Последние посетители   0 пользователей онлайн

    Ни одного зарегистрированного пользователя не просматривает данную страницу