fodev.net

General => Features & Articles => Topic started by: Slowhand on December 18, 2015, 11:38:17 am

Title: Advanced Development Tutorial for FOnline
Post by: Slowhand on December 18, 2015, 11:38:17 am
This is the continuation of the Basic Development Tutorial for FOnline. More complex tutorials will be posted here, as experience shows, that for some people the basic tutorial was not basic enough, especially the scripting part.

Table of Contents:
Title: 1. Making a location spawn (for a daily/weekly quest) repeatable with timer.
Post by: Slowhand on December 18, 2015, 11:38:32 am
1. Making a location spawn (for a daily/weekly quest) repeatable with timer.

There will be no Step by Step for this one, as all the elements have been shown previously, I will just explain and link the script. You need to add the source to the same script file as the one we used previously, because it uses some of it's functions. Remove the lines starting with player.Say.. when you put this to production code, they were just used for debug, and for you to see what is happening.


There are many ways to do this, this is only one presentation that works, for experimentations.

Code: [Select]
// Demo for Timed Event used for repeatable quests.
void r_GetQuest(Critter& player, Critter@ npc)
{
player.Say(SAY_NETMSG, "r_GetQuest() called");
if (isTimedEventAvailable(player, npc))
{
uint[] values = {player.Id, npc.Id};
setTimedEventAvailable(player, npc, false);
CreateTimeEvent(AFTER(REAL_SECOND(10)), "e_ResetSpawnLocTimer", values, false);
r_SpawnLoc(player, npc);
}
else
{
player.Say(SAY_NETMSG, "r_GetQuest() - Quest not available yet.");
}
}

// S
uint e_ResetSpawnLocTimer(array<uint>@ values)
{
Critter@ player = GetCritter(values[0]);
player.Say(SAY_NETMSG, "e_ResetSpawnLocTimer()");
Critter@ npc = GetCritter(values[1]);
setTimedEventAvailable(player, npc, true);
return 0;
}

bool setTimedEventAvailable(Critter& player, Critter@ npc, bool isReady)
{
player.Say(SAY_NETMSG, "setTimedEventAvailable()");
if(!valid(player) || !valid(npc))
return false;
GameVar@ var = GetUnicumVar(UVAR_q_timedEventAvailable, npc.Id, player.Id);
if (!valid(var))
{
return false;
}
if (isReady)
{
var = 1;
player.Say(SAY_NETMSG, "setTimedEventAvailable() - 1");
}
else
{
player.Say(SAY_NETMSG, "setTimedEventAvailable() - 0");
var = 0;
}
return true;
}


bool isTimedEventAvailable(Critter& player, Critter@ npc)
{
player.Say(SAY_NETMSG, "isTimedEventAvailable()");
        if(!valid(player) || !valid(npc))
                return false;
GameVar@ var = GetUnicumVar(UVAR_q_timedEventAvailable, npc.Id, player.Id);
if (!valid(var))
{
return false;
}
if (var == 0)
{
player.Say(SAY_NETMSG, "isTimedEventAvailable() == 0");
return false;
}
else
{
player.Say(SAY_NETMSG, "isTimedEventAvailable() == 1");
return true;
}
}
Title: 2. Floating heal text above the head.
Post by: Slowhand on December 18, 2015, 11:40:54 am
2. Floating heal text above the head.

Specification:

In this tutorial we will use the Reloaded SDK version 2, and will change some RP elements into RNG or whatever it's called. Instead of the usual ***patches wounds***, ***injects stimpack*** healing message a green positive number will show the amount healed by using First Aid or healing drugs.
To specify our task, only First Aid, Super Stimpacks, Stimpacks, Hype, Healing Powder and Weak Healing Powder usage will change it's floating text. Also, if the FA is a critical failure the color of the text will be teal, while if it's  a critical success, the healing number will be the brightest green possible.

Understanding the code changes:


Code:

When linking the code from pastebin, I will leave a few lines for context, so you can see what to cut out and what to replace with.


Test it, if it does not work, report back on feedback please.

(https://i.imgur.com/4kNd9j8.png)

Title: 3. Writing a gambling game: Roulette.
Post by: Slowhand on December 18, 2015, 11:41:33 am
3. Writing a gambling game: Roulette.

We will write what the name suggest. At first, it's sounds like an easy and fast task, but once you get into details, you will see it's quite long. The good side of it is, that it helps us understand a lot about dialogues. Almost everything. And gives a lot of practice also.

First, I will explain the mechanic of how our roulette will work, then you should copy/paste the codes and use it to try it out on your development environment. I will give step by step instructions to make it seamless. After that I will explain most of the functions, the structure and highlight some specifics that can be useful later on. The code will be attached at the end.


Our simplified roulette:

Points of interest that we will cover:


Full dialogue in editor:


(https://i.imgur.com/wfD9X4u.png)



Full source code: (click on the files, they are a pastebin link)


Code review:

Ideas to enhance the gambling script:
Title: 4. Dialogues vs Scripts: Russian Roulette.
Post by: Slowhand on December 18, 2015, 11:48:55 am
4. Dialogues vs Scripts: Russian Roulette.

In this tutorial I will present two ways to write a Russian roulette game. The mechanic of the game is simple, the player can play Russian roulette with an NPC: A player puts a bet, a revolver has only 1 (in our example 2) bullet inside, the cylinder is rolled and the player pulls the trigger. If the player survives, he wins double, if not then... re-spawn time.

This example is used to illustrate how to solve the task in two different ways, one being without writing scripts (will use only pre-written scripts from dialogue.fos) the other with our own scripts.

Using only dialogues and the pre-written scripts from "dialogs.fos":




Here is how it looks:

(https://i.imgur.com/ciB60eX.png)

Review:
Title: 5. Writing a simple quest: Kill all monsters on a specific location.
Post by: Slowhand on December 18, 2015, 11:49:27 am
5. Writing a simple quest: Kill all monsters on a specific location.

As suggested/asked for, here is a simple quest. The player needs to go to a location, where he needs to kill all mobs. The location is private, so others can't interrupt him. When the mobs are killed (RP: for some reason the NPC will know) the player gets some reward.

Step by step:

Understanding the script:




Dialog:

(https://i.imgur.com/yE3wPP0.png)

Source:

Pastebin link. (http://pastebin.com/C1k8YQ4Q)

"Server/scripts/_vars.fos" - Header part

Code: [Select]
#define LVAR_q_tut_killmobs_loc (701)
#define LVAR_q_tut_killmobs_prog (702)

"Server/scripts/_vars.fos" - Body part

Code: [Select]
   $ 701 1 q_tut_killmobs_loc 0 0 0 4
**********
   Stores the location ID generated by the tutorial quest, so it can be deleted later.
**********

   $ 702 1 q_tut_killmobs_prog 0 0 0 4
**********
   Follows the progress of the tutorial quest.
**********
Title: 5.1 The location is given, but the position of mobs random.
Post by: Slowhand on December 18, 2015, 11:54:03 am
Explanation and code refinement in progress, until I do that, here is an example that works. (Need to add a dialogue, and a few variables which should be self explanatory if the code is understood.)

What the code does is, that it will try to put the critters on random positions surrounding a spot.

Main code - unrefined yet. (http://pastebin.com/wW5nQ8rf)
Title: 6. Perk: Mysterious Stranger
Post by: Slowhand on December 24, 2015, 07:58:02 am
6. Perk: Mysterious Stranger

Description:

If you have this perk, from time to time, a mysterious stranger appears out of the blue and tries to help you. This stranger might be there when you encounter difficulties in your travels, or sometimes even in remote zones, caves, hidden vaults, when you feel ill or are crippled. In the future he might even open locked doors for you, if you fail to do so.

Purpose:(One step toward RP.)

The reason for this perk, besides coolness, is to introduce the stat Charisma back into the game. (for servers who abandon it totally PvP wise) The perk should help people who want to role-play with higher Charisma than 1. The perk should be takeable with lower Charisma as well, but Charisma shall have a great effect on strength of the perk, this is why most of the timers depend on Charisma. Ofc, RP logic can surface as well, I leave to everyone's imagination why someone would help a charismatic person more often or for longer period of time. Even if the perk is reduced to a minimum of only random encounter appearance, or support perk, I suggest that Charisma dependency shall be dominant. The code is free for everyone to use it as they wish, gl, hf and may the stranger be with you.

Specification:

From time to time, a mysterious stranger will help the player, regarding the rules below.


Known bugs:

Code review:
Title: 6.1 Perk - Mysterious Stranger - Installation
Post by: Slowhand on December 31, 2015, 10:06:14 pm
6.1 Perk - Mysterious Stranger - Installation


How to install:


Setting up the module:

Every variable that is used to configure the module, can be find at the "ms_perk_h.fos" header file. To use the MS perk in production code, simply leave the variables as they are, or change some of them as your sense of balance dictates.

Setting up the module for testing:

To test the module, with or without the test module, it is advised to set the configuration variables to the following:

Title: 7. Blackjack card game - Specification
Post by: Slowhand on January 09, 2016, 06:33:46 pm
7. Blackjack card game.

Introducing a Blackjack card game into the RP of FOnline.

What would be the most reasonable way that gambling skill would affect the course of the game? (It shall be true to gambling in rl, shall be fun, and shall not be exploitable or afk farmed easily (or at all?).)

Specification:
What to keep in sight:
Title: 7. Black Jack card game - Installation
Post by: Slowhand on January 09, 2016, 06:39:41 pm
First things first. This, as well as the Mysterious Stranger is more like a module, rather than a tutorial, as it's complexity is too high to be of any proper use to teach stuff. Sorry about that.

7. Black Jack card game - Installation

Copy the following files to the "Server/scripts" folder:
Copy the following files to the "Server/dialogs" folder:

To complete the install, you also need to link stuff together, discussed several times in basic tutorial, like add "blackjack_dialogues.fos" to the script list, so the dialogue file can reference to it's scripts, you need to define a dialogue number to use the dialogue with and you need to create a map with an NPC or just add the dialogue to an NPC in a public map to try it out.

Testing:

- To help testing of rare cases, you can find some use cases on the bottom of the blackjack class. I left their calls commented out, so you can see where to put them, but it's basically at the end of init.

Current situation:

- Some features are not implemented and I will not implement them myself, that remains to the player. The split, basic function of Blackjack is cut out, because it produces a lot of complexity and I did not bother to implement it. Other than this, every function works, but it is not as configurable as promised, someone wanting to assign quests to this module, will have to work him/her self on scripting.

Edit:

- Fixed a a bug where when shoe ended there was no reshuffling.
- Added a few RP elements, shoe size can be seen, dealer's hole card can be seen and when shuffling happens, can be seen, depending on gambling and random check.
Title: 8. Adding or modifying sound effects.
Post by: Slowhand on January 22, 2016, 06:43:36 pm
8. Adding or modifying sound effects.

Modifying a sound effect - drinking nuka cola:

Testing it:
Title: 9. Adding or modifying graphical assets.
Post by: Slowhand on September 18, 2023, 07:48:41 am
9. Adding or modifying graphical assets.

Client side:

Server side:


Testing it:

CHEAT SHEET:

(https://i.ibb.co/ngQhVTH/image-2023-09-18-132538255.png) (https://ibb.co/98yRfJF)