Howdy pardner!

These here forums are read-only. Click here to go to the new forums, where you can actually post and stuff!

Sorry for the inconvenience

-Andrew

This thread will be used to show some examples of basic, and advanced Lua scripts for D3 Servers.

For your reference throughout this, the Lua documentation for D3 can be found Here

Basic Stuff

This covers where you should put your Lua scripts and why, as well as a few standards with the D3 Software that you may or may not follow.

First, you will of course open the "Lua" folder in your server. Within this, you have many different folders.

Buildmodes, Commands, Events, Gamemodes, Map_Fill, Map_Style, Physic.

Each of these is aptly named for what type of scripts are contained in them. For example, in Map_Fill, you will find only Lua scripts that produce map fills (The scripts are all Map Generators)

Buildmodes, you will find things such as /box, /paint, and so on.

It is recommended that you continue to follow these standards. However, if you choose not to, you should at least create your own folder with your name (In my case, a folder called "umby24") with your scripts inside.

Lua behavior for the D3 software, like most other files for the server, is that whenever the file is changed the server will automatically reload the script. This allows you to make large changes and add functionality to your server without restarting your server.

Finally, to finish off the "Basic Stuff" Category, at the bottom of every Lua file, it is a standard to include a line such as this:

System_Message_Network_Send_2_All(-1, "&4Script reloaded!")

This will send a message to everyone on the server, alerting them that the script has been reloaded (In dark red text). It is common to include the name of the file in the reload message, but that is up to you.

D3 Helloworld Plugin

This is really simple! Just create a new file in notepad, notepad++, whatever you would like to use. Then enter...

System_Message_Network_Send_2_All(-1, "Hello world!")

and save the file as "helloworld.lua". Once you have saved the file, you should see the text "Hello world!" sent to everyone on the server! Congratulations on your first D3 plugin.

D3 Helloworld Command

This one is a bit different. If you are going to go here, I highly recommend using the D3 GUI, as it will simply this process for you greatly.

First, in your helloworld.lua file from before, you will need to make a function. You can name this whatever you want, but there are require arguments for your command.

Here is an example.

function Command_Helloworld(Client_ID, Command, Text_0, Text_1, Arg_0, Arg_1, Arg_2, Arg_3, Arg_4)
    System_Message_Network_Send(Client_ID, "Hello world!")
end

So before this command will work, you will need to go into the D3 GUI, the Commands section, and click the "+" sign to add a command. You can use "helloworld" for both the internal name, and the command that will be used to trigger it.

Next, for this example, you would enter "Lua:Command_Helloworld" in the "Plugin" field, then click save.

Now whenever you type /helloworld, the function you defined from above will be run.

Something different about this command, is you will notice I am using the function System_Message_Network_Send instead of Send_2_All. This means the message will only be sent to a single player.

Next, I am using the Client_ID Provided to the command function, so the message will be sent only to the person who used the command.

Specific Topics

This will cover the usage of specific Lua functions of the server, including map fills, map styles, and commands.

Mapfills

Any Lua functions that start with "Mapfill_" Will automatically be registered as a Map Fill with the server. So if the full function name was Mapfill_Helloworld, then the corresponding command to run that function would be /mapfill Helloworld.

If you are creating a mapfill, it is recommended that you change blocks using Map_Block_Change function with the "Send" field set to 0.

Mapfills can be as simple or as complex as you want. Here is a simple flatgrass mapfill example. (This is included with all D3 servers, as mapfill "standart")

function Mapfill_standart(Map_ID, Map_Size_X, Map_Size_Y, Map_Size_Z)

    for ix = 0, Map_Size_X-1 do
        for iy = 0, Map_Size_Y-1 do
            for iz = 0, Map_Size_Z/2-1 do
                if iz == Map_Size_Z/2-1 then
                    Map_Block_Change(-1, Map_ID, ix, iy, iz, 2, 0, 0, 0, 0)
                else
                    Map_Block_Change(-1, Map_ID, ix, iy, iz, 3, 0, 0, 0, 0)
                end
            end
        end
    end

end

However, as map fills can use the full ability of Lua and every function that the server extends to Lua, you can make map fills as complex as you want. An example is the City map fill by WolfX. This is a long script, so for sake of space, You can find it Here.

AndrewPH time for dominate Sat Dec 21 at 7:17:23 (2013)
This post has been hidden by the ClassiCube moderation team.

Uh... I don't know anything about scripting or developing things.... -.- Its hard to make Classic servers... :(

I don't even know what Lua is..

[Removed]

++lxl_BEAST_lxl posted:++

Uh... I don't know anything about scripting or developing things.... -.- Its hard to make Classic servers... :(

I don't even know what Lua is..

Lua is a scripting language. You don't need to develop anything to use the server, this is just for those who wish to do so. That's why it's in the programming topic!

What is a scripting language of lua? How do I not need help to develop anything to use the server? Uh... I don't know some of the things about these classic servers... :(

Lua is a scripting language, easy to use and easy to extend.

You don't NEED to use it if you use the D3 server, it's just a nice thing to play around with if you want to extend the server more.

A lot of the server's features run off of these scripts, so you can browse through them and check it out.

This post has been hidden by the ClassiCube moderation team.
This post has been hidden by the ClassiCube moderation team.

Lua is usually used as a simple script that is embedded into games, but there are some games programmed entirely in Lua, such as ROBLOX.

🛑 This thread has been set to read-only due to inactivity. 🛑