A Development Tutorial: Chapter 15.01

From FOnline: Reloaded Wiki
Jump to: navigation, search
A Development Tutorial: Chapter 15.01
Get the developer tools and try building new content for this game!
Season All Seasons
Status Progress Stopped
Completion 75%
Authors Slowhand
This Chapter 15.01: Lockpick Cooldown
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
The 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}}}

Modifying lock pick cooldown mechanic, using Reloaded SDK source, version 2.

This will be an example, how to spice up the lock picking mechanic a bit, changing the value of its cooldown from a static, to a dynamic value based on the character's Lockpick skill, tools used, lock difficulty and a random roll.

The script file of interest is "lockers.fos". Generally the usage of skills is defined in "main.fos", but this one there is empty.

I do not know how to explain this minor change in basic tutorial level, here is what the old code did:

   .. skipping parts of code that do not interest us now, starting from line 60..
   If lock pick skill is still in timeout then do display message, and do nothing.
   If lock is already unlocked, or locker is open, do nothing.
   Calculate the base lock picking value from player skill and lock complexity.
   Add to this base the bonus from tools if in main hand slot.
   Depending on random roll, delete the lock picks if in main hand.
   Roll and check if failure or success and message the player accordingly.
   Set the timeout for the skill.

The new mechanic:

   Lock picks will break on critical failure only.
   If the player tries to pick the lock without lock picks and critical failure occurs, he will hurt his fingers for random small amount damage and will trigger a higher cooldown.
   If the lock is unpickable by the player (because of lack of skill + tools) and a critical success occurs, the player will receive a warning message, so he does not bother anymore.
   If the lock pick simply fails, then the default timeout will be triggered, as before
   If the lock pick is successful, then a cooldown between 25% and 75% of default will be triggered. This cooldown depends on the roll made to pick the lock. The transition between the values is linear, when the minimum cooldown will trigger if the (skill + tool bonus - lock difficulty) is higher or equal to 50, basically the bonus value of the expanded lock pick set. The maximum cooldown (3/4 of default cooldown) is triggered when the roll check barely made it. This way having way higher lock pick skill is more rewarding, since opening very easy locks will trigger a much shorter cooldown, sometimes allowing the player to loot and try to unlock another container if nearby.

Points of interest:

1. If you didn't so far, make sure you understand the CLAMP(x, min, max) macro:

What it does, is makes sure that a value is between boundaries, like the value of CLAMP(x, 1, 95) will be "x" if that is between 1 and 95, else if "x" is higher than 95, then the value will be 95 or if "x" is lower than 1 the value will be 1. The CLAMP macro is defined using the ternary operator "?:" (actually two of them embedded in each other), which has the following formula: "logical condition ? value_if_true : value_if_false", meaning that if the condition is true, the first value will be returned, else the last. It might be a bit confusing, because of the excessive usage of this operator, but you'll get used to it.

2. Random(x, y) function:

This will generate a random number between two values, the numbers are decimal. Most common use case is: int roll =Random(0, 100); In this case the "roll" variable will be used somewhere against a skill, critical or to hit check.


This a macro, it's a leftover of some old code, and it has been left there to note the old structure of the code. It is still used, but it is overridden to a static value, which makes the extra "cr" parameter useless. I keep using it and let the owner of the server who use this tutorial code to dispose of it if they want to. Basically, instead of this macro we could have used simply a value.


The LOCKPICK_TIMEOUT macro refers to this, and what this macro does transforms real time value into game value, hence the name "real".

5. Locker's parameters:

Lockers as simply Items, you can find a lot in mapper under container, and have 3 parameters regarding locking, which you can modify also in mapper.

   LockerId - key with the same Id can open this locker.
   LockerCondition - if 1, then it is open (but not necessarily unlocked, if not, then closed.
   LockerComplexity - this is used to measure the difficulty of the lock.

The new code fragment to replace the old parts with in the script file: lockers.fos

Simply replace the old part with the new part, I did not copy the whole file into pastebin, but left enough context ( a few extra lines) and comments, so you can find where to copy paste from.