Все посты %s в %S - AMK Team
Перейти к контенту

Скриптование


Svoboда

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

Подскажите в чем проблема? Имею такую функцию:

Скрытый текст

function spawn_meat(victim, who)
    local meat_position = victim:position()
    local meat_direction = victim:direction()
    meat_direction = vector_rotate_y(meat_direction, math.random(-180, 180))
    meat_position.x = meat_position.x + meat_direction.x * random_float(0.5, 0.7)
    meat_position.y = meat_position.y + meat_direction.y + 1
    meat_position.z = meat_position.z + meat_direction.z * random_float(0.5, 0.7)

    local monster_meat = monster_to_meat[victim:clsid()]
    for i = 1, math.random(1,3) do
    alife():create(monster_meat, meat_position, victim:level_vertex_id(), victim:game_vertex_id())
end
end

 

Спавн itema по кругу трупа мутантов. Но они спавняться в одно стопке. в чем проблема? https://disk.yandex.ru/i/-miHtOu9MKTVhA

 

Изменено пользователем Colder

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


Ссылка на сообщение

Как правильно прочитат рандомно название оружия или где то можно подсмотреть?

Пробовал так:

Скрытый текст

local weapon_classes  = {
    [clsid.wpn_svu] = true,
    [clsid.wpn_svu_s] = true,
    [clsid.wpn_usp45] = true,
    [clsid.wpn_usp45_s] = true,
    [clsid.wpn_val] = true,
    [clsid.wpn_val_s] = true,
    [clsid.wpn_vintorez] = true,
    [clsid.wpn_vintorez_s] = true,
    [clsid.wpn_walther] = true,
    [clsid.wpn_walther_s] = true
}

function irWeapon(object, class_id)
    local id = class_id or get_clsid(object)
    return id and weapon_classes[id]
end

function show_news()
    if irWeapon(item) then
    local name = system_ini():r_string(item:section(), "inv_name")
    local n = name[math.random(#name)]
    local ww = gts(n)

    local news_text = "%c[ui_gray_1]".. ww
    db.actor:give_game_news(news_text, "ui\\cop\\ui_cop_iconstotal", Frect():set(415,0,83,47), 0, 5000)
end
end

но ничего не приходит.

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


Ссылка на сообщение

@WinCap повесил на on_trade(item, sell_bye, money)

Изменено пользователем Colder

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


Ссылка на сообщение

@Kirgudu 

Скрытый текст

local gts = game.translate_string

local weapon_classes  = {
    [clsid.wpn_svu] = true,
    [clsid.wpn_svu_s] = true,
    [clsid.wpn_usp45] = true,
    [clsid.wpn_usp45_s] = true,
    [clsid.wpn_val] = true,
    [clsid.wpn_val_s] = true,
    [clsid.wpn_vintorez] = true,
    [clsid.wpn_vintorez_s] = true,
    [clsid.wpn_walther] = true,
    [clsid.wpn_walther_s] = true
}

function irWeapon(object, class_id)
    local id = class_id or get_clsid(object)
    return id and weapon_classes[id]
end

 

function show_news(item)
    if irWeapon(item) then
    local name = system_ini():r_string(item:section(), "inv_name")
    local n = name[math.random(#name)]
    local ww = gts(n)

    local news_text = "%c[ui_gray_1]".. ww
    db.actor:give_game_news(news_text, "ui\\cop\\ui_cop_iconstotal", Frect():set(415,0,83,47), 0, 5000)
end
end

 

Вызываю с ui_main_menu по кнопке

 

Можно было сделать так :

 

Скрытый текст

function show_news()
    local where_trade = txr_utils.collect_translations("st_dyn_news_lvl_",true)
    if (not where_trade) then
    return false
end
    local wt = where_trade[math.random(#where_trade)]
    local news_text = "%c[ui_gray_1]".. wt
    db.actor:give_game_news(news_text, "ui\\cop\\ui_cop_iconstotal", Frect():set(415,0,83,47), 0, 5000)
end

 

txr_utils:

 

local cache_translated = {}
local cache_untranslated = {}
local string_find = string.find

 

function collect_translations(st, is_translated)
    if is_translated and cache_translated[st] then
    return cache_translated[st]
    elseif cache_untranslated[st] then
    return cache_untranslated[st]
end
    local string_count = 1
    local tr_t = {}
    while true do 
    local tr_s = game.translate_string(st .. string_count)
    if (tr_s == st .. string_count) then
    break
    else
    if is_translated then
    tr_t[#tr_t + 1] = tr_s
    else
    tr_t[#tr_t + 1] = st .. tostring(string_count)
end
end
    string_count = string_count + 1
end
    if (#tr_t == 0) then
    if (not string_find(st,"st_msg")) then
    printf("! WARNING: collect_translations | strings of (%s) don't exist!", st)
end
    return false
end
    if is_translated then
    cache_translated[st] = tr_t
    else
    cache_untranslated[st] = tr_t
end
    return tr_t
end

 

Но это не решает проблему, ведь он будет читать строку в виде ...._1, ..._2 и т.д. А мне нужны имена оружий.

 

Ну не писать же длинющий список:

 

local where_trade = {
    "ПМ",
    "ПБ",
    и т.д
}

Я так понимаю это не реализовать?

 

Изменено пользователем Colder

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


Ссылка на сообщение

@Kirgudu 

7 минут назад, Kirgudu сказал:

Вообще любого в игре?

Именно

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


Ссылка на сообщение

Всем привет!

Имею такой код:

Скрытый текст

function actor_on_update(status)
    local tm = task_manager.get_random_task()
    local active = tm.active_task_by_type
    for k, task_id in pairs(active) do
    local task_status = tm.task_info[task_id].status
        if task_status == "completed" then --// Если завершили таск
            ----
        end
    end
end

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

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


Ссылка на сообщение

Всем привет. Хочу выдать инфопорцию при сдачи второстепенных квестов. Делаю так:

Скрытый текст

В task_manager.script пишу:

 

в function CRandomTask:__init()

self.reward_info = utils.cfg_get_string(self.task_ini, id, "reward_info", nil, false, "")

 

в function CRandomTask:init_reward_dialog(dlg, parent)

    if self.reward_info ~= nil then
    phrase_script:AddGiveInfo(self.reward_info)
end

 

Соответственно в ltx:

reward_info = инфопорция

 

Но ничего не происходит. Что я пишу не так?

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


Ссылка на сообщение

Помогите установить метку

Скрытый текст

function random_anom_spawn()
    local section = anom[math.random(table.getn(anom))]
    local lv = math.random(level_vertexes[level.name()]["lvid"])
    local gv = level_vertexes[level.name()]["gvid"]
    for i = 1, count do
    create_anom(section, level.vertex_position(lv), lv, gv, 1.5, 1.0)
    level.map_add_object_spot_ser(section.id, "zone_zdn_mapspot", gts("st_ui_pda_legend_special"))
end
end

Но метка ставится на гг

 

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


Ссылка на сообщение
Скрытый текст

local t = 0
local BACKPACK_SLOT = 8

 

function ItTank(obj)
    if not obj then return false end
    local list = {

    ["airtank"] = true,
}
    return list[obj:section()]
end

 

local toxic_level = ini_file([[items\settings\txr_toxic_level.ltx]]):r_float("hit_level", level.name())
local min_cond = sys_ini:r_float_ex("airtank", "inv_condition")

 

function item_to_tank()
    local slot = db.actor:item_in_slot(BACKPACK_SLOT)

    local function list(actor,obj)
    if slot and ItTank(obj) then
    if t < time_global() then

    local cond = obj:condition()
    obj:set_condition(cond-min_cond)
    db.actor.health = toxic_level+0.001
    t = time_global() + 1000
end
end
end
    db.actor:iterate_inventory(list,db.actor)
end

  • Всем привет.
  • У меня такая проблема если вставить в слот airtank, потом вытащить его и поставить другой. То хит наноситься всё равно 1 airtank который стоял до этого в слоте. Я так понимаю нужно присвоить ид предмету? Как мне это сделать?
Изменено пользователем Colder

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


Ссылка на сообщение

Всем привет. Создал спальник который при использовании спавнит, матрас к гг под ноги и компресионый мешок в инвентарь. Возникла проблема что при использовании компресионого мешка на НЕ разрешеной дистанции компресионый мешок не спавнится обратно к гг.

Скрытый текст

local spawned_sleepbags = {}
local dist = 1.5

function on_item_sleep(obj)
    if obj:section() == "sleep_bag" then                    -- спальный мешок
    alife():create("compression_bag", pos, lvid, gvid, pid)            -- спавним компресионый мешок гг

    pos.x = pos.x + 1
    pos.z = pos.z + 0

    local matt = alife():create("mattress", pos, lvid, gvid)        -- спавним матрас
    spawned_sleepbags[matt.id] = true

    elseif obj:section() == "compression_bag" then

    for id, v in pairs(spawned_sleepbags) do
    local sp = level.object_by_id(id)
    if sp and (v == true) then

    local sp_distance = sp:position():distance_to(db.actor:position())
    if (sp_distance < dist) then

    alife():release(alife():object(sp:id()), true)                -- удаляем матрас и спавним мешок обратно
    alife():create("sleep_bag", pos, lvid, gvid, pid)

    local bag = db.actor:object("compression_bag")                -- удаляем компресионый мешок у гг
    alife():release(alife():object(bag:id()), true)
    spawned_sleepbags[id] = nil
    break
end
end
end
end
end

 

Изменено пользователем Colder

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


Ссылка на сообщение

Я пробывал спавнить гг но он спавниться каждым действием при использовании 

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


Ссылка на сообщение

@naxac когда в рюкзаке 2 спальника, то компрессионый мешок все равно спавниться постоянно 

Изменено пользователем Colder
  • Согласен 1

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


Ссылка на сообщение

Подскажите как правильно прочитать строку из ltx файла ввиде:

[item]
item_1

item_2

item_3

item_4

...

...

Скрытый текст

пробовал так:

 

function ..... ()

    local spawn = {}
    local ini_pack = ini_file("items\\settings\\txr_list.ltx")

    local need = ini_pack:line_count("item")
    spawn.section = need[math.random(table.getn(need))]

 

Ругаеться на getn.

P.S Мне нужно выбрать 1 из предметов.

Заранее спасибо!

 

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


Ссылка на сообщение

Подскажите что делаю не так? Пытаюсь вывести вес в ящике. Когда выкладываешь/берешь все работает. Закрываешь/открываешь ящик вес сбрасываеться по 0.

Скрытый текст


local box_info_wnd
local cur_box_weight = 0

function init(obj)
    printf("_bp: init(): name='%s'", obj:name())
    local ini = obj:spawn_ini()
    if ini and ini:section_exist("animation") then
    abort("object '%s': animation section is deprecated, use logic + impulse combination", obj:name())
    return
end
    if (not ini) or (not ini:section_exist("logic") and not ini:section_exist("drop_box")) then
    if obj:clsid() ~= clsid.projector and obj:clsid() ~= clsid.inventory_box then
    return
end
end
    db.storage[obj:id()] = {}
    local new_binder = generic_physics_binder(obj)
    obj:bind_object(new_binder)
end

class "generic_physics_binder" (object_binder)
function generic_physics_binder:__init(obj) super(obj)
    self.initialized = false
    self.loaded = false
end 

function generic_physics_binder:reload(section)
    object_binder.reload(self, section)
end

function generic_physics_binder:reinit()
    object_binder.reinit(self)
    db.storage[self.object:id()] = {}
    self.st = db.storage[self.object:id()]
end

function generic_physics_binder:update(delta)
    object_binder.update(self, delta)

    if not self.initialized and db.actor then
    self.initialized = true
    xr_logic.initialize_obj(self.object, self.st, self.loaded, db.actor, modules.stype_item)

    local particle = utils.cfg_get_string(self.st.ini, self.st.section_logic, "particle", self.object, false, "", nil)
    if particle ~= nil then
    self.particle = particles_object(particle)
    self.particle:play_at_pos(self.object:position())
end
    local graph_point_marker = utils.cfg_get_string(self.st.ini, self.st.section_logic, "graph_point_marker", self.object, false, "", nil)
    if graph_point_marker ~= nil then
    self.disable_graph_point = patrol(graph_point_marker):game_vertex_id(0)
    game_graph():accessible(self.disable_graph_point, false)
    printf("GRAPH POINT DISABLED")
end
    self.cur_box_weight = get_box_weight(self.object)
end
    if self.st.active_section ~= nil or (self.object:spawn_ini() ~= nil and self.object:spawn_ini():section_exist("drop_box") == true) or self.object:clsid() == clsid.inventory_box then
    xr_logic.issue_event(self.object, self.st[self.st.active_scheme], "update", delta)

    self.object:set_callback(callback.hit, generic_physics_binder.hit_callback, self)
    self.object:set_callback(callback.death, generic_physics_binder.death_callback, self)
    self.object:set_callback(callback.use_object, generic_physics_binder.use_callback, self)
    elseif self.object:section() == "inventory_box" or self.object:section() == "active_backpack" or self.object:section() == "active_system" then
    self.object:set_callback(callback.use_object, generic_physics_binder.use_callback, self)
end
end

function generic_physics_binder:net_spawn(data)
    if not object_binder.net_spawn(self, data) then
    return false
end
    if self.object:clsid() == clsid.projector then
    db.add_sl(self.object)
end
    if self.object:spawn_ini() ~= nil and self.object:spawn_ini():section_exist("drop_box") == true then
    self.box_items = xr_box.ph_item_box(self.object)
end
    self.object:set_callback(callback.on_inv_box_item_take, self.on_put, self)
    self.object:set_callback(callback.on_inv_box_item_drop, self.on_drop, self)
    return true
end

function generic_physics_binder:net_destroy()
    local st = db.storage[self.object:id()]
    if st.active_scheme then
    xr_logic.issue_event(self.object, st[st.active_scheme], "net_destroy")
end
    if self.particle ~= nil then
    self.particle:stop()
end
    db.del_sl(self.object)
    db.storage[self.object:id()] = nil

    self.object:set_callback(callback.on_inv_box_item_take, nil)
    self.object:set_callback(callback.on_inv_box_item_drop, nil)

    object_binder.net_destroy(self)
end

function generic_physics_binder:on_put(item)
    local wnd = level.get_car_body_wnd()
    if not wnd:IsShown() or db.actor:is_talking() then
    return
end
    self.cur_box_weight = get_box_weight(self.object)
    if box_info_wnd then
    box_info_wnd:update_info(self.cur_box_weight)
end
end

function generic_physics_binder:on_drop(item)
    local wnd = level.get_car_body_wnd()
    if not wnd:IsShown() or db.actor:is_talking() then
    return
end
    self.cur_box_weight = get_box_weight(self.object)
    if box_info_wnd then
    box_info_wnd:update_info(self.cur_box_weight)
end
end

function generic_physics_binder:net_save_relevant()
    return true
end

function generic_physics_binder:save(packet)
    object_binder.save(self, packet)
    xr_logic.save_obj(self.object, packet)
end

function generic_physics_binder:load(reader)
    self.loaded = true
    object_binder.load(self, reader)
    xr_logic.load_obj(self.object, reader)
end

function generic_physics_binder:use_callback(obj, who)
    if obj:section() == "inventory_box" or obj:section() == "active_backpack" or obj:section() == "active_system" then
    dxr_carbody.use_inventory_box = obj
end
    if self.st.active_section then
    xr_logic.issue_event(self.object, self.st[self.st.active_scheme], "use_callback", obj, who)
end
end

function generic_physics_binder:hit_callback(obj, amount, local_direction, who, bone_index)
    printf("_bp: generic_physics_binder:hit_callback: obj='%s'", obj:name())
    if self.st.ph_on_hit then
    xr_logic.issue_event(self.object, self.st.ph_on_hit, "hit_callback", obj, amount, local_direction, who, bone_index)
end
    if self.st.active_section then
    xr_logic.issue_event(self.object, self.st[self.st.active_scheme], "hit_callback", obj, amount, local_direction, who, bone_index)
end
end

function generic_physics_binder:death_callback(victim, who)
--    printf("_bp: generic_physics_binder:death_callback: obj='%s'", victim:name())
    printf("_bp: generic_physics_binder:death_callback: obj='%s'", victim and victim:name() or self.object:name())
    if self.st.active_section then
    xr_logic.issue_event(self.object, self.st[self.st.active_scheme], "death_callback", victim, who)
end
    if self.particle ~= nil then
        self.particle:stop()
end
    if self.disable_graph_point ~= nil then
    game_graph():accessible(self.disable_graph_point, true)
    printf("GRAPH POINT ENABLED")
end
    if self.object:spawn_ini() ~= nil and self.object:spawn_ini():section_exist("drop_box") == true then
    self.box_items:spawn_items()
end
end

---------------------------------------------------------------------------------------------------
function get_box_weight(box)
    if box == nil then
    return 0
end
    local weight = 0.0
    for i=0,box:inv_box_count()-1 do
    weight = weight + box:object_from_inv_box(i):get_weight() or 0
end
    return weight
end

function show_box_info()
    box_info_wnd = box_info_wnd or box_info()

    if box_info_wnd ~= nil then
    box_info_wnd:show()
end
end

function hide_box_info()
    if box_info_wnd then
    get_hud():RemoveDialogToRender(box_info_wnd)
end
    box_info_wnd = nil
end

class "box_info" (CUIScriptWnd)

function box_info:__init() super()
    local xml = CScriptXmlInit()
    xml:ParseFile("carbody_new.xml")
    xml:InitWindow("main", 0, self)
    self.weight = xml:InitStatic("weight_static", self)
    get_hud():AddDialogToRender(self)
end
    
function box_info:show()
    self:update_info(self.cur_box_weight)
    self:Show(true)
end

function box_info:hide()
    self:Show(false)
end

function box_info:update_info(cur)
    if cur ~= nil then
    self.weight:SetText(string.format("%5.1f",cur))
    else
    self.weight:SetText(string.format("%5.1f",0))
end
end
 

 

Изменено пользователем Colder

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


Ссылка на сообщение

Пробывал добавить на апдейт

Скрытый текст

    if self.object:clsid() == clsid.inventory_box and box_info_wnd ~= nil then
            box_info_wnd:hide()
        else
            box_info_wnd:show()
        end

Но не сработало

  • Жуть! 1

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


Ссылка на сообщение

@Zander_driver  Сделал так:

Скрытый текст

local box_info_wnd

function init(obj)
    printf("_bp: init(): name='%s'", obj:name())
    local ini = obj:spawn_ini()
    if ini and ini:section_exist("animation") then
    abort("object '%s': animation section is deprecated, use logic + impulse combination", obj:name())
    return
end
    if (not ini) or (not ini:section_exist("logic") and not ini:section_exist("drop_box")) then
    if obj:clsid() ~= clsid.projector and obj:clsid() ~= clsid.inventory_box then
    return
end
end
    db.storage[obj:id()] = {}
    local new_binder = generic_physics_binder(obj)
    obj:bind_object(new_binder)
end

class "generic_physics_binder" (object_binder)
function generic_physics_binder:__init(obj) super(obj)
    self.initialized = false
    self.loaded = false
end 

function generic_physics_binder:reload(section)
    object_binder.reload(self, section)
end

function generic_physics_binder:reinit()
    object_binder.reinit(self)
    db.storage[self.object:id()] = {}
    self.st = db.storage[self.object:id()]
end

function generic_physics_binder:update(delta)
    object_binder.update(self, delta)

    if not self.initialized and db.actor then
    self.initialized = true
    xr_logic.initialize_obj(self.object, self.st, self.loaded, db.actor, modules.stype_item)

    local particle = utils.cfg_get_string(self.st.ini, self.st.section_logic, "particle", self.object, false, "", nil)
    if particle ~= nil then
    self.particle = particles_object(particle)
    self.particle:play_at_pos(self.object:position())
end
    local graph_point_marker = utils.cfg_get_string(self.st.ini, self.st.section_logic, "graph_point_marker", self.object, false, "", nil)
    if graph_point_marker ~= nil then
    self.disable_graph_point = patrol(graph_point_marker):game_vertex_id(0)
    game_graph():accessible(self.disable_graph_point, false)
    printf("GRAPH POINT DISABLED")
end
end
    if self.st.active_section ~= nil or (self.object:spawn_ini() ~= nil and self.object:spawn_ini():section_exist("drop_box") == true) or self.object:clsid() == clsid.inventory_box then
    xr_logic.issue_event(self.object, self.st[self.st.active_scheme], "update", delta)

    self.object:set_callback(callback.hit, generic_physics_binder.hit_callback, self)
    self.object:set_callback(callback.death, generic_physics_binder.death_callback, self)
    self.object:set_callback(callback.use_object, generic_physics_binder.use_callback, self)

    elseif self.object:section() == "inventory_box" or self.object:section() == "active_backpack" or self.object:section() == "active_system" then
    self.object:set_callback(callback.use_object, generic_physics_binder.use_callback, self)
end
    local weight = 0
    for i=0,self.object:inv_box_count()-1 do
    weight = weight + self.object:object_from_inv_box(i):get_weight()
    if box_info_wnd then
    box_info_wnd:update_info(weight)
end
end
end

function generic_physics_binder:net_spawn(data)
    if not object_binder.net_spawn(self, data) then
    return false
end
    if self.object:clsid() == clsid.projector then
    db.add_sl(self.object)
end
    if self.object:spawn_ini() ~= nil and self.object:spawn_ini():section_exist("drop_box") == true then
    self.box_items = xr_box.ph_item_box(self.object)
end
    self.object:set_callback(callback.on_inv_box_item_take, self.on_take, self)
    self.object:set_callback(callback.on_inv_box_item_drop, self.on_drop, self)

    return true
end

function generic_physics_binder:net_destroy()
    local st = db.storage[self.object:id()]
    if st.active_scheme then
    xr_logic.issue_event(self.object, st[st.active_scheme], "net_destroy")
end
    if self.particle ~= nil then
    self.particle:stop()
end
    db.del_sl(self.object)
    db.storage[self.object:id()] = nil

    self.object:set_callback(callback.on_inv_box_item_take, nil)
    self.object:set_callback(callback.on_inv_box_item_drop, nil)

    object_binder.net_destroy(self)
end

function generic_physics_binder:on_take(item)
    self.cur_box_weight = get_box_weight(self.object)
    if box_info_wnd then
    box_info_wnd:update_info(self.cur_box_weight)
end
end

function generic_physics_binder:on_drop(item)
    self.cur_box_weight = get_box_weight(self.object)
    if box_info_wnd then
    box_info_wnd:update_info(self.cur_box_weight)
end
end

function generic_physics_binder:net_save_relevant()
    return true
end

function generic_physics_binder:save(packet)
    object_binder.save(self, packet)
    xr_logic.save_obj(self.object, packet)
end

function generic_physics_binder:load(reader)
    self.loaded = true
    object_binder.load(self, reader)
    xr_logic.load_obj(self.object, reader)
end

function generic_physics_binder:use_callback(obj, who)
    if obj:section() == "inventory_box" or obj:section() == "active_backpack" or obj:section() == "active_system" then
    dxr_carbody.use_inventory_box = obj
end
    if self.st.active_section then
    xr_logic.issue_event(self.object, self.st[self.st.active_scheme], "use_callback", obj, who)
end
end

function generic_physics_binder:hit_callback(obj, amount, local_direction, who, bone_index)
    printf("_bp: generic_physics_binder:hit_callback: obj='%s'", obj:name())
    if self.st.ph_on_hit then
    xr_logic.issue_event(self.object, self.st.ph_on_hit, "hit_callback", obj, amount, local_direction, who, bone_index)
end
    if self.st.active_section then
    xr_logic.issue_event(self.object, self.st[self.st.active_scheme], "hit_callback", obj, amount, local_direction, who, bone_index)
end
end

function generic_physics_binder:death_callback(victim, who)
    printf("_bp: generic_physics_binder:death_callback: obj='%s'", victim and victim:name() or self.object:name())
    if self.st.active_section then
    xr_logic.issue_event(self.object, self.st[self.st.active_scheme], "death_callback", victim, who)
end
    if self.particle ~= nil then
        self.particle:stop()
end
    if self.disable_graph_point ~= nil then
    game_graph():accessible(self.disable_graph_point, true)
    printf("GRAPH POINT ENABLED")
end
    if self.object:spawn_ini() ~= nil and self.object:spawn_ini():section_exist("drop_box") == true then
    self.box_items:spawn_items()
end
end

---------------------------------------------------------------------------------------------------
function get_box_weight(box)
    if box == nil then return end
    local weight = 0
    for i=0,box:inv_box_count()-1 do
    weight = weight + box:object_from_inv_box(i):get_weight()
end
    return weight
end

function show_box_info()
    box_info_wnd = box_info_wnd or box_info()
    if box_info_wnd ~= nil then
    box_info_wnd:show()
end
end

function hide_box_info()
    if box_info_wnd then
    get_hud():RemoveDialogToRender(box_info_wnd)
end
    box_info_wnd = nil
end

class "box_info" (CUIScriptWnd)

function box_info:__init() super()
    local xml = CScriptXmlInit()
    xml:ParseFile("carbody_new.xml")
    self.weight = xml:InitStatic("weight_static", self)
    get_hud():AddDialogToRender(self)
end
    
function box_info:show()
    box_info_wnd:update_info(self.cur_box_weight)
    self:Show(true)
end

function box_info:hide()
    self:Show(false)
end

function box_info:update_info(cur)
    if cur ~= nil then
    self.weight:SetText(string.format("%5.1f",cur))
    else
    self.weight:SetText(string.format("%5.1f",0))
end
end

function on_info(info_id)
    if info_id == "ui_car_body_hide" then
    hide_box_info()
end
    if info_id == "ui_car_body" then
    show_box_info()
end
end
 

Но теперь при получении тайника(появления итемов в ящике) цифры начинают бегать.

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


Ссылка на сообщение

Подскажите как выбрать один предмет а не все при парсинге

Скрытый текст

    local sec = self.items[index + 1]
    local parts = ini_parts:r_string_ex("con_list", sec)
    parts = string.gsub(parts,"[,]"," ")

    for k, v in string.gmatch(parts, "[%p0-z]+") do
    sim:create(k, pos, lvid, gvid, pid)

 

 

Изменено пользователем Colder

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


Ссылка на сообщение

 

Сделал так:

Скрытый текст

    local parts = ini_parts:r_string_ex("con_parts_list", sec)
    if parts then
    local parts_tbl = str_explode(parts,",")
    local t = parts_tbl[math.random(#parts_tbl)]

    sim:create(t, pos, lvid, gvid, pid)

 

А еще вопрос, если мне нужно пару итемов?

Изменено пользователем Colder

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


Ссылка на сообщение
  • Недавно просматривали   0 пользователей

    • Ни один зарегистрированный пользователь не просматривает эту страницу.
×
×
  • Создать...