Меню сайта
 
Форма входа
 
Мини-чат
200
[ Новые сообщения · Участники · Правила форума · Поиск · RSS ]
  • Страница 1 из 1
  • 1
Форум » Shadow Chernobyl » Уроки модостроения » Спальный мешок сталкера
Спальный мешок сталкера
zloty813Дата: Среда, 22.09.2010, 23:45 | Сообщение # 1
Стрелок
Группа: С.Т.А.Л.К.Е.Р.
Сообщений: 112
Репутация: 0
Статус: Ушёл из Зоны
1.Теория
Допустим нам надо сделать спальный мешок. Сделаем методом: если нет мешка то срабатывает определёная функция. Это будет функция меню сна. Вообщем всё. Не люблю теория перейдём к практике.

2.Мешок.
Напишем в конце файла config\misc\items.ltx вот это:

[spalniy_meshek]:identity_immunities
GroupControlSection = spawn_group
discovery_dependency =
$spawn = "food and drugs\antirad"
$prefetch = 32
class = II_ANTIR
cform = skeleton
visual = weapons\bred\bred.ogf ;в оригинале нет модели спального мешка так что пока пусть такая

модель
radius = 1
description = enc_equipment_spalniy_meshek
inv_name = spalniy_meshek
inv_name_short = spalniy_meshek
inv_weight = 1.2
inv_grid_width = 2
inv_grid_height = 2
inv_grid_x = 19
inv_grid_y = 33
cost = 0

quest_item = true

; eatable item
eat_health = 0
eat_satiety = 0
eat_power = 0
eat_radiation = 0
eat_alcohol = 0
wounds_heal_perc = 0
eat_portions_num = 1

; food item
animation_slot = 4

;hud item
hud = wpn_vodka_hud
3.Скрипты

***Создаём в папке gamedat\skripts вот такой фаил sleep.script***

function sleep()
local actor_has_meshek=db.actor:object("spalniy_meshek")
if actor_has_meshek==nil then
local spwn=ui_cheat.cheat(get_hud())
level.start_stop_menu(spwn,true)
sleep.spawn_item_in_inv("spalniy_meshek")
end
end

function spawn_item_in_inv(spawn_item,npc) --Это из амк мода
if npc==nil then
npc=db.actor
end
return alife():create(spawn_item,
npc:position(),
npc:level_vertex_id(),
npc:game_vertex_id(),
npc:id())
end

***Создаём скрипт ui_cheat***

--Половина амк половину рснр
-- инициализация
class "cheat" (CUIScriptWnd)

function cheat:__init(owner) super()
self.owner = owner
self:InitControls()
self:InitCallBacks()
end

function cheat:__finalize() end

function cheat:InitControls()
-- здесь определяем координаты левого верхнего угла и ширину-высоту
self:Init(50,50,550,450)

-- файл-описатель наших элементов
local xml = CScriptXmlInit()
xml:ParseFile("ui_cheat_wnd.xml")

-- видео на заднем плане
xml:InitStatic("back_video", self)

-- рамка
xml:InitStatic("background", self)

-- кнопки
self:Register(xml:Init3tButton("caption", self),"caption")
self:Register(xml:Init3tButton("btn_1", self),"btn_1")
self:Register(xml:Init3tButton("btn_2", self),"btn_2")
self:Register(xml:Init3tButton("btn_3", self),"btn_3")
if db.actor.health < 0.9 then
self:Register(xml:Init3tButton("btn_4", self),"btn_4")
end
-- кнопка выхода
self:Register(xml:Init3tButton("btn_quit", self),"btn_quit")
end

function cheat:InitCallBacks()
-- тут интерактивные элементы, при определенном действии выполняется заданная ф-ия
self:AddCallback("btn_1", ui_events.BUTTON_CLICKED, self.cheat1, self)
self:AddCallback("btn_2", ui_events.BUTTON_CLICKED, self.cheat2, self)
self:AddCallback("btn_3", ui_events.BUTTON_CLICKED, self.cheat3, self)
if db.actor.health < 0.9 then
self:AddCallback("btn_4", ui_events.BUTTON_CLICKED, self.cheat4, self)
end
self:AddCallback("btn_quit", ui_events.BUTTON_CLICKED, self.on_quit, self)
end

function cheat:on_quit()
self:GetHolder():start_stop_menu (self,true)
end

function cheat:OnKeyboard(dik, keyboard_action)
CUIScriptWnd.OnKeyboard(self,dik,keyboard_action)
if keyboard_action == ui_events.WINDOW_KEY_PRESSED then
-- на выход повесим Esc
if dik == DIK_keys.DIK_ESCAPE then
self:on_quit()
end
if dik == DIK_keys.DIK_NUMPAD1 then
self:cheat1()
end
if dik == DIK_keys.DIK_NUMPAD2 then
self:cheat2()
end
if dik == DIK_keys.DIK_NUMPAD3 then
self:cheat3()
end
if dik == DIK_keys.DIK_NUMPAD4 then
self:cheat4()
end
end
return true
end

function cheat:cheat1()
sleep_manager.sleep_one_hour()
self:on_quit()
end
function cheat:cheat2()
sleep_manager.sleep_three_hours()
self:on_quit()
end
function cheat:cheat3()
sleep_manager.sleep_nine_hours()
self:on_quit()
end
function cheat:cheat4()
sleep_manager.sleep_unlim(0)
self:on_quit()
end

function cheat:check_game()
-- возвращает true если запущена игра
local check = false
if level.present() and (db.actor ~= nil) and db.actor:alive() then
check = true
end
return check
end

function cheat:on_quit()
self:GetHolder():start_stop_menu (self,true)
end

***Создаём sleep_manager***
--dream mod
function sleep_one_hour()
sleep_manager.main (1)
end
function sleep_three_hours()
sleep_manager.main (3)
end
function sleep_nine_hours()
sleep_manager.main (5)
end
function sleep_unlim(scale)
local sleep_time = (1 - db.actor.health)*6
sleep_manager.main (sleep_time)
end

function main(scale)
-- get_console():execute("_main_")
local sleep_ltx = ini_file ("scripts\\actorsleep.ltx")
schemes["ar_sleep"] = "ar_sleep"
ar_sleep.set_scheme(db.actor, sleep_ltx, "ar_sleep", logic)
-- get_console():execute("_main_set_sheme")
db.actor:stop_talk()
db.actor:hide_weapon()
level.disable_input()
sleep_manager.hp_corrector(scale)
-- get_console():execute("_main_done")
sleep_manager.starter (scale)
end

function starter(scale)
local factor = scale * 2650
game.start_tutorial("time_scaling")
level.add_pp_effector("teleport.ppe", 2006, false)
level.set_time_factor(factor)
-- get_console():execute("scaling_done")
end

function dreamer()
level.set_time_factor(system_ini():r_float("alife","time_factor"))
if sleep_manager.is_sleep_active() then
sleep_manager.hp_corrector(0)
local dream = dream.sleep_video_name_callback ()
-- get_console():execute(dream)
if dream ~= "" then game.start_tutorial(dream)
else game.start_tutorial("without_dream") end
end
end

function stopper()
if not is_sleep_active() then
return
end
-- get_console():execute("stoping")
level.set_time_factor(system_ini():r_float("alife","time_factor"))
ar_sleep.disable_scheme()
if not db.actor:alive() then
--
else
db.actor:restore_weapon()
local snd_obj = xr_sound.get_safe_sound_object([[characters_voice\human_01\stalker\states\breath\breath_2]])
snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 15.0)

end
level.enable_input()
-- get_console():execute("stoped")
end

function hp_corrector(fr)
if fr ~= 0 then
hp = fr/6 + db.actor.health
if hp > 1 then hp = 1 end
return
elseif db.actor.health > hp then
db.actor.health = hp - db.actor.health
end
end

function is_sleep_active()
if db.storage[db.actor:id()].active_scheme == "ar_sleep" then
return true
end
return false
end

***Создаём в папке gamedat\skripts вот такой фаил ar_sleep.script***
--Дрим мод

class "ar_sleep" (cse_alife_creature_actor)

function ar_sleep:__init(actor, storage)
self.actor = actor
self.st = storage
end

function ar_sleep:reset_scheme()
local st = xr_logic.assign_storage_and_bind(actor, ini, scheme, section)
-- st.logic = xr_logic.cfg_get_switch_conditions(actor, section, npc)
end

function ar_sleep:update()
local ini = ini_file ("scripts\\actorsleep.ltx")
if db.storage[db.actor:id()].active_section ~= death then
_G[schemes["ar_sleep"]].set_scheme(self.actor, ini, "ar_sleep", death)
db.storage[db.actor:id()].active_section = death
db.storage[db.actor:id()].active_scheme = "ar_sleep"
end
local cond = xr_logic.cfg_get_condlist(ini, "death", "on_info", self.actor)
xr_logic.pick_section_from_condlist(self.actor, self.actor, cond.condlist)
end

function ar_sleep:death_callback(victim, who)
cse_alife_creature_actor.on_death(self, -1)
sleep_manager.stopper()
end
-------------------------------------------------------------------------------
function add_to_binder(actor, ini, scheme, section, storage)

local new_action = ar_sleep(actor, storage)

-- Регистрируем все actions, в которых будет вызван метод update()
xr_logic.subscribe_action_for_events(actor, storage, new_action)
end

function set_scheme(actor, ini, scheme, section)
local st = xr_logic.assign_storage_and_bind(actor, ini, scheme, section)
-- st.logic = xr_logic.cfg_get_switch_conditions(actor, section, npc)
db.storage[db.actor:id()].active_scheme = "ar_sleep"
-- xr_death.set_death(actor, ini, scheme, death)
end
function disable_scheme()
db.storage[db.actor:id()]["ar_sleep"] = nil
db.storage[db.actor:id()].active_scheme = nil
db.storage[db.actor:id()].active_section = nil
end
-------------------------------------------------------------------------------
***скрипт xr_detector***
--' Схема: детектор на опасную зону: граница уровня.
--' dead_zone.ppe
local start_time = 0 --'Время, с которого начинается возрастание интенсивности
local max_time = 100 --'Время, в которое интенсивность станет максимальной
local threshold = 0.2 --'Порог, с которого начинается заражение
local idle_time = 10 --'Время между хитами. В игровых секундах.
class "actor_detector"
function actor_detector:__init()
self.init_time = -1
end
function actor_detector:actor_enter()
--' Игрок покидает опасную территорию (входит в разрешенную границу уровня)
self.init_time = -1
level.remove_pp_effector(1001)
xr_sound.set_actor_sound("")

printf("LEVEL BORDER EXIT")
end
function actor_detector:actor_exit()
--' Игрок входит на опасную территорию (покидает разрешенную границу уровня)
self.init_time = game.get_game_time()

level.add_pp_effector("dead_zone.ppe", 1001, true)
level.set_pp_effector_factor(1001, 0.01)

xr_sound.set_actor_sound("level_border_detector")
xr_sound.set_actor_sound_factor(10)

self.last_update_time = game.get_game_time()

printf("LEVEL BORDER ENTER")
end
function actor_detector:update()
sleep.sleep()



if self.init_time == -1 then
return
end

if game.get_game_time():diffSec(self.last_update_time) < idle_time then
return
end
self.last_update_time = game.get_game_time()
--' В зависимости от времени нахождения игрока внутри возрастает интенсивность.
--' Интенсивность возрастает от 0 до 1. При достижении порога начинает хитовать радиация.
local intence = math.min(1,math.max(0.01,game.get_game_time():diffSec(self.init_time)/(max_time - start_time)))

level.set_pp_effector_factor(1001, intence, 0.3)
xr_sound.set_actor_sound_factor(10 - intence*9)

printf("INTENCE %s", intence)

if intence > threshold then
local h = hit()
h.draftsman = db.actor
h.type = hit.radiation
h.power = 0.05
db.actor:hit(h)
end
end
function actor_detector:save(packet)
if self.init_time == -1 then
packet:w_u8(0)
else
packet:w_u8(1)
utils.w_CTime(packet, self.init_time)
utils.w_CTime(packet, self.last_update_time)
end
end
function actor_detector:load(packet)
local flag = packet:r_u8()
if flag == 1 then
self.init_time = utils.r_CTime(packet)
self.last_update_time = utils.r_CTime(packet)
else
self.init_time = -1
end
end

Далее...


Имя: Александр
Возраст: 13 Лет
Город: Чусовой

 
zloty813Дата: Среда, 22.09.2010, 23:47 | Сообщение # 2
Стрелок
Группа: С.Т.А.Л.К.Е.Р.
Сообщений: 112
Репутация: 0
Статус: Ушёл из Зоны
Продолжаем создания спального мешка.
4.xml-описатель

В папке gamedata\config\ui создаём ui_cheat_wnd.xml файл с таким содержанием:

Code
<cheat>   
   <back_video x="10" y="10" width="380" height="320" stretch="1">
    <texture>ui\credits_back_512_v10</texture>
   </back_video>

   <background x="0" y="0" width="400" height="340" stretch="1">
    <texture x="0" y="0" width="350" height="460">ui\ui_dg_inventory</texture>
   </background>

   <caption x="175" y="30" width="50" height="35">
    <text>Сон</text>
   </caption>
     
   <btn_1 x="72" y="80" width="256" height="35">
   <texture_e>ui\ui_btn_mm_e</texture_e>
   <texture_t>ui\ui_btn_mm_t</texture_t>
   <texture_h>ui\ui_btn_mm_h</texture_h>
    <text>Спать 1 час</text>
   </btn_1>

   <btn_2 x="72" y="130" width="256" height="35">
   <texture_e>ui\ui_btn_mm_e</texture_e>
   <texture_t>ui\ui_btn_mm_t</texture_t>
   <texture_h>ui\ui_btn_mm_h</texture_h>
    <text>Спать 3 часа</text>
   </btn_2>

   <btn_3 x="72" y="180" width="256" height="35">
   <texture_e>ui\ui_btn_mm_e</texture_e>
   <texture_t>ui\ui_btn_mm_t</texture_t>
   <texture_h>ui\ui_btn_mm_h</texture_h>
    <text>Спать 5 часов</text>
   </btn_3>
     
   <btn_4 x="72" y="230" width="256" height="35">
   <texture_e>ui\ui_btn_mm_e</texture_e>
   <texture_t>ui\ui_btn_mm_t</texture_t>
   <texture_h>ui\ui_btn_mm_h</texture_h>
    <text>Спать до выздоровления</text>
   </btn_4>

<btn_quit x="270" y="300" width="117" height="29">
   <texture_e>ui_button_ordinary_e</texture_e>
   <texture_t>ui_button_ordinary_t</texture_t>
   <texture_h>ui_button_ordinary_h</texture_h>
   <text>ui_inv_exit</text>
</btn_quit>
</cheat>

Спасибо russian-stalker'у в написании скрипта


Имя: Александр
Возраст: 13 Лет
Город: Чусовой

 
Форум » Shadow Chernobyl » Уроки модостроения » Спальный мешок сталкера
  • Страница 1 из 1
  • 1
Поиск:

 
Наш опрос
Оцените мой сайт
Всего ответов: 26
 
Поиск
 
Статистика
 
Друзья