[34] Lua Scripting

05/31/2021, 10:09pm

There's a bunch of new stuff in the works for Antorum. The biggest thing is probably Lua Scripting.

To test and prove out the scripting system, I built the tutorial for the game, or at least the first iteration of it. It's been helpful to feel out any requirements for the scripting system, as well as get a bunch of basic script endpoints set up so that other quests down the line can take advantage of them for interesting scenarios.

I used the rlua crate for the Lua implementation. I don't love Lua as a scripting language, but I wanted to integrate something that was simple to write, and well-known. I'll probably switch it up next time I do something like this for a game.

Dialog Scripts

Dialog trees now support Script nodes, allowing the execution of scripts based on dialog option choice (or just by talking to an NPC). This is how quests are started - dialog nodes trigger scripts which mutate the players quest stages or flags.

asmabius.toml // ... other dialog nodes ... [[nodes]] type = "Script" id = 140 script = """ player_ent_id = Context:player_ent_id() quest_res_id = 0 -- Clear player inventory and equipment but give them a map inventory_clear(player_ent_id) equipment_clear(player_ent_id) add_item(player_ent_id, "map-of-antorum", 1) set_quest_stage(player_ent_id, quest_res_id, 30) """ next_node_id = 123

Information about the game world is passed to these scripts via context objects. Different contexts (Like Dialog, Entity Spawn, Entity Killed by another entity, etc) contain different information about each event and the Entities involved in it. The lua scripts are essentially just callback functions, with the arguments being passed in this context object.

Entity Scripts

Scripts can also be directly embedded on an Entity, allowing execution based on various events. Here's an example of a script on the Tutorial Chonkrat NPC, which executes when a player tries to interact with it. In this case, it's meant to keep players from attacking the NPC before they have begun the Combat portion of the tutorial.

npc-tutorial-chonkrat.toml on_interaction_requested_lua = """ if OnInteractionRequestedContext:interaction_type() ~= "attack" then return end player_ent_id = OnInteractionRequestedContext:player_ent_id() if not get_quest_flag(player_ent_id, "tutorial-lesson-combat-started") then send_chat_message(player_ent_id, "You haven't started the Combat lesson yet. Speak to Asmabius first.") cancel_interaction(player_ent_id) return end tutorial_quest_res_id = 0 tutorial_quest_stage = get_quest_stage(player_ent_id, tutorial_quest_res_id) if get_quest_flag(player_ent_id, "tutorial-lesson-combat-finished") or tutorial_quest_stage == 14 then send_chat_message(player_ent_id, "You already killed a Chonkrat for Galus. Best leave them alone.") cancel_interaction(player_ent_id) return end if tutorial_quest_stage ~= 13 then send_chat_message(player_ent_id, "You should speak with Galus before trying to fight a Chonkrat.") cancel_interaction(player_ent_id) return end """

Music

There are three new music tracks in the game, by Electric Dad! He also made all the other tracks that have been added so far. Check out his Soundcloud and Spotify.

Other

Here's some of the other stuff that's been done recently. The changes are mostly based on alpha player feedback. This month has been kind of slow though, so there's not a lot else to report.

  • Added a second chat box, for "system" messages
  • Added a global chat channel (/all )
  • Added more combat messages for things like blocks and dodges
  • Logging into an account that is already logged in will now kick the already logged in client

- Declan (@dooskington)