A Development Tutorial: Chapter 09: Difference between revisions

From FOnline: Reloaded Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 5: Line 5:
| status = Progress Stopped
| status = Progress Stopped
| complete = 75%
| complete = 75%
| season = All Seasons
| authors = Slowhand
| authors = Slowhand
| chapter = 09: Dialogue-to-Quest Location
| chapter = 09: Dialogue-to-Quest Location
| chapters = [[A Development Tutorial|Title Page]]<br>[[A Development Tutorial: Chapter 01|Development Kit Setup]]<br>[[A Development Tutorial: Chapter 02|Making Maps]]<br>[[A Development Tutorial: Chapter 03|The World Map Editor]]<br>[[A Development Tutorial: Chapter 04|NPC Dialogues]]<br>[[A Development Tutorial: Chapter 05|Create a 2-Map Zone]]<br>[[A Development Tutorial: Chapter 06|Monsters, Loot, and Scripts]]<br>[[A Development Tutorial: Chapter 07|Tracking Quest Progress]]<br>[[A Development Tutorial: Chapter 08|Scenery Scripts]]<br>'''Dialogue-to-Quest Location'''<br>Chapter 10<br>[[A Development Tutorial: Chapter 11|Setup of Scripting Environment]]<br>[[A Development Tutorial: Chapter 12|Understanding Quest Scripts]]<br>Chapter 13<br>[[A Development Tutorial: Chapter 14|Dialogue: The "SAY" Menu]]<br>Chapter 15<br>[[A Development Tutorial: Chapter 15.01|Lockpick Cooldown]]
| chapters = [[A Development Tutorial|Title Page]]<br>[[A Development Tutorial: Chapter 01|Development Kit Setup]]<br>[[A Development Tutorial: Chapter 02|Making Maps]]<br>[[A Development Tutorial: Chapter 03|The World Map Editor]]<br>[[A Development Tutorial: Chapter 04|NPC Dialogues]]<br>[[A Development Tutorial: Chapter 05|Create a 2-Map Zone]]<br>[[A Development Tutorial: Chapter 06|Monsters, Loot, and Scripts]]<br>[[A Development Tutorial: Chapter 07|Tracking Quest Progress]]<br>[[A Development Tutorial: Chapter 08|Scenery Scripts]]<br>'''Dialogue-to-Quest Location'''<br>Chapter 10<br>[[A Development Tutorial: Chapter 11|Setup of Scripting Environment]]<br>[[A Development Tutorial: Chapter 12|Understanding Quest Scripts]]<br>Chapter 13<br>[[A Development Tutorial: Chapter 14|Dialogue: The "SAY" Menu]]<br>Chapter 15<br>[[A Development Tutorial: Chapter 15.01|Lockpick Cooldown]]<br>[[A Development Tutorial: Chapter 16|Repeatable Locations]]<br>[[A Development Tutorial: Chapter 17|Floating FA Text]]<br>[[A Development Tutorial: Chapter 18|Roulette Game]]<br>[[A Development Tutorial: Chapter 19|Dialogues vs Scripts]]<br>[[A Development Tutorial: Chapter 20|Simple Kill Quest]]<br>Chapter 21<br>[[A Development Tutorial: Chapter 22|Mysterious Stranger Perk]]<br>[[A Development Tutorial: Chapter 23|Perk Installation]]<br>[[A Development Tutorial: Chapter 24|Black Jack Game]]<br>[[A Development Tutorial: Chapter 25|Black Jack Installation]]<br>[[A Development Tutorial: Chapter 26|Sound Effects]]<br>[[A Development Tutorial: Chapter 27|Pro Tips]]
}}
}}


Line 53: Line 54:
(image soon)
(image soon)


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


(image soon)
<code class="bbc_code" style="overflow: scroll;">#include "utils_h.fos"<br>#include "worldmap_h.fos"<br>#include "npc_planes_h.fos"<br>#include "entire.fos"<br>#include "_colors.fos"<br>&nbsp;<br>&nbsp;<br>//<span style="white-space: pre;"> </span>function called as request from dialog to spawn quest location<br>void r_SpawnLoc(Critter&amp; player, Critter@ npc)<br>{<br><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>roll X,Y value of WM (World Map) zone index, in this case from 3x2 zones area near Hub<br><span style="white-space: pre;"> </span>uint zoneX = Random(28, 31);&nbsp; &nbsp; <br><span style="white-space: pre;"> </span>uint zoneY = Random(39, 40);&nbsp; &nbsp; <br><br><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>get X,Y value of quest location position on WM in zone we picked above<br><span style="white-space: pre;"> </span>uint&nbsp; &nbsp;wx = zoneX * __GlobalMapZoneLength;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //get zone X,Y start value<br><span style="white-space: pre;"> </span>uint&nbsp; &nbsp;wy = zoneY * __GlobalMapZoneLength;<br><span style="white-space: pre;"> </span>wx += Random(0, __GlobalMapZoneLength);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//add random value from 0 to zone size<br><span style="white-space: pre;"> </span>wy += Random(0, __GlobalMapZoneLength);<br><br><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>you can add more map locations here, and select one randomly<br><span style="white-space: pre;"> </span>array&lt;uint16&gt; locationIds = { 91 };<br><span style="white-space: pre;"> </span>uint num = locationIds.length;<br><br><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>pick random encounter map, if only one map, then only one will be selected<br><span style="white-space: pre;"> </span>uint16&nbsp; &nbsp; &nbsp; &nbsp; locPid = locationIds[Random(0, num - 1)];<br><br><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>create quest location<br><span style="white-space: pre;"> </span>Critter@[] crits = { player };<br><span style="white-space: pre;"> </span>int&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;loc = CreateLocation(locPid, wx, wy, crits);<br><span style="white-space: pre;"> </span>if(loc == 0)<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>return;<br><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>makes the location visible to the player<span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><br><span style="white-space: pre;"> </span>player.SetKnownLoc(true, loc);<br><span style="white-space: pre;"> </span> <br><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>change location color on World Map<br><span style="white-space: pre;"> </span>Location@ location = GetLocation(loc);<br><span style="white-space: pre;"> </span>location.Color = COLOR_RED;<br><span style="white-space: pre;"> </span>location.Update();<br><br><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>set TB combat mode if needed<br><span style="white-space: pre;"> </span>if(player.Mode[MODE_DEFAULT_COMBAT] == COMBAT_MODE_TURN_BASED)<br><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>SetTurnBasedAvailability(location);<br><span style="white-space: pre;"> </span>}<br><br><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>set location id to quest lvar (used when you need to delete location)<br><span style="white-space: pre;"> </span>GameVar@&nbsp; locidv = GetLocalVar(LVAR_q_gen_locid, player.Id);<br><span style="white-space: pre;"> </span>locidv = loc;<br><br><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>player can die and come back, but we will have to delete the location later<br><span style="white-space: pre;"> </span>location.AutoGarbage = false;<br>}<br>&nbsp;<br>//<span style="white-space: pre;"> </span>dialog function used in request to delete quest location (after player report finishing the quest)<br>void r_DeleteLoc(Critter&amp; player, Critter@ npc)<br>{<br><span style="white-space: pre;"> </span>GameVar@ var = GetLocalVar(LVAR_q_gen_locid, player.Id);<br><span style="white-space: pre;"> </span>DeleteLocation(var.GetValue());<br>}<br></code>


[[Category:Guides]]
[[Category:Guides]]

Latest revision as of 21:15, 22 September 2018

A Development Tutorial: Chapter 9
Get the developer tools and try building new content for this game!
Season All Seasons
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
Pro Tips
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());
}