Topic: Basic Development Tutorial for FOnline: Reloaded  (Read 808 times)

Slowhand

  • Posts: 81
  • Go for the eye, Boo! Go for the eyes!
    • View Profile
    • Personal Message (Offline)
Basic Development Tutorial for FOnline: Reloaded
« on: July 29, 2015, 04:45:08 PM »
I do feel important that this tutorial is published on the FOnline: Reloaded forums, because the info on dev forums is very scattered, and too hard to start out. I belive this would help many mapper/scripter/story writter wannabes, who play this game. Also, the closer the information is, to someone who requires it, the better.

P.S.: As promised in my first post on this forum :)

Basic Development Tutorial for FOnline: Reloaded.
  • This is a brief tutorial on how to get started developing FOnline.

Contents:
« Last Edit: August 24, 2015, 06:10:32 PM by Slowhand »

Slowhand

  • Posts: 81
  • Go for the eye, Boo! Go for the eyes!
    • View Profile
    • Personal Message (Offline)
1. Downloading and setting up the Development Kit.
« Reply #1 on: July 29, 2015, 05:48:18 PM »
1. Downloading and setting up the Development Kit.

  • Download the SDK
    • Download the Server and Mapper and the full Client.
    • Keep these 2 zip files for later use, because if you mess things up very badly while experimenting (I did), u can just start over from here.
    • Copy the Client, Mapper, Server, Tools folders from the zip files to your development folder.
  • Setting up the Mapper: (don't use yet)
    • If you start the Mapper for the first time, it will use the default video resolution, which is set in the client. Unfortunately, this will trim down the Mappers interface, so the first thing you should do, is launch the FOConfig.exe in the Client folder and set the resolution to at least 1024*768.
    • I also advise you to disable Full Screen.
    • Save and Exit.
  • Try out if it works
    • Start the Server and wait for the scripts/everything to load, when it's done, you will see something like this: ***   Starting game loop   ***
    • Start the Client, create new char, log in. If no errors, then you are done with the setup.
  • If you got problems with this part, you might try to set up your environment again, if it fails, search Questions and Answers at fodev.net.
« Last Edit: August 07, 2015, 04:48:43 PM by Slowhand »

Slowhand

  • Posts: 81
  • Go for the eye, Boo! Go for the eyes!
    • View Profile
    • Personal Message (Offline)
2. Modifying existing maps with the Mapper.
« Reply #2 on: July 29, 2015, 06:00:29 PM »
2. Modifying existing maps with the Mapper.

Another easy step, is to modify and existing map and check the effects.
  • Load the map and get around
    • Launch Mapper and load the map of The Hub
    • Press enter after mapper started to get the console.
    • Type: "~hub" - to load the map.
    • Press F8 to disable mouse scrolling. (This can be very annoying, since even if the Mapper does not have focus, it will try to scroll while you are working with other apps.
    • Press Enter again, when the command line is empty, so the command line disappears, now you can use the arrow keys to scroll around.
  • Modify and save the map.
    • After you find the northen entrance of the hub, try to delete some NPC's and some vagons. Also try to add a car and an NPC.
    • To select something, just click on it. To delete the selected item, press del.
    • To place NPC's, go to Humanoids and there click on the tab again, to filter them. Find one that suits you and place it on the map. To place it on the map, make sure u don't have anything else selected, click on it, then move your mouse over the map you want to place it, right click, then left click. You can use middle mouse button to rotate the element.
    • Type: "^hub" - to save(overwrite) the map.
  • Delete the old map's cache
    • Go to the Server/Maps folder and find the two map files: hub.fomapb and hub.fomap.
    • Delete hub.fomapb. (Make sure u keep the hub.fomap file. Alternatively you can use the clean.bat before starting the server, which will delete all binary? map files so when the server starts it will generate them.)
  • In order for changes to take effect, you will need clear the world saves.
    • These are some files in the Server/Save folder, usually named like "world0001.fo".
    • If you do not delete these files, then only some changes will take effect, like map design, but not NPCs, items, or anything that is not static.
  • Check your work.
    • Start the server, start the client, and check the effects.
    • You should see your modified Hub map, with the missing NPC's and vagons, and the extra NPC's, cars u added.
« Last Edit: August 07, 2015, 04:48:24 PM by Slowhand »

mojuk

  • Posts: 305
    • View Profile
    • Personal Message (Offline)
Re: Slowhand's development tutorial
« Reply #3 on: July 29, 2015, 07:35:07 PM »
For dialogs this is a must read in my opinion:
http://fodev.net/files/sdk/ArtOfDialogs.pdf

Slowhand

  • Posts: 81
  • Go for the eye, Boo! Go for the eyes!
    • View Profile
    • Personal Message (Offline)
3. Adding new locations to the world, using the World editor.
« Reply #4 on: July 29, 2015, 09:52:24 PM »
3. Adding new locations to the world, using the World editor.

This isn't hard as well, but here u can mess things up pretty easy if you click around while experimenting.
  • First things first, before you forget, delete the world save files. I always forget this and launch the server two times bc of this.
  • Launch Mapper and open a map to copy from, I used: tent_mountain (Type in console: "~tent_mountain")
  • Add a new robot NPC (critters->others->Robobrain)
  • Save the map: "^tut_map1"
  • Go to the Server\Maps forlder, you should have a new map file here named: tut_map1.fomap

Now, time to place this map on the world.
  • Launch the World editor located in the Tools folder. (You might need to get .NET framework v4, this is a freely downloadable framework for Windows, don't be affraid of it, programs written in C# use it. Most Windows Service  Packs have it, so you probably won't have to dl it.)
  • Add the new map:
    • Press Ctrl+M (or in the menu Tools->Mapdata Editor) and Add New Map
    • Name your nap: Tutorial1
    • Press Assign Free PID (but the default 128 should be free as well)
    • Browse the map file recently made (..\Server\Maps\tut_map1.fomap)
    • Save.
  • Add the new location:
    • Press Ctrl+L (or in the menu Tools->Location Editor) and Add New Location
    • Name the location: Tut_Loc1
    • Assign a free PID. (Default 90 should work fine as well)
    • Set size to 6. (24 is a town size green cirle, 6 or 8 should be small enough)
    • Set max players to 0. (In case you leave it at 1, and you test it later with multiple chars, they won't be able to enter until the one inside leaves.)
    • Set description ("A strange robot in the middle of the wastes")
    • Set visibilty: Check Visible.
    • Add Map: Sort by PID, scroll to 128 and select the recently made map, Tutorial1.
    • Save and exit Location Editor.
  • Set the location on world map:
    • Press Ctrl+A (menu Worldmap->Add Location)
    • Sort by PID, scroll to 90 and find your recently added location named Tut_Loc1
    • Add this location. Now you can place your location on the map, place it near the spawning point for easier testing.
    • Check what you done, by searching the map in World Editor near Hub, your new location should appear.
    • Save the world map, press Ctrl+S (menu: File -> Save) and exit World Editor.
Test what you have done. Make sure you delete the World saves, start server, launch client and with a new char you should see the new tutorial location nearby.
« Last Edit: August 07, 2015, 04:49:07 PM by Slowhand »

Slowhand

  • Posts: 81
  • Go for the eye, Boo! Go for the eyes!
    • View Profile
    • Personal Message (Offline)
4. Adding dialogues for NPC's
« Reply #5 on: July 30, 2015, 03:00:53 AM »
4. Adding dialogues for NPC's

Okay, let's continue, developing our newbie tutorial. This robot shall give usefull information for newbies who never played any FOnline games and are used to the original Fallout1/2/3/New Vegas etc games. So, our robot shall teach the newbies how to be self sufficient, how to gather resources, harvest, make tents etc. Ofc if they want to. It should introduce the old quality of questing/talking to NPC's where the NPC reacted to the Players stats, actions etc.

  • Launch the Dialog Editor (Tools\DialogEditor)
  • Create a new dialog by pressing the Add Tree. Name your dialog engl. (This isn't actually it's name, but it's language type, it should be "engl" always, unless you want the dialog in a different language, but don't ask me about it)
  • You will get a node named Predialogue Installations. This node is responsible for the initial reaction of the NPC to the player.
  • For now let's make a new dialog. On the botton, select Dialog tabpage. For text enter the text the NPC will say, for example: "The robot scans you briefly then greets you. Hi. I'm TuRo MKI.". Edit the dialog number to a unique number, this time 200, and Add Dialog.
  • This dialog will need answers as well, from which the player can choose from. Select the newly added dialog, on the botton select answer tabpage, and add two answers:
    • First answer with text: "Hi yourself Robot.", set the radio button to Other->Close dialog. This will make your robot interactive, but NPC's only have one option, to leave the conversation at first answer.
    • Second answer with text: "Hi. I'm lost.", set the radio button to On dialog and leave the number at default value or set it to 200. This answer might generate an infinite loop, bc it will always get the player back to where the Robot says Hi. In order to advance the dialog we need more dialoges, but for presentation purposes this should do.
  • Now set the predialogue installations. Add an aswer to it: "I dont know you" and link it so, that the answer takes the player to the first dialog (200). This will make the Robot react to the players by always saying Hi.
  • To give a meaning to the "I dont know you" answer, we can introduce a demand constraint. Go to Demands,select Var: "name_mem_npc_player", set the equation sign to "==" and enter the value "0".
  • Add a Result to this answer as well: Var "name_mem_npc_player", set the equation sign to "=" and enter "1" for value. Also select NPC from the radio box and add the Result.
  • This way we made our Robot to interract with each NPC only once.
  • Other contrains can be made as well, like required strenght, or intellect, or simply make the robot talk at a different level of language if the player has low intellect. The example below shows this.
  • Save the dialog with a name you remember, for example: tut_dialog1.fodlg
  • For next step, we need to link the dialog with the Robot.
    • First, you need to edit the file named dialogs.lst in Server\Dialogs to include the new dialog. Just copy a line and give a unique ID for the dialog file, I used 2100. Try to keep the order and structure of this dialogs list file.
    • Use the Mapper to add this dialog to the Robot. Simply select the robot, and at dialogs enter this number.
  • Save the map, delete world save files, launch server, try.

I made a little bit more complex dialog for my robot, feel free to understand it and try it. Basically the robot detect the players Intellect and greets him accordingly. The player can gather some extra information if he has high perception. The successfull scenario ends in the robot giving the player a task to gather him flint, so the robot can teach him how to craft a tool.

Here is how it looks. (click on images for normal size)


« Last Edit: August 07, 2015, 04:49:36 PM by Slowhand »

Slowhand

  • Posts: 81
  • Go for the eye, Boo! Go for the eyes!
    • View Profile
    • Personal Message (Offline)
5. Creating a two map zone.
« Reply #6 on: August 01, 2015, 04:24:59 PM »
5. Creating a two map zone.

  • Create second map and add it to the world.
    • Launch the Mapper and open a cave map. Save it to a different name. (I used: q_tut1_in) (q for quest, tut1 for tutorial1, and in for inside)
    • Launch the WorldEditor, Tools->Map Data Editor (Ctrl+M), Add New Map. Add q_tut1_in, and assign an ID similar to the previous one. (129 for me)
    • Tools->Location Editor (Ctrl+L), find the tutorial location (mine had PID 90) and double click to edit it. Add the new map with PID 129 to it. Now it should have 2 maps.
    • Save the World (Ctrl+S) and exit World Editor.
  • Link the first map to the second one:
    • Launch Mapper again and open the first map. (The one that will be accessed from the world map, I named it: q_tut1_out)
    • Add some Ent (Entry point) elements, and set their "EntireNumber" to 0. This is where the player will spawn when he enters the area from the world map.
    • Add a cave entrance, add the design elements, and add some Exit Grid (EG) element to the cave entrance. (They can be found at Tech panel)
    • Edit the Exit Grid's values: set "ToEntire" to 0, while set "ToMapPid" to 129 (the PID of the second map, the cave)
    • Now add some more Ent elements close to the cave entrance, and set the "EntireNumber" value to 1. This is where the player will spawn when he exits the cave.
    • The first map is set, save it.
  • Link the second map to the first:
    • Load the second map (cave).
    • Add some Ent elements near the cave entrance and set their "EntireNumber" to 0. Here will the player spawn when enters the cave.
    • Fill the entrance of the cave with EG elements with values: set "ToEntire" to 1 and set "ToMapPid" to 128 (the PID of the first map, q_tut1_out in my case)
    • Save the map and exit the Mapper.
  • Try it out:
    • Clean, delete world save files, and run the server.
    • Your character should be able to enter and leave the cave at his leisure.

Here are my maps:



« Last Edit: August 07, 2015, 04:50:00 PM by Slowhand »

Slowhand

  • Posts: 81
  • Go for the eye, Boo! Go for the eyes!
    • View Profile
    • Personal Message (Offline)
6. Adding monsters, loots and some basic (pre-written) scripts.
« Reply #7 on: August 06, 2015, 05:29:10 PM »
6. Adding monsters, loots and some basic (pre-written) scripts.

So, next in line is, adding some monsters to the map, with some basic script. We will not make scripts, only use some default ones.
The first thing you might notice, is that if you place a critter on the map, for example a Mole Rat, it will stay idle and do nothing, unless attacked. In order to make a Critter be agressive or semi-agressive, it will need some scripts. There are some good basic scripts in the Klamath map (Rats/Geckos), we will use those. (The are in the scripts files not in the map ofc, but you can access them by checking Klamath map with Mapper)

So, step by step:
  • First things first, if you haven't, create a new bat file to lauch your server. It should delete all fosmapb from the maps, and launch server after. This way you will never run in circles trying to figure out, why things don't works, when the only problem was, that you forgot to clean, rebuild the maps and reload the world.
    (In case you don't know how to make batch files, just make a new text file with the name CleanWorld.bat in the Server folder and add the following 3 lines to it:
    • "del maps\q*.fomapb"
    • "del save\world*.fo"
    • "FOnlineServer.exe"
    This will delete ur current world save as well, so every progress your char had, except it's creation and location is lost.)
  • Launch Mapper.
  • Create a cave (or copy one, but remove useless "tech" objects so u don't accidentally get random monsters generated) and place some rats in it.
  • Use the property editor (press F9 to toggle on/off) to set the mobs (I will refer to monsters/critters as mobs from now on) script to the following:
    • set ScriptName to "mob" (This will tell which script file to check for the function below. Server\Scripts\mob.fos )
    • set FuncName to "critter_init" (This is the function (script) to be called when creating this mob)

  • Save the map and try it. Use your new batch file.

Adding some loot for the mobs.
  • Select the mob (click on it, have details window turned on - F9)
  • On the bottom panel select Norm, double click it and filter for ammo.(You target on the map still should be the rat.)
  • Now Alt+Click on some shotgun shells.
  • On the bottom panel select Inve, you should see the shotgun shells added. You can Alt+Click to remove them.
  • To set the amount of the shells, just click on the shells and edit the Count to a differnt value than 0.
  • Launch server and client, to try it out.
  • Kill the mob for your reward: 1 shotgun shell ;)

The result should look like this in Mapper:



Adding agressive mobs usually does not fullfill all of the quest writers desires. So our next step is, to add some mobs, that do not move/attack, until they are triggered to do so. For this, we will also make a new dialog. The molerat will talk to the player, and the player will have some options how to engage it. The choise "I will exterminate you and all your vermints." will trigger all mobs who see the player to attack him, otherwise the player can leave peacefully or take on the molerat in a man versus rat duel.

Step by step:
  • Launch Dialog Editor and create a new dialog.
  • Make the dialog tree as the picture below shows.
  • After saving it, make sure you edit the dialog list (Server\dialogs\dialog.lst)file and add to it the dialog you made, I used 2102 for dialog ID.
  • Add the dialog ID to the Molerat Dialog property.
  • Add some small rats around the Molerat and set their ScriptName to "mob" and FuncName to "_DontMove".
  • Add some weapons to the entrance of the cave, so your character can survive the rat attack.
  • Save map and try. Gl.
Note: Use Demand or Result to add scripts to dialogs. The one we added, was in the script file named dialog and the scripts function name was r_Alert. We will do more complicated scripts later on, but if you want, feel free to study some of the script files.


« Last Edit: August 07, 2015, 04:50:19 PM by Slowhand »

Slowhand

  • Posts: 81
  • Go for the eye, Boo! Go for the eyes!
    • View Profile
    • Personal Message (Offline)
7. More on dialogs - Tracking quest progress
« Reply #8 on: August 06, 2015, 05:29:51 PM »
7. More on dialogs - Tracking quest progress

The next important thing with dialogs is, to track a given quests progress. For this, we will need to create a game variable, track it through the dialog and through other actions of the player as well.

Step by step:
  • Make a quest variable:
    • Launch DialogEditor, use the Vars editor tabpage on the top.
    • Enter a fitting name, (like "q_tut1" - q for quest, tut1 for tutorial1)
    • Enter a unique number for Num, one that is not used, for easy access I used 3, but a number in higher range should be used.
    • Set the radio box to Local, leave the checkboxes unchecked.
    • Click Add.
  • If it fails, this is how you can make it the harder way:
    • Open for edit the variable text-file list in your server's script forlder: Server\scripts\_vars.fos
    • Add the following lines at their respective places (use your unique Num, not mine which was 3):
    • Add the header lines somewhere at the start of the text file, keeping the ordering by Num.
      • #define LVAR_q_turo                        (3)
    • Add the body lines somewhere where similar lines are, exact place depending on your Num:
      •    $   3   1   q_turo   0   0   1000   0
      • **********
      •    TuRo progress.
      • **********
  • Create or modify your dialog to support the new quest variable:
    • Add a new Dialog with an Aswer, which will end the dialog.
    • To the Answer add a Result, which will set the new quest varialbe to 10.
    • Add a new Answer to Predialogue Installations, which will lead to a dialog, that will be the progress of the quest.
    • Add a Demand to this answer, that requires the quest variable to be 10.

This is how it looks at my end:



On the above picture, the tutorial robot will check if the quest varialble (q_turo_prog) is 10, which means that the player has reached a point in the conversation with the robot, where the robot will ask him, to gather some flint and use his fixboy to make a primitive tool.




On the above picture, the tutorial robot will ask the player to make a primitive tool and to mark the progress so far, will set the quest variable to 10, and exit the dialog. Next time when the player talks to the robot, it will jump to dialog 9 where the robot asks if the task is done. Here the robot checks if the player has a primitive tool on him, and will progress further if so.

This was only a part of the Tutor Robot quest, but enough to point out the example, how to progress using a quest variable. Ofc, other dialogues would lead to incrementing or setting back to quest variable to other values, and because of the Predialogue installation Answer Demands, the right dialog will be selected for the current progress of the quest.
« Last Edit: August 07, 2015, 04:50:42 PM by Slowhand »

Slowhand

  • Posts: 81
  • Go for the eye, Boo! Go for the eyes!
    • View Profile
    • Personal Message (Offline)
8. Creating and using some basic scripts: Scenery scripts.
« Reply #9 on: August 07, 2015, 01:10:36 PM »
8. Creating and using some basic scripts: Scenery scripts.

A quest complexity will usually require us to use scripts. At this point we will dive into one of the most simple scripts, the Scenery scripts, or scripts associated with scenery objects on the map. For this we will need a Scenery object on our map and a new script we want to call when the user interract with it.

Step by step:

  • Create a new scriptfile:
    • Create a new textfile named "quest_tut1.fos" in "Server\scripts\"
    • Copy paste the content from the code part below.
  • Bind the script file to the Scenery in Mapper:
    • Launch Mapper and the load the map.
    • If you haven't add a Scenery object to the map. (I used some defected robot.)
    • Set the ScriptName value of the Scenery object to your script files name. (quest_tut1.fos)
    • Set the FuncName value of the Scenery object to the function to be called when player interaction. (s_RefillRobot)
    • Save the map and exit.
  • Run the server to compile your script:
    • To test if your script compiles error free, you can use: Server\scripts\compile.bat quest_tut1.fos
    • Delete previous script file binaries of your modified script file if they exist. (quest_tut1.fosb, quest_tut1.fosp)
    • Run the server.
  • Understand the script:
    • Study the script file, pretty straightforward, comments are useless but I left them there anyways.
    • If the player tries to use the Repair Skill on the robot, it will say that he can't do that without Small Energy Cells.
    • If the players tries to use the Science Skill on the robot, the system will say that the robot is out of energy.
    • Finally, if the player tries to use Small Energy Cells on the robot, the system will notify about the success and set the quest variable to the desired value. This is how the quest is progressed in this case.
    • Also one Small Energy Cell is removed from the backpack of the player.
    • If the player tries to use the Repair or Science skills on the robot, the notification will tell, that it is already done. This is ensured by the quest variable chesk at the start.
Code: [Select]
//  Includes some definitions
#include "_macros.fos"

//  Function signature for player interactions with Scenery objects
bool s_RefillRobot(Critter& player, Scenery& robot, int skill, Item@ item)
{
// Retrieve the variable used by the quest to mark it's progress, plus error handling
GameVar@ questVar = GetLocalVar(LVAR_q_turo_prog, player.Id);
if(valid(questVar))
{
// is quest still in progress and before repairing the robot
if (questVar < 30)
{
//  Check if repair skill is used on the robot
if(skill == SK_REPAIR)
{
player.Say(SAY_NETMSG, "You don't think it can be done without some small energy cells.");
return true;
}
// Check if science skill is used on the robot
if(skill == SK_SCIENCE)
{
player.Say(SAY_NETMSG, "The robot is running very low on energy.");
return true;
}
// Check if the player used a Small Energy Cell on the robot.
if(valid(item))
{
if(item.GetProtoId() == PID_SMALL_ENERGY_CELL)
{
player.Say(SAY_NETMSG, "You replace one of the energy cells of the robot.");
// Set the quest progress
questVar = 30;
// Remove the Small Energy Cells used.
item.SetCount(item.GetCount() - 1);
item.Update();
return true;
}
}
}
else
{
if(skill == SK_REPAIR || skill == SK_SCIENCE)
{
player.Say(SAY_NETMSG, "You already replaced the energy source of this robot, there is nothing more you can do here.");
return true;
}
}
}
return false;
}
« Last Edit: August 07, 2015, 04:50:57 PM by Slowhand »

Slowhand

  • Posts: 81
  • Go for the eye, Boo! Go for the eyes!
    • View Profile
    • Personal Message (Offline)
9. Creating new quest location from dialog.
« Reply #10 on: August 07, 2015, 04:24:18 PM »
9. 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 questgiver and succedes), 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 repsective 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:



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

Code: [Select]
#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());
}
« Last Edit: August 07, 2015, 04:51:18 PM by Slowhand »

Slowhand

  • Posts: 81
  • Go for the eye, Boo! Go for the eyes!
    • View Profile
    • Personal Message (Offline)
10. 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.

  • r_GetQuest(..)
    • This function should be called from the dialog, when the NPC gives the quest.
    • If the timed even is available, then it will summon the location, but this is a precation only, the dialog branching should decide this.
    • Try and test this, if the timer is not up, it should say in system window that the quest is not available yet.
  • e_ResetSpawnLocTimer(..)
    • This is an even function which will be called from r_getQuest(..) and is responsible for reseting the timer.
    • All this function does, is to call the setTimedEventAvailable(..) function to allow the retaking of the quest.
  • setTimedEventAvailable(..)
    • Is used to set the Unique variable for this quest timer.
  • isTimedEventAvailable(..)
    • Check the value of the timer variable.

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;
}
}
« Last Edit: August 08, 2015, 02:04:56 AM by Slowhand »

Yuno-Gasai

  • Supporter
  • Posts: 168
  • Hi, hehe
    • View Profile
    • Personal Message (Offline)
Re: Basic Development Tutorial for FOnline: Reloaded
« Reply #12 on: August 08, 2015, 03:39:18 AM »
Interesting, I'll try coding something  :P
According to some people's logic, posting completely logical arguments with elaboration (even when they asked you too) is considered as aggressive spam. Sad, sad humans.


Slowhand

  • Posts: 81
  • Go for the eye, Boo! Go for the eyes!
    • View Profile
    • Personal Message (Offline)
Re: Basic Development Tutorial for FOnline: Reloaded
« Reply #13 on: August 08, 2015, 10:45:32 AM »
Well, if you haven't tried to dev yet at all, and would take the time, please follow these steps one by one and tell me when somewhere you had difficulty, or got stuck, so I can correct them.

Henry

  • Wiki Editor
  • Posts: 568
  • Toxica disconnected
    • View Profile
    • Personal Message (Offline)
Re: Basic Development Tutorial for FOnline: Reloaded
« Reply #14 on: August 09, 2015, 06:54:17 PM »
This is a fantastic amount of work. Do not let silence effect you - i think everyone here is impressed and appreciative of this. Thanks!