Lua Scripting

The game has a very young Lua API that interacts with most of the game components, like Teams, Players and Mobs. In this post we'll explain the functions and features of this API and how you can use it for your minigames to have a better interaction in your games or Plugin Packs.

## Lua is ❤

In the Lua Website, it's defined *a powerful, efficient, lightweight and embeddable scripting language,* made to be used within other languages, like C or C++. It's Embeddable, so you can use it as a complementary language for your program, game or whatever you can add some .dll/.so library.

### Lua as the main (and the complementary) Language.

Lua in 2018 has an Amazing community of developers, this is because some years ago a library and game framework was released, it's called LÖVE (or Love2D), it's being used by games like Move or Die and many others.

Lua is also being used by many moddable games, like World of Warcraft, Garry's Mod, and this game: Mini World!

## Mini World, Lua and You.

Mini World is running a C++ Lua Virtual Machine, that is actually running another Lua Scripts that the game requires, I can even say that their own webpage and servers are running using Lua with OpenResty, awesome! But, going back to the main thing, the API:

The API is uncomplete, so there's no "full" documentation of it, that sucks! But, hey, someone just documented the few ones!

The game has two APIs, one is for Dev Mode minigames, and the other one is for manipulating mobs physics, we are going to see the Dev Mode scripts, that they're called **wsc** scripts. These can extend your games with ease if you know what you are doing. An example of a cool script can be my own, minispect, a \*untested\* script that is able to make someone a spectator at the game start by killing it at the very start, but it works only if your game has the spectate on die feature activated.

This is the script:

`wes_gamestart = function()`

`local judge = ClientCurGame:getUsername()`

`ClientCurGame:sendChat(judge.. ' has entered in Spectator Mode!', 1)`

`if judge == "realFeik" then`

`judge:kill();`

`elseif judge:getUin == 872134 or judge:getUin == AccountManager:getUin()`

`judge:kill();`

`end`

`end`

Let's split it for a better explanation:

`wes_gamestart = function()` it's initializing the API, this function will run on every game start.

`local judge = ClientCurGame:getUsername()` **judge** it's being defined with a function, ClientCurGame:getUsername(), that will get all usernames from the match.

`ClientCurGame:sendChat(judge.. ' has entered in Spectator Mode!', 1)` will send a message when the player got in spectator mode, it's being interpolated with the **judge** variable.

I'm going to explain this with the full structure:

`if judge == "realFeik" then`

`judge:kill();`

`elseif judge:getUin == 872134 or judge:getUin == AccountManager:getUin()`

`judge:kill();`

`end`

This is a declaration, if the judge variable equals to "realFeik" then it will kill me, else if the judge UID equals to 872134 or the judge UID equals to the AccountManager UID then it will kill me, the end it's for ending the declaration.

## Main Functions

Before when I was explaining wes\_gamestart, I said that is something that will be executed and interpreted every game start. Well, this one is not the only one:

**wes\_player\_revive(player)** is going to be executed when **player** respawned.

**wes\_player\_die(player, killedby)** is for killing and scoring purposes, with this you can make custom kill messages or even store the kills and make some kind of database. Cool, right?

**wes\_game\_timeover** is going to be executed when the map has a limited time and that limited time ended.

**wes\_gamerun** is going to be executed when the goal has been made, you can set this programatically.

## Useful Features

This very young API gives million of possibilities for coding, I'm going to explain the most useful Features (functions, tricks, tips) to start making scripts.

**ClientCurGame:sendChat(message, 1)**

This one can send messages like some kind of broadcast chat (if you put that 1 at the end), it can be used to explain the rules or for warning about the time.

**ClientCurGame:getRandomPlayer()**

If you want to make something like a Murder Mistery game, this one is for you, define it into a variable to get better results (recommended: player, people, murder), this one will select a Random Player from the online people.

**<variable>:setTeam(teamnumber)**

This can complement **getRandomPlayer()**, **<variable>** is the variable you assigned, (it can be the one that you made using the **getRandomPlayer** function), it will the team for that variable to the **teamnumber** team.

## and more to come!

Mini Wan mentioned that in a future the API will be extended. By this time, if you want to see a well-structured Lua Script, you should check out Wildman's Coming Plugin Pack, that is exposed to the public in your game files or via this Pastebin Note.

## References

1. ↑ In computer programming, an **application programming interface** (**API**) is a set of subroutine definitions, communication protocols, and tools for building software. In general terms, it is a set of clearly defined methods of **communication** between various components.
2. ↑ The Lua Website is the homepage of Lua, where they document and explain all the functions and APIs of both Library and Scripting Language.
3. ↑ **C** (/siː/, as in the letter *c*) is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, and therefore it has found lasting use in applications that had formerly been coded in assembly language, including operating systems, as well as various application software for computers ranging from supercomputers to embedded systems.
4. ↑ **C++** (/ˌsiːˌplʌsˈplʌs/ "see plus plus") is a general-purpose programming language. It has imperative, object-oriented and generic programming features, while also providing facilities for low-level memory manipulation.
5. ↑ LÖVE is an \*awesome\* framework you can use to make 2D games in Lua. It's free, open-source, and works on Windows, Mac OS X, Linux, Android and iOS.
6. ↑ 20 seconds, constantly changing mechanics and a lot of yelling. These are the keywords that perfectly describe a round of Move or Die, the **4-player friendship ruining party game** where rules change every single round.
7. ↑ A mod (short for "modification") is an alteration by players or fans of a video **game**that changes some aspects or one aspect of a video **game**, such as how it looks or behaves.
8. ↑ ***World of Warcraft*** (***WoW***) is a massively multiplayer online role-playing game (MMORPG) released in 2004 by Blizzard Entertainment.
9. ↑ ***Garry's Mod*** (***GMod***) is a sandbox physics game created by Garry Newman and developed by his company, Facepunch Studios. *Garry's Mod* was originally a mod for Valve Corporation's *Half-Life 2* but was later made into a standalone release in 2006 for Microsoft Windows, published by Valve Corporation. Later updates saw an OS X port, added in 2010, and a version for Linux in 2013.
10. ↑ In computing, a **virtual machine** (**VM**) is an emulation of a computer system. **Virtual machines** are based on computer architectures and provide functionality of a physical computer. Their implementations may involve specialized hardware, software, or a combination.
11. ↑ OpenResty® is a full-fledged web platform that integrates the standard Nginxcore, LuaJIT, many carefully written Lua libraries, lots of high quality 3rd-party Nginx modules, and most of their external dependencies. It is designed to help developers easily build scalable web applications, web services, and dynamic web gateways.
12. ↑ A Lua Script that activates spectator mode to a specific UID at the start of the game. (deprecated since creator moved up its creations)
13. ↑ In the mathematical field of numerical analysis,**interpolation** is a method of constructing new data points within the range of a discrete set of known data points.
14. ↑ Mini Wan is the Community Manager, a Mini Captain and the voice that post new updates of the game.

Made with ❤ by realFeik.

Mini World Connoisseur (talk) 21:04, 13 September 2018 (UTC)