Создание полоски здоровья, меняющей цвет - Сталкерский Форум
[ Главная страница | Новые сообщения | Участники | Поиск | RSS ]
  • Страница 1 из 1
  • 1
Модератор форума: Леголас  
Создание полоски здоровья, меняющей цвет
ЛеголасДата: Суббота, 26.05.2012, 18:39 | Сообщение # 1
Лидер Бандитов
Группа: Администратор
Сообщений: 21
Репутация: 3
Статус: Offline
Создание полоски здоровья, меняющей цвет
Автор: Xmk, на основе полоски оружия из Симбиона
Сложность: Среднея

Для этого нам понадобятся стандартные файлы:
config/ui/maingame.xml
config/ui/ui_custom_msgs.xml
scripts/bind_stalker.script


Инструкция:

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

Code
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 и пишем в него:

Code
[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прописываем:

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

находим строчки:

.....

и

....

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

Code
<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 и пишем после:

Code

.....
      level_tasks.add_lchanger_location()

      self.bCheckStart = false          
end

следущее:
new_hud_health.update()


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

-----------
Вроде все, если что пишите что неправильно поправлю. smile


Я - Леголас. Эльф лесного королевства.
 
STALKER-SMASHДата: Пятница, 24.08.2012, 18:46 | Сообщение # 2
Сержант
Группа: Вольный сталкер
Сообщений: 26
Репутация: 1
Статус: Offline
Леголас, любопытненько!
 
  • Страница 1 из 1
  • 1
Поиск:
Хостинг от uCoz | Дизайн выполнен художником