A Development Tutorial: Chapter 08: Difference between revisions
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
| status = Progress Stopped | | status = Progress Stopped | ||
| complete = 75% | | complete = 75% | ||
| seasons = All Seasons | |||
| authors = Slowhand | | authors = Slowhand | ||
| chapter = 08: Scenery Scripts | | chapter = 08: Scenery Scripts | ||
| 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>'''Scenery Scripts'''<br>[[A Development Tutorial: Chapter 09|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]] | | 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>'''Scenery Scripts'''<br>[[A Development Tutorial: Chapter 09|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 37: | Line 38: | ||
** 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. | ** 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:'''<br> | ||
<code class="bbc_code" style="overflow: scroll;">// Includes some definitions<br>#include "_macros.fos"<br><br>// Function signature for player interactions with Scenery objects<br>bool s_RefillRobot(Critter& player, Scenery& robot, int skill, Item@ item)<br>{<br><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>Retrieve the variable used by the quest to mark it's progress, plus error handling<br><span style="white-space: pre;"> </span>GameVar@ questVar = GetLocalVar(LVAR_q_turo_prog, player.Id);<br><span style="white-space: pre;"> </span>if(valid(questVar))<br><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>is quest still in progress and before repairing the robot<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>if (questVar < 30)<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>// Check if repair skill is used on the robot<span style="white-space: pre;"> </span><br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>if(skill == SK_REPAIR)<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>player.Say(SAY_NETMSG, "You don't think it can be done without some small energy cells.");<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>return true;<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>}<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>Check if science skill is used on the robot<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>if(skill == SK_SCIENCE)<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>player.Say(SAY_NETMSG, "The robot is running very low on energy.");<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>return true;<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>}<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>Check if the player used a Small Energy Cell on the robot.<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>if(valid(item))<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>if(item.GetProtoId() == PID_SMALL_ENERGY_CELL)<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>player.Say(SAY_NETMSG, "You replace one of the energy cells of the robot.");<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>Set the quest progress<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>questVar = 30;<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>//<span style="white-space: pre;"> </span>Remove the Small Energy Cells used.<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>item.SetCount(item.GetCount() - 1);<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>item.Update();<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>return true;<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>}<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>}<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>}<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>else<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>if(skill == SK_REPAIR || skill == SK_SCIENCE)<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>{<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>player.Say(SAY_NETMSG, "You already replaced the energy source of this robot, there is nothing more you can do here.");<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>return true;<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>}<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>}<br><span style="white-space: pre;"> </span>}<br><span style="white-space: pre;"> </span>return false;<br>}<br></code> | |||
[[Category:Guides]] | [[Category:Guides]] |
Latest revision as of 21:15, 22 September 2018
A Development Tutorial: Chapter 8 | |
---|---|
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;
}