Jump to content

Ban


xeon17

Recommended Posts

Hello , i'm try to create a ban command like /iban serial of player , days , reason

The script is before 3 mounths , i found today but still no know to fix :/

if anyone can fix my script please and tell me what's wrong.

function banCommand(player, command, serial, strtime ...) 
  
            local target = getPlayerSerial(target) 
  
            if(target) then 
  
                                local length = tonumber(strtime) or 2 
                local args = { ... } 
  
                local reason = "" 
  
                for k,v in pairs(args) do 
  
                    reason = reason .. ' ' .. v 
  
                end 
  
                if(reason ~= "") then 
  
                    outputChatBox ( "O Serial " .. getPlayerSerial(target) ..  "(" .. id .. ") " ..  "foi banido por "  .. getPlayerName(player) ..  "(" .. (getPlayerID(player) or "???") .. ") -> (motivo:" .. reason .. ").", root, 0, 236, 255) 
  
                else 
  
                    outputChatBox ( "O jogador " .. getPlayerName(target) ..  "(" .. id .. ") " ..  "foi banido por "  .. getPlayerName(player) ..  "(" .. (getPlayerID(player) or "???") .. ").", root, 0, 236, 255) 
  
                end 
  
                addBan(nil, nil, serial,player,reason,legh) 
  
            else 
  
                outputChatBox ( "[ERRO] Player  (" .. id .. ") não encontrado. ", player, 255, 0, 0) 
  
            end 
  
        else 
  
            outputChatBox ( "[ERRO] ID  (" .. id .. ") invalido. ", player, 255, 0, 0) 
  
        end 
  
    else 
  
        outputChatBox ( "[servidor] use: /iban [serial] [days] [reason]", player, 255, 255, 255) 
  
    end      
  
end 
  
addCommandHandler("iban", banCommand , true) 
  

Link to comment

This code makes almost 0 since at all.

An example, you have defined target to get the player serial of target (which is never defined in the first place) and then you wrote getPlayerSerial ( target ) and getPlayerName ( target ). This means, you're trying to get the serial and name of a serial?

Link to comment

Oh , the outputchatbox is wrong i know i not tried to do something with it. It's from a other version of ban command i created.

I Wanted to create a command like /iban (serial of player ) ( number of days how much he'll be banned ) and reason of ban.

function banCommand(player, command, id, ...) 
  
    if(id) then 
  
        local playerID = tonumber(id) 
  
        if(playerID) then 
  
            local target = getPlayerFromID(playerID) 
  
            if(target) then 
  
                local args = { ... } 
  
                local reason = "" 
  
                for k,v in pairs(args) do 
  
                    reason = reason .. ' ' .. v 
  
                end 
  
                if(reason ~= "") then 
  
                    outputChatBox ( "O jogador " .. getPlayerName(target) ..  "(" .. id .. ") " ..  "foi banido por "  .. getPlayerName(player) ..  "(" .. (getPlayerID(player) or "???") .. ") -> (motivo:" .. reason .. ").", root, 0, 236, 255) 
  
                else 
  
                    outputChatBox ( "O jogador " .. getPlayerName(target) ..  "(" .. id .. ") " ..  "foi banido por "  .. getPlayerName(player) ..  "(" .. (getPlayerID(player) or "???") .. ").", root, 0, 236, 255) 
  
                end 
  
                banPlayer(target, player, reason) 
  
            else 
  
                outputChatBox ( "[ERRO] Player  (" .. id .. ") não encontrado. ", player, 255, 0, 0) 
  
            end 
  
        else 
  
            outputChatBox ( "[ERRO] ID  (" .. id .. ") invalido. ", player, 255, 0, 0) 
  
        end 
  
    else 
  
        outputChatBox ( "[servidor] use: /iban [id] [motivo]", player, 255, 255, 255) 
  
    end      
  
end 
  
addCommandHandler("iban", kickCommand, true) 

Link to comment

I haven't tested it, but you can try to use this function:

(I re-wrote it because I don't like fixing codes xD)

function banCommand ( plr, cmd, serial, days, ... ) 
    if ( not serial or not days or not ... or not tonumber ( days ) ) then 
        return outputChatBox ( "Syntax error. /"..tostring(cmd).." [serial] [days] [reason]", plr, 255, 0, 0 ) 
    end 
  
    local days = math.floor ( tonumber ( days ) ) 
    if ( days <= 0 ) then 
        return outputChatBox ( "Invalid number of days. Must be greater than 0", plr, 255, 0, 0 ) 
    end 
  
    local ip = nil 
    local username = nil 
    local reason = table.concat ( { ... }, " " ) 
    local time = ( ( days * 24 ) * 60 ) * 60 -- I think the math is right 
  
    -- handle the player kick 
    for i, v in pairs ( getElementsByType ( "player" ) ) do 
        if ( getPlayerSerial ( v ) == serial ) then 
            ip = getPlayerIP ( v ) 
  
            local acc = getPlayerAccount ( v ) 
            if ( not isGuestAccount ( acc ) ) then 
                username = getAccountName ( acc ) 
            end 
  
            kickPlayer ( v ) 
        end 
    end 
  
    addBan ( ip, username, serial, plr, reason, time ) 
end  
addCommmandHandler ( "iban", banCommand ) 

Link to comment

LOL. A typo at last line. (addCommmandHandler -- loooooooooooooool )

  
function banCommand ( plr, cmd, serial, days, ... ) 
    if ( not serial or not days or not ... or not tonumber ( days ) ) then 
        return outputChatBox ( "Syntax error. /"..tostring(cmd).." [serial] [days] [reason]", plr, 255, 0, 0 ) 
    end 
  
    local days = math.floor ( tonumber ( days ) ) 
    if ( days <= 0 ) then 
        return outputChatBox ( "Invalid number of days. Must be greater than 0", plr, 255, 0, 0 ) 
    end 
  
    local ip = nil 
    local username = nil 
    local reason = table.concat ( { ... }, " " ) 
    local time = ( ( days * 24 ) * 60 ) * 60 -- I think the math is right 
  
    -- handle the player kick 
    for i, v in pairs ( getElementsByType ( "player" ) ) do 
        if ( getPlayerSerial ( v ) == serial ) then 
            ip = getPlayerIP ( v ) 
  
            local acc = getPlayerAccount ( v ) 
            if ( not isGuestAccount ( acc ) ) then 
                username = getAccountName ( acc ) 
            end 
  
            kickPlayer ( v ) 
        end 
    end 
  
    addBan ( ip, username, serial, plr, reason, time ) 
end 
addCommandHandler ( "iban", banCommand ) 
  

Fixed code

Link to comment
You no understand ._. i wan't to create the command to ban players when they are offline
I haven't tested it, but you can try to use this function:

(I re-wrote it because I don't like fixing codes xD)

function banCommand ( plr, cmd, serial, days, ... ) 
    if ( not serial or not days or not ... or not tonumber ( days ) ) then 
        return outputChatBox ( "Syntax error. /"..tostring(cmd).." [serial] [days] [reason]", plr, 255, 0, 0 ) 
    end 
  
    local days = math.floor ( tonumber ( days ) ) 
    if ( days <= 0 ) then 
        return outputChatBox ( "Invalid number of days. Must be greater than 0", plr, 255, 0, 0 ) 
    end 
  
    local ip = nil 
    local username = nil 
    local reason = table.concat ( { ... }, " " ) 
    local time = ( ( days * 24 ) * 60 ) * 60 -- I think the math is right 
  
    -- handle the player kick 
    for i, v in pairs ( getElementsByType ( "player" ) ) do 
        if ( getPlayerSerial ( v ) == serial ) then 
            ip = getPlayerIP ( v ) 
  
            local acc = getPlayerAccount ( v ) 
            if ( not isGuestAccount ( acc ) ) then 
                username = getAccountName ( acc ) 
            end 
  
            kickPlayer ( v ) 
        end 
    end 
  
    addBan ( ip, username, serial, plr, reason, time ) 
end  
addCommandHandler ( "iban", banCommand ) 

Just type /iban [serial] [days] [reason]

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...