v1.0.0

Sea

A powerful framework for CS2D modding. Build clean, organized, and robust mods with minimal hassle.

Docs

Say Hi to Better Modding

CS2D has mostly been home to small, casual mods — tweaks here and there, nothing too heavy. But in the shadows, a few developers pushed the limits, building massive, complex mods with barely any tools. Those developers know the pain: messy code, clunky systems, and a frustrating development experience. Sea is here to change that. It takes care of the hassle behind the scenes, giving you clean, powerful tools so you can focus on what matters most — your mod.

Features

Sea transforms every entity (not only the map entities, but also players, objects, images, NPCs, items, etc.) to an instance that is initialized from a class using metatables.

This simply lets you not have to use the good old CS2D API functions such as parse(), player(), object(), item() and pass the related ID every time. Here's the comparison:

To retrieve a player's health, instead of this:

player(id, 'health')

You do this:

player.health

To set a player's health, instead of this:

parse('sethealth '..id..' 100')

You do this:

player.health = 100

To most people this would be a lot cleaner and easy to work with. Especially once that parse uses goes a little too long - if you know what I mean.

Sea also transforms hooks to so-called events. This is necessary since CS2D API passes the regular arguments to the hooked functions; Sea initially loads all the hooks and then creates its own events to parse the arguments to transform them to instances.

To listen an event (similar to registering a function to a hook), you use the sea.listen() function:

sea.listen('join', function(player)
    player:message('Welcome to the server, '..player.name..'!')
end)

We don't allow addhook()s here.

Sea has the dedicated apps directory for your mods. Every time you open your server, Sea checks the content of this directory and try to load the apps within.

App simply means a directory and inside contains its scripts, config.lua, and main.lua file that are required for Sea to acknowledge it as an app.

You can have as many apps as you want, and they can all work indepentant from each other (still, it is a good habit to lookout for potential conflicts).

To give you an idea, your apps folder can include these apps: apps/vote-map/, apps/chat-color/, apps/admin/, apps/leaderboard/, etc.

Rather than deleting your apps, disabling them is as easy as just putting ".disabled" suffix into their directory name. So you just can keep them where they belong while not getting loaded.

Sea can automatically save and load player and game states. This, of course, requires app configuration so Sea knows what to save and load.

Players also have the choice to save either with their USGN ID or Steam ID.

This by default happens during join and leave hooks. But you are able to call the players methods to do it whenever you want:

player:save()
player:load()

Sea automatically generates the servertransfer.lst file for you. This means you don't have to manually enter every path of your files to be downloaded for players who join your server.

This is done by simply supplying the directory paths of your files like gfx/masea/tibia/ in your app configuration and as soon as the server is open for the first time, Sea is done with writing all the file paths found in that directory to be ready in the next server start.

It is a known fact in the community that it is cumbersome (and risky) to deal with HUD texts and images in CS2D. Sea provides a set of UI elements that you can use to create your own user interfaces.

These will let you not to worry if freeimage() actually frees the image you want to free. Moreover, HUD text IDs are handled behind the scenes, so you don't have to worry about them either.

UI elements are also instances just like entities, and player instance has its ui instance automatically created once they join to server. This means you can use the player.ui instance to create UI elements for that player:

player.ui:createText('USGN ID: '..player.usgn, 100, 100)
player.ui:createPanel('gfx/masea/hello.png', 200, 200)

Inspirations and samples

You might want to check out what has been made with Sea so far:

Get started with Sea

Docs