Archived

This topic is now archived and is closed to further replies.

Toolmaker

Using LUA in my MUD server

Recommended Posts

Toolmaker    967
I am currently developing a MUD server and I am almost at a point of starting to write the commands for the server(Movement, admin, fighting, spells, picking up items, etc.). After seeing the article about LUA on the main page I came up with the idea of making the command handler scripted while having a sort of API inside the server. My question however is, how will this look like? Should I write a class, CCommandHandler which will process the script any further? And how will I be able to have interaction between different objects? Because, I could even script my movement handler, battle system, etc. This are the classes I am thinking of getting scripted inside the server: - Movement(Changes current pos of the player and notifies players in the rooms that the player leaves and or arrives in a room). It uses the UserDB for this for interaction. - Command handling(Uses UserDB, battle system, item DB, spell DB, etc.). If a player executes a command, this system needs to trigger the appropriate action. - Battle system(Uses userDb, Race DB, etc.). Depending on different items the player is currently holding(Not in back pack) and depending on the race, the player will withstand some attacks easier then others. - Scripted actions. Some IRC style actions like .slap, .me, etc. - NPCs So, how would this work? I haven''t read the LUA article yet, but I will after finishing the user DB class(Only need to add some accessors). Toolmaker
-Earth is 98% full. Please delete anybody you can.

Share this post


Link to post
Share on other sites
Kylotan    10007
Strangely enough, I am about to embark on the same project, namely embedding Lua into a MUD.

One thing worth considering is whether you are doing this scripting just to make your life easier, or whether you intend extending it to your administrative players too, as that might influence the functions you expose to the outside world.

To be honest, your question is a bit vague, given that we have little knowledge of why you want to use Lua, who will use it, and what kind of functions it will tie into. If it''s just a case of scripting commands, you just need an interface from the command dispatcher to one of the commands in Lua, and Lua interfaces to whatever database manipulation you need. I firmly believe that you''ll only really know what functions you need to expose to Lua by trying to write your scripts and seeing what functionality you require.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

Share this post


Link to post
Share on other sites
Toolmaker    967
Thx for the reply Kylotan. Seems like I am about to start working on the first scripted system. I will read the LUA article and try some stuff before implementing the scripting into the server.

Toolmaker



-Earth is 98% full. Please delete anybody you can.

Share this post


Link to post
Share on other sites
Kylotan    10007
I''ve been thinking about things a bit more, my initial API will consist of 3 distinct layers.

The first layer locates characters, rooms, or objects, based on a set of criteria. eg. GetCharsHereByName would take a RoomID and return a table of CharacterIDs for the characters in the room. Some of the functions can take a predicate function as a parameter to further customise their behaviour.

The second layer will take a table of character, room, or object IDs and perform actions on them. This lets me deal damage, increase strength, bestow protections, etc. Since the first layer always returns a table of IDs, the second layer works just as well on multiple targets as it does on single ones.

With this system, many events are just 1 or 2 lines of code: one to locate the victim(s) and one to apply the results.

The 3rd layer will be a separate set of querying functions. This will probably be a set of several functions that operate on a single Character, Room, or Object ID, and some sort of aggregation functions such as Sum, Multiply, Maximum, Minimum, and Average functions that take a table of IDs plus one of the previous querying functions. Pretty much any value can be calculated in 1 or 2 lines that way.

Of course, that''s the theory. I''ve yet to put it into practice.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

Share this post


Link to post
Share on other sites