stendhal
stendhal copied to clipboard
Idea: Implement Scripting Engine for Custom Games
I think it would be interesting to implement a scripting engine (using a language such as Lua would be my choice). Then use the scripts for configuring quests, NPCs, etc. alongside the xml implementation. It would be a lot of work to convert the current code & may not be worth it. But, it would make creating custom games using Stendhal much easier (in my opinion).
It should not be too hard to add Lua support to the existing scripting engine in https://github.com/arianne/stendhal/tree/master/src/games/stendhal/server/core/scripting
You can find example groovy scripts in the git history at https://github.com/arianne/stendhal/tree/f4fc003b4fcd2a814ecc0a4b5ace7a9485783805/data/script
They got rewritten into Java code because maintaining some quest in another language was too much effort. But the scripting engine with the sandbox, that allows removal of loaded objects, is still there and I assume it is fully functional.
So, I am not familiar with Groovy, though I've seen it mentioned. I just looked it up & looks like it is developed by Apache with Java in mind.
Would it be easier to use Groovy with Stendhal? I'm familiar with Lua because I have worked on some mods for Minetest.
Hi,
I created a wrapper for JSR223 and implemented support for Groovy and JavaScript (nashorn). With the wrapper I can use non JSR223 implementations as well, I do this for jexl, java classes and script references.
I define the scripts in configuration files which are reloaded by a file watcher.
Implementation here: https://github.com/codingchili/chili-game-ext/tree/master/services/realm/main/java/com/codingchili/instance/scripting
Example configuration here: https://github.com/codingchili/chili-game-ext/blob/master/prototype/conf/game/spells/regeneration.yaml
I have created a branch where I added support for Lua scripting via Luaj.
Edit: I plan to merge after v1.32 release.
Lua scripting support has been added. Closing this issue. I think it would be a good idea to separate the code into core
& game
directories. This would make it easier to create custom games.