A Development Tutorial: Chapter 09

From FOnline: Reloaded Wiki
Revision as of 07:36, 29 January 2017 by Henry (talk | contribs)
Jump to navigation Jump to search
A Development Tutorial: Chapter 9
Get the developer tools and try building new content for this game!
Season {{{season}}}
Status Progress Stopped
Completion 75%
Authors Slowhand
This Chapter 09: Dialogue-to-Quest Location
More Chapters Title Page
Development Kit Setup
Making Maps
The World Map Editor
NPC Dialogues
Create a 2-Map Zone
Monsters, Loot, and Scripts
Tracking Quest Progress
Scenery Scripts
Dialogue-to-Quest Location
Chapter 10
Setup of Scripting Environment
Understanding Quest Scripts
Chapter 13
Dialogue: The "SAY" Menu
Chapter 15
Lockpick Cooldown
Repeatable Locations
Floating FA Text
Roulette Game
Dialogues vs Scripts
Simple Kill Quest
Chapter 21
Mysterious Stranger Perk
Perk Installation
Black Jack Game
Black Jack Installation
Sound Effects
Notes {{{notes}}}


Creating new quest location from dialog.

After receiving a quest from an NPC, the NPC might in some cases mark a location on the player's map. This location will be known only to the player, and a red dot on the world map will appear. Once the player finished the quest (talks with the quest-giver and succeeds), the location will disappear.

Step by Step:

  • Create map data and location:
    • Open World Editor
    • Press Ctrl+M (Tools->Mapdata Editor) and Add New Map:
      • Set a name for the map data (I used: q_generated)
      • Set a unique ID (130)
      • Set the filename of the map you want to use. You probably need to make a new map with Mapper for this purpose, but for demonstration existing ones can be used.(q_tut1_out)
      • Save.
    • Press Ctrl+L (Tools->Location Editor) and Add New Location:
      • Set a name for the location. (q_tut1_loc)
      • Set a unique Id. (91)
      • Add the previously made mapdata to it. (q_generated)
      • Save
    • Save the World and exit
  • Create the script:
    • Create a file with the contents given below in the source tags and save it.(Server\scripts\quest_generateMap.fos)
    • Open "Server\scripts\scripts.cfg" with notepad, find the "quest-specific" area, and add an extra line to include the new script in the build/bind process. ("@ server module quest_generateMap")
    • Try out if the script compiles: Server\scripts\compile.bat quest_generateMap.fos
  • Create the dialog:
    • First you need to create a local variable (local if you set it on player, unique if u set it on NPC) to store the location ID which will be generated, so you can delete after it's not needed.(Recycling is important if you want to keep your server up for more than a few hours.)
      • Edit "Server\scripts\_vars.fos".
      • Add the header line to it's respective place (use unique number, I used 4):
        • #define LVAR_q_gen_loc (4)
      • Add the body lines to their respective places:
        • $ 4 1 q_gen_loc 0 0 1000 0
        • **********
        • Generated location progress.
        • **********
    • Create the dialog to look like on the below picture. (this is for demonstration purposes only)
    • On one of the answer you will have to add a Result, which will call the script function to create the map location.
    • When completing the quest, don't forget to call the script function which will delete the map location.
  • Do a clean on scripts as well, delete world save and launch server, client to try it out.


Here is the basic dialog, it's crude but only for demonstration of usage:

(image soon)

Here is the script that will spawn a location on the map and will delete it afterwards when triggered:

#include "utils_h.fos"
#include "worldmap_h.fos"
#include "npc_planes_h.fos"
#include "entire.fos"
#include "_colors.fos"
 
 
// function called as request from dialog to spawn quest location
void r_SpawnLoc(Critter& player, Critter@ npc)
{
// roll X,Y value of WM (World Map) zone index, in this case from 3x2 zones area near Hub
uint zoneX = Random(28, 31);   
uint zoneY = Random(39, 40);   

// get X,Y value of quest location position on WM in zone we picked above
uint   wx = zoneX * __GlobalMapZoneLength;          //get zone X,Y start value
uint   wy = zoneY * __GlobalMapZoneLength;
wx += Random(0, __GlobalMapZoneLength);             //add random value from 0 to zone size
wy += Random(0, __GlobalMapZoneLength);

// you can add more map locations here, and select one randomly
array<uint16> locationIds = { 91 };
uint num = locationIds.length;

// pick random encounter map, if only one map, then only one will be selected
uint16        locPid = locationIds[Random(0, num - 1)];

// create quest location
Critter@[] crits = { player };
int           loc = CreateLocation(locPid, wx, wy, crits);
if(loc == 0)
return;
// makes the location visible to the player
player.SetKnownLoc(true, loc);

// change location color on World Map
Location@ location = GetLocation(loc);
location.Color = COLOR_RED;
location.Update();

// set TB combat mode if needed
if(player.Mode[MODE_DEFAULT_COMBAT] == COMBAT_MODE_TURN_BASED)
{
SetTurnBasedAvailability(location);
}

// set location id to quest lvar (used when you need to delete location)
GameVar@  locidv = GetLocalVar(LVAR_q_gen_locid, player.Id);
locidv = loc;

// player can die and come back, but we will have to delete the location later
location.AutoGarbage = false;
}
 
// dialog function used in request to delete quest location (after player report finishing the quest)
void r_DeleteLoc(Critter& player, Critter@ npc)
{
GameVar@ var = GetLocalVar(LVAR_q_gen_locid, player.Id);
DeleteLocation(var.GetValue());
}