Сповіщення
Очистити все

Функція купівля зброї та броні через діалог


NazarTmm
Ранг:
Досвідчений
Роль:
Модмейкер
Угруповання:
Бандити
Записи:
35
Приєднався:
10 місяців тому
Початок теми  

У цьому уроці ми будемо робити функцію купівлі зброї та броні через діалог. Я буду робити це на своїй локації.
Перше, що нам знадобиться, це dialogs_локація.scripts
Див. скріншот.

image

Пропишемо ось таку функцію:
-Виведення іконок і тексту в діалозі:

function give_message_proposed_items(first_speaker, second_speaker)      

                  db.actor:give_talk_message2("Броня:", "Комбінезон СЕВА", "ui_inGame2_Orujie","iconed_answer_item")

                  db.actor:give_talk_message2("Оружие:", "АС ВАЛ", "ui_inGame2_Orujie","iconed_answer_item")

                  db.actor:give_talk_message2("Броня:", "Єкзоскелет", "ui_inGame2_Orujie","iconed_answer_item")

end

-Видача предметів і відбирання грошей:

function trader_seva(first_speaker, second_speaker)

dialogs.relocate_item_section(second_speaker, "scientific_outfit", "in")

   dialogs.relocate_money_from_actor(first_speaker, second_speaker, 30000)

end

function trader_val(first_speaker, second_speaker)

dialogs.relocate_item_section(second_speaker, "wpn_val", "in")

   dialogs.relocate_money_from_actor(first_speaker, second_speaker, 25000)

end

function trader_exo(first_speaker, second_speaker)

dialogs.relocate_item_section(second_speaker, "exo_outfit", "in")

   dialogs.relocate_money_from_actor(first_speaker, second_speaker, 50000)

end

-Перевірка на наявність грошей:

function trader_seva_money(first_speaker, second_speaker)

return first_speaker:money() >= 30000

end

function trader_val_money(first_speaker, second_speaker)

return first_speaker:money() >= 25000

end

function trader_exo_money(first_speaker, second_speaker)

return first_speaker:money() >= 50000

end

Іконки прописуйте свої.

image

Пропишемо діалог НПС, якому ви хочете.
Йдемо в папку gameplay.
Див. скріншот.

image

Я буду прописувати Бармену, ви прописуєте своєму НПС.
Прописуємо НПС ось такий діалог:

<actor_dialog>bar_trader_unique_dialog</actor_dialog>
image

Переходимо в dialogs_bar.xml

image

Прописуємо ось так:

                <dialog id="bar_trader_unique_dialog">

        <phrase_list>

            <phrase id="2">

                <text>bar_trader_unique_dialog_2</text>

                <next>4</next>

            </phrase>

            <phrase id="4">

                <text>bar_trader_unique_dialog_4</text>

                <action>dialogs_bar.give_message_proposed_items</action>

                <next>44</next>

                <next>45</next>

                <next>46</next>

                <next>47</next>

            </phrase>

            <phrase id="44">

                <text>bar_trader_unique_dialog_44</text>

                <next>444</next>

            </phrase>

            <phrase id="46">

                <text>bar_trader_unique_dialog_46</text>

                <next>466</next>

            </phrase>

            <phrase id="457">

                <text>bar_trader_unique_dialog_457</text>

            </phrase>

            <phrase id="468">

                <text>bar_trader_unique_dialog_468</text>

            </phrase>

            <phrase id="47">

                <text>bar_trader_unique_dialog_47</text>

            </phrase>

            <phrase id="45">

                <text>bar_trader_unique_dialog_45</text>

                <next>455</next>

            </phrase>

            <phrase id="455">

                <text>bar_trader_unique_dialog_455</text>

                <next>456</next>

                <next>457</next>

            </phrase>

            <phrase id="466">

                <text>bar_trader_unique_dialog_466</text>

                <next>467</next>

                <next>468</next>

            </phrase>

            <phrase id="1">

                <text>bar_trader_unique_dialog_1</text>

                <next>2</next>

            </phrase>

            <phrase id="444">

                <text>bar_trader_unique_dialog_444</text>

                <next>445</next>

                <next>446</next>

            </phrase>

            <phrase id="0">

                <text>bar_trader_unique_dialog_0</text>

                <has_info>bar_trader_trade</has_info>

                <next>1</next>

            </phrase>

            <phrase id="446">

                <text>bar_trader_unique_dialog_446</text>

            </phrase>

            <phrase id="445">

                <text>bar_trader_unique_dialog_445</text>

                <precondition>dialogs_bar.trader_seva_money</precondition>

                <action>dialogs_bar.trader_seva</action>

            </phrase>

            <phrase id="456">

                <text>bar_trader_unique_dialog_456</text>

                <precondition>dialogs_bar.trader_val_money</precondition>

                <action>dialogs_bar.trader_val</action>

            </phrase>

            <phrase id="467">

                <text>bar_trader_unique_dialog_467</text>

                <precondition>dialogs_bar.trader_exo_money</precondition>

                <action>dialogs_bar.trader_exo</action>

            </phrase>

        </phrase_list>

    </dialog>
image
image

Українізуємо текст, йдемо у файл st_dialogs_bar.xml

image

Прописуємо ось так:

<string id="bar_trader_trade_dialog_0">
<text>Слухай, а чого вибір у тебе такий небагатий?</text>
</string>
<string id="bar_trader_trade_dialog_1">
<text>Це ж не база повноцінна. Тут збираються тільки ті, хто прийшов "Боргу" за гроші допомагати від мутантів відстрілюватися. Я попит нюхом відчув, та й прийшов сюди торгувати. Що встиг із собою взяти та наміняти тут - дивись, усе в асортименті.</text>
</string>
<string id="bar_trader_unique_dialog_0">
<text>А що-небудь екзотичне запропонувати можеш?</text>
</string>
<string id="bar_trader_unique_dialog_1">
<text>Можу, тільки коштувати це буде дорожче звичайних предметів.</text>
</string>
<string id="bar_trader_unique_dialog_2">
<text>Що в тебе є?</text>
</string>
<string id="bar_trader_unique_dialog_4">
<text>Вибирай:</text>
</string>
<string id="bar_trader_unique_dialog_44">
<text>Я візьму "СЕВУ"</text>
</string>
<string id="bar_trader_unique_dialog_444">
<text>Це обійдеться тобі в 30000 рублів.</text>
</string>
<string id="bar_trader_unique_dialog_445">
<text>Хорошо, тримай.</text>
</string>
<string id="bar_trader_unique_dialog_446">
<text>Я передумав.</text>
</string>
<string id="bar_trader_unique_dialog_45">
<text>Я візьму "АС ВАЛ"</text>
</string>
<string id="bar_trader_unique_dialog_455">
<text>Це обійдеться тобі в 25000 рублів.</text>
</string>
<string id="bar_trader_unique_dialog_456">
<text>Хорошо, тримай.</text>
</string>
<string id="bar_trader_unique_dialog_457">
<text>Я передумав.</text>
</string>
<string id="bar_trader_unique_dialog_46">
<text>Я візьму "Екзоскелет"</text>
</string>
<string id="bar_trader_unique_dialog_466">
<text>Це обійдеться тобі в 50000 рублів.</text>
</string>
<string id="bar_trader_unique_dialog_467">
<text>Хорошо, тримай.</text>
</string>
<string id="bar_trader_unique_dialog_468">
<text>Я передумав.</text>
</string>
<string id="bar_trader_unique_dialog_47">
<text>Мі поки що нічого не потрібно.</text>
</string>
image

Ось і все, функція готова! Можна запускати гру і тестувати.

 


   
Цитата
Теги теми