I have build my prey system in lua, the prey system has defense bonus when monsters attacks a player and has damage bonus when the player attacks the monster which is way easier to implement in C++ (maybe its doable with creaturescripts on onhealthchange), every time a monster damaged the player or the player damaged a monster the C++ code called a lua callback. Imagine AOE spells and the callback being called for each hit, for every player and monster, all the time, everywhere. It worked and my server handled 1500 players online without lags.
So i believe you can implement what you want in lua and worry about performance vs C++ later. Of course, you lua code should be optimized for better results.
Things like getSpectators, GetPathing and other stuff must be inside C++ because their performance in lua would be horrible, but most of the engine could be implemented in lua.
You also should only worry about this if you got many players(that is when performance matters), otherwise pick the easier and fastest way to implements thing which most of time is lua.
That is exactly the kind of reply I was looking for, people who actually have owned otservs with heavy Lua scripts. Thank you.
Depends on the code. In general Lua is the fastest scripting language available. If you are not going to implement custom pathfinding, world generator or anything heavy on calculations then you are completely fine. Ofc any code written in Lua will be slower than pure C++ but that's not the point. Who cares if the execution time is 1ms vs 2ms (well, as long as you are not executing that code 1000 times every second).
Well, my point is exactly about codes which are running all the time. For example, suppose that a server puts all attacks (from monsters and players) scripted in Lua. In this situation, 400 players simultaneously hunting could mean 1600 monsters actives trying to kill them, i.e, 2000 creatures executing attack scripts at the same. Assuming each one attacking once per 2 seconds and you would get that script being executed 1000 times every second.
Generally the more base kind of system it is, the more it belongs in c++. For example the market is one of core features and is something that doesn't give much room for customization so it's written in c++. I only moved market item descriptions to lua in my own fork because I will be writing some version 12 item bonuses in lua.
Another example is cyclopedia. Most people prefer it in c++ because they won't be customizing it. I wrote it in lua because it's easier to connect achievements to it this way plus my inspect system is in lua already.
I was more worried about how expensive is customizing everything in Lua, not actually discussing what should TFS allow customizing.
I think (almost) everything that can be done in Lua, should be done in Lua. I disagree with
@zbizu that market would be a good sample for a C++ use-case. The market should be flexible and adaptable, and is a perfect case to write entirely in Lua. The market isn't conceptually a high performance task. The default Lua code should comply with cip client behavior, but make it easy to modify to accomodate interesting and innovative otclient solutions.
I agree. But, in the other hand, I also understand that developers should carefully pick what should be easily customized, because it often means a more complex code, harder to mantain. So they've got to see if the trade off is worthy. Personally, for the Market I would say yes, but that is a subject for a different thread.
I think C++ should be used only where there is a significance performance increase for doing it, such as RSA encrypt/decrypt, thread handling, perhaps path finding, loading big binary objects, working with big chunks of hot memory.
There are lots of developers who has spent lots of time implementing stuff in C++, only to get the code removed and migrated to Lua later. (or get stuck in an obsolete distro, or in maintenance hell) Which is weird, it should be the other way. Start with Lua, if it performs too bad, stop coding like shit, if its still to bad, ask someone else to review your code and tell what is still shit, if its still to bad, look into a C++ solution.
Yes. But anyway it is interesting to foresee what is too heavy for Lua and avoiding the trouble of writing the code twice. I am particularly worried about scripts who might be called thousand of times per second (look at the example I wrote above when replying to
@oen432), that is why I felt that it was worthy to ask more experienced OT developers.
On
AcidsOT, I use
@Leo32's
Rarity Rolls & Custom Attributes Library
I have also rewritten
wand and rods attack behavior, as well as
paladin weapon behaviors. Entirely in Lua revscript. I'm about to start rewriting the attack behaviors of many knight weapons now. So far I havent had any performance issues on my server. (granted, I havent been able to stress test my server yet, with current online records around 25 players).
Even if I was looking for more extreme cases of heavy usage of Lua scripts, it was interesting to know. Thank you.
[offtopic] BTW, I was looking around the site of your OT and it seems very nice. A custom map with several cool custom features... It is a shame for this community that your base player is so small while so many stupid bayak servers easily get hundreds of players. I hope that your project gets more players, that is exactly the kind of server that opentibia needs. [/offtopic]
Cheers,
Assassina Mutante.