A Development Tutorial: Chapter 08

From FOnline: Reloaded Wiki
Jump to: navigation, search
A Development Tutorial: Chapter 8
AWikiEditor.gif
Get the developer tools and try building new content for this game!
Season {{{season}}}
Status Progress Stopped
Completion 75%
Authors Slowhand
This Chapter 08: Scenery Scripts
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 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 interact 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 check at the start.

Code:
//  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;
}