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:

Let's split it for a better explanation:

it's initializing the API, this function will run on every game start.

judge it's being defined with a function, ClientCurGame:getUsername, that will get all usernames from the match.

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:

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.

 :setTeam(teamnumber)

This can complement getRandomPlayer,   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 =

Made with ❤ by realFeik.

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