Cuberite Forum

Full Version: /give [player]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
how would you go about doing this in Lua, ive messed around with some of the other Lua files understanding the concepts of player, otherlayer, and splits but i cant get it right, be in the format of /give [player] [item id] [amount] i think i saw someone ask this a while back, and i dont remember who, but they said it was pointless, at that current point in time. if im hosting a server, i dont want just anyone to be able to use it other than setting permissions which is to general, this lua file, you type in /kit it gives you a fiew items to start off, how would you make it able to give it to a target? or is that not possible yet?
Give the player name along with /kit or /give, find it by using StringSplit and using the correct index of the split. Then use cWorld:GetPlayer( PlayerName ) and use THAT player to give items to instead of the Player parameter from KitCommand()
tyBig Grin ^_^, perhaps a quick example so i can get the context correctly
You could look at the /tp command in the Core plugin, as it takes a player name as its first argument (/tp [playername])

Code:
function HandleTPCommand( Split, Player )
    if( not Player:HasPermission( "core.teleport" ) ) then
        return false
    end
    
    local Server = cRoot:Get():GetServer()
    if( #Split ~= 2 ) then
        Server:SendMessage( cChatColor.Green .. "Usage: /tp [PlayerName]", Player )
        return true
    end
    local World = cRoot:Get():GetWorld()
    local OtherPlayer = World:GetPlayer( Split[2] )
    if( OtherPlayer == nil ) then
        Server:SendMessage( cChatColor.Green .. "Can't find player " .. Split[2], Player )
    elseif( OtherPlayer == Player ) then
        Server:SendMessage( cChatColor.Green .. "Already there :)", Player )
    else
        Player:TeleportTo( OtherPlayer )
        Server:SendMessage( cChatColor.Green .. "You teleported to "..OtherPlayer:GetName().."!", Player )
        Server:SendMessage( cChatColor.Green .. Player:GetName().." teleported to you!", OtherPlayer )
    end
    return true
end
i see i see, alright thanks. good luck with -r174