June 24, 2017, 03:31:44 am


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


  • Posts: 222
  • Go for the eye, Boo! Go for the eyes!
    • View Profile
15. Modifying base mechanics - Only the easy parts.
« Reply #15 on: January 07, 2016, 06:10:33 pm »
15. Modifying base mechanics - Only the easy parts.
« Last Edit: January 07, 2016, 06:12:10 pm by Slowhand »


  • Posts: 222
  • Go for the eye, Boo! Go for the eyes!
    • View Profile
15.1 Modifying lock pick cooldown mechanic.
« Reply #16 on: January 07, 2016, 06:11:00 pm »
15.1 Modifying lock pick cooldown mechanic.

(Using Reloaded SDK source, version 2.)

This will be an example, how to spice up lock picking mechanic a bit, changing the value of cooldown from a static, to a dynamic value based on the player skill, tools used, lock difficulty and the 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.
« Last Edit: January 07, 2016, 06:24:22 pm by Slowhand »


  • Wiki Administrator
  • Global Moderator
  • Posts: 751
  • Gravity is just a theory. Try Density.
    • View Profile
Re: Basic Development Tutorial for FOnline. (Reloaded)
« Reply #17 on: January 21, 2017, 02:56:34 am »
This guide and the next one (advanced) are now being added to the wiki. I believe we all owe Slowhand a lot of thanks for this. It's EXACTLY what this community needs for possible junior developers to get started in a strong way. It must have taken a TON of time to do all of this, and i'm very pleased to finally get it on the wiki in the Guides section.

If you like this game and are thinking about writing some new content for it (stories/quests, maps, NPC dialogues and more), Slowhand has made it a lot easier for you to get started!