Cuberite Forum
Plugin developement - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: Plugin developement (/thread-857.html)

Pages: 1 2 3


Plugin developement - tonibm19 - 04-14-2013

I want to learn Lua, to make plugins for MCServer. Any good tutorial?
I'm 14 years old and I programmed in HTML, PHP and Python (I only know the basics).
Thank you.


RE: Plugin developement - NiLSPACE - 04-14-2013

well i also only know the basics but i reccommend looking at the api.txt for all the avalible functions and also look at other plugins like the core for an example.


RE: Plugin developement - tonibm19 - 04-14-2013

(04-14-2013, 10:08 PM)STR_Warrior Wrote: well i also only know the basics but i reccommend looking at the api.txt for all the avalible functions and also look at other plugins like the core for an example.
Where is the api.txt?
I don't know the basics of Lua, so I want a tutorial, do you know a good one?


RE: Plugin developement - NiLSPACE - 04-14-2013

if you enable the debuggers plugin it should generate a api.txt.
i am realy bad in creating tutorials especially in programming since i just started programming so i propably can't help you with that.


RE: Plugin developement - tonibm19 - 04-14-2013

(04-14-2013, 10:29 PM)STR_Warrior Wrote: if you enable the debuggers plugin it should generate a api.txt.
i am realy bad in creating tutorials especially in programming since i just started programming so i propably can't help you with that.
Ok, I found one, but for now I only can print a message, I've done my first Hello World in Lua Smile (too easy)


RE: Plugin developement - NiLSPACE - 04-14-2013

if Taugeshtu came online again he could propably explain everything very well. he is pretty skilled ;P


RE: Plugin developement - FakeTruth - 04-14-2013

You have probably already noticed that most programming languages look a lot like each other since you've played with PHP and Python. Even though the way you write the code is different, the idea behind it is pretty much the same (if/else/while/etc.)

I think the best way to learn how to create plugins for MCServer is to look at the already existing plugins. For example look at MCServer\Plugins\Core\main.lua
The Core main.lua file contains the initialize functions and stuff to start the plugin. It binds commands and links hooks to functions.

Another extremely simple plugin is the ChatLog plugin MCServer\Plugins\ChatLog\plugin.lua.

The way MCServer starts plugins is by loading ALL the files in the plugin folder (order does not matter) and then it calls the Initialize() function. The Initialize() function can be in any of the .lua files, but there should only be one Smile
MCServer basically loads all plugin files into a single plugin, so you could create the biggest plugin ever in just a single file, but it's easier for the programmer to split plugins up into multiple files so they won't get lost in the complexity of the plugin.


RE: Plugin developement - tonibm19 - 04-14-2013

I'm trying to make /tpa, and integrate it into Core. For now, when you type /tpa and you have the core.tpa permision you send a request to other player, and when you do it, you recieve the message: teleport request send and the other player receives the message: Player has sent you a teleport request, type /tpaccept to accept it. The problem is that I don't know to make that if a player types /tpaccept, the player that has sent the request teleport to the other player. How can I do it?


RE: Plugin developement - NiLSPACE - 04-15-2013

i have an idea but i'm not sure if it works with the code you made. could you post it with
Code:
[shcode=lua]CODE HERE[/shcode]
?


RE: Plugin developement - tonibm19 - 04-15-2013

(04-15-2013, 12:04 AM)STR_Warrior Wrote: i have an idea but i'm not sure if it works with the code you made. could you post it with
Code:
[shcode=lua]CODE HERE[/shcode]
?
The code it's based on teleport.lua, it's very similar.
Code:
function HandleTPACommand( Split, Player )
    if( Split[2] == nil )  then
        Player:SendMessage( cChatColor.Green .. "Usage: /tpa [PlayerName] (-h)" )
        return true
    end
    
    local TeleportDestination = function(OtherPlayer)
        if( OtherPlayer == Player ) then
            Player:SendMessage( cChatColor.Green .. "Already there :)" )
        else
                     Player:SendMessage( cChatColor.Green .. "Teleport request sent" )
                     OtherPlayer:SendMessage( cChatColor.Green .. Player:GetName().." has sent you a teleport request, type /tpaccept to accept it" )            
        end
    end
    World = Player:GetWorld()
    if (not(World:DoWithPlayer(Split[2], TeleportDestination))) then
        Player:SendMessage( cChatColor.Green .. "Can't find player " .. Split[2] )
    end
    return true
end