stendhal icon indicating copy to clipboard operation
stendhal copied to clipboard

Idea: Implement Scripting Engine for Custom Games

Open AntumDeluge opened this issue 6 years ago • 4 comments

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).

AntumDeluge avatar Aug 04 '18 20:08 AntumDeluge

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.

nhnb avatar Aug 05 '18 16:08 nhnb

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.

AntumDeluge avatar Aug 05 '18 21:08 AntumDeluge

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

codingchili avatar Jan 30 '19 12:01 codingchili

I have created a branch where I added support for Lua scripting via Luaj.

Edit: I plan to merge after v1.32 release.

AntumDeluge avatar Dec 12 '19 00:12 AntumDeluge

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.

AntumDeluge avatar Jan 21 '24 21:01 AntumDeluge