Jump to content

Tworzenie paska zdrowia zmieniającego kolor


Recommended Posts

NAZWA: Tworzenie paska zdrowia zmieniającego kolor
AUTOR: ?

 

POTRZEBNE PLIKI:

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

 

OPERACJE NA PLIKACH:

Spoiler

1. NEW_HUD_HEALTH.SCRIPT (NOWY PLIK):

Spoiler

Tworzymy plik new_hud_health.script w folderze gamedata\scripts. Piszemy w nim:

local hud_name = "hud_health"

-- zapisujemy zmienną
function save_variable(variable_name, value)
xr_logic.pstor_store(db.actor, variable_name, value)
end

-- wczytujemy zmienną
function load_variable(variable_name, value_if_not_found)
return xr_logic.pstor_retrieve(db.actor, variable_name, value_if_not_found)
end

-- usuwamy zmienną
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

-- współrzędne(parametry) 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 --/ aktualna długość skali
local wide = false --/ aktualny tryb ekranu

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 --/ ramki nie można usunąć podczas zmiany broni
if cs_bg then hud:RemoveCustomStatic("hud_health_bg") end
end
if cs_lv then hud:RemoveCustomStatic("hud_health_lv") end
return
end

-- sprawdzanie zmiany trybu ekranu
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 --/ zmiana koloru
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", --/ zielony
[1] = "ui_hud_shk_car", --/ pomarańczowy
[2] = "ui_hud_shk_health" --/ czerwony
}
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 (NOWY PLIK):

Spoiler

Tworzymy plik new_hud_health.ltx w folderze gamedata\configs\scripts. Piszemy w nim:

[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:

Spoiler

Do pliku ui_custom_msgs.xml dopisujemy:

<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><!-- zaślepka --></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:

Spoiler

Otwieramy plik maingame.xml i szukamy linijek:

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

i takiej:

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

Wydzielamy i zamieniamy na następujące:

<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:

Spoiler

Otwieramy plik bind_stalker.script i szukamy linijek:

.....
level_tasks.add_lchanger_location()

self.bCheckStart = false
end

i piszemy po nich:

new_hud_health.update()

Po tej linijce powinno być end, sprawdźcie czy jest.

 

 

ŹRÓDŁO:

https://ap-pro.ru/forums/topic/1188-sozdanie-poloski-zdorovya-menyayushtey-cvet/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.