Jump to content

Question Script


WASSIm.

Recommended Posts

Posted

You have to manage the bans by yourself. Create a a custom ban function, similar to the original banPlayer, wich saves the ban's details somehow (eg. in an xml file). And check the players when they join or just connect (onPlayerJoin or onPlayerConnect), wether they IP/serial is in your custom banlist. If it is, then don't let them spawn, just write something on the screen.

Posted

i have this

idk how make this

name="Joe" serial="123" time="57348957" reason="no reason"

function getPlayerFromSerial(serial) 
    if serial and type(serial) == "string" then 
        for i, v in ipairs(getElementsByType("player")) do 
            if getPlayerSerial(v) == serial then 
                return v 
            end 
        end 
    end 
    return false 
end 
  
local theFile = xmlLoadFile ( "banlist.xml" ) 
if not ( theFile ) then 
    theFile = xmlCreateFile( "banlist.xml","banlist" ) 
end 
xmlSaveFile( theFile ) 
  
addEvent( "getBanlistedPlayers", true ) 
function getBanlistedPlayers ( ) 
    local BansTable = {}  
    local theBans = xmlNodeGetChildren( theFile ) 
    for i, theNode in ipairs( theBans ) do 
        if ( getPlayerFromSerial ( xmlNodeGetValue( theNode ) ) ) then 
            table.insert(BansTable,getPlayerFromSerial( xmlNodeGetValue( theNode ) ) ) 
        end 
    end 
    return BansTable 
end 
addEventHandler( "getBanlistedPlayers", root, getBlacklistedPlayers ) 
  
function addPlayerBanlisted ( thePlayer ) 
    local nodeExists = false 
    local playerSerial = getPlayerSerial(thePlayer) 
    if ( thePlayer ) and ( playerSerial ) then 
        local theBans = xmlNodeGetChildren( theFile )  
        if #theBans >=1 then  
            for i, theNode in ipairs( theBans ) do 
                if ( xmlNodeGetValue( theNode ) == tostring(playerSerial) ) then  
                    nodeExists = true 
                end 
            end 
            if not nodeExists then  
                xmlNodeSetValue( xmlCreateChild( theFile, "userSerial" ), tostring ( playerSerial ) ) 
                xmlSaveFile( theFile ) 
                return true 
            else 
                return false 
            end 
        else 
            xmlNodeSetValue( xmlCreateChild( theFile, "userSerial" ), tostring ( playerSerial ) ) 
            xmlSaveFile( theFile ) 
            return true 
        end 
    end 
end 
  
function removePlayerBanlisted ( thePlayer ) 
    local playerSerial = getPlayerSerial(thePlayer) 
    if ( thePlayer ) and ( playerSerial ) then 
        local theBans = xmlNodeGetChildren( theFile ) 
        for i, theNode in ipairs( theBans ) do 
            if ( xmlNodeGetValue( theNode ) == tostring(playerSerial) ) then  
                xmlDestroyNode ( theNode ) 
            end 
        end 
    end 
end 
  
function isPlayerinBanlisted ( thePlayer ) 
    local playerSerial = getPlayerSerial(thePlayer) 
    if ( thePlayer ) and ( playerSerial ) then 
        local theBans = xmlNodeGetChildren( theFile ) 
        for i, theNode in ipairs( theBans ) do 
            if ( xmlNodeGetValue( theNode ) == tostring(playerSerial) ) then  
                return true 
            else 
                return false 
            end 
        end 
    end 
end  
  
function onPlayerBanlisted ( _, _, _, serial ) 
    if ( serial == isPlayerinBanlisted ( source ) )then 
        cancelEvent(true) 
    end 
end 
addEventHandler("onPlayerJoin",getRootElement(), antilogout) 

Posted

There is an example of how you can save it. It only demonstares the saving ( and error checking ) nothing else.

local banlist = xmlLoadFile ( "banlist.xml" ) or xmlCreateFile ( "banlist.xml", "bans" ) 
  
--customBanPlayer ( player playerToban, [ bool IP, bool serial, player/string resbonsiblePlayer, string reason, int(seconds) unbanTime ] ) 
 function customBanPlayer ( playerToBan, IP, serial, resbonsiblePlayer, reason, unbanTime ) 
    assert ( isElement ( playerToBan ) and getElementType ( playerToBan ) == "player", "Bad player element" ) 
    IP = IP 
    if not IP and not serial then 
        IP = true 
    end 
    serial = serial or false 
    reason = reason or "" 
    time = time or 0 
    if isElement ( resbonsiblePlayer ) and getElementType ( resbonsiblePlayer ) == "player" then 
        resbonsiblePlayer = getPlayerName ( resbonsiblePlayer )    
    end 
     
    local newBan = xmlCreateChild ( banlist, "ban" ) 
    xmlNodeSetAttribute ( newBan, "Name", getPlayerName ( playerToBan ) ) 
    xmlNodeSetAttribute ( newBan, "IP", IP and getPlayerIP ( playerToBan ) or "" ) 
    xmlNodeSetAttribute ( newBan, "Serial", serial and getPlayerSerial ( playerToBan ) or "" ) 
    xmlNodeSetAttribute ( newBan, "Banner", resbonsiblePlayer or ""  ) 
    xmlNodeSetAttribute ( newBan, "Reason", reason ) 
     
    local currentTime = getRealTime().timestamp 
    xmlNodeSetAttribute ( newBan, "Bantime", currentTime ) 
    if unbanTime > 0 then 
        xmlNodeSetAttribute ( newBan, "Unbantime", currentTime + unbanTime ) 
    end 
     
    --xmlSaveFile ( banlist )     
    --kickPlayer ( playerToBan, "Banned" .. (reason ~= "" and ": " .. reason or "" ) ) 
end 

Posted

thank you :D

why this not working

function getPlayerBanSerial ( thePlayer ) 
    assert ( isElement ( thePlayer ) and getElementType ( thePlayer ) == "player", "Bad player element" ) 
    local playerSerial = getPlayerSerial(thePlayer) 
    if ( thePlayer ) and ( playerSerial ) then 
        local theBans = xmlNodeGetChildren( banlist ) 
        for i, theNode in ipairs( theBans ) do 
            local theValue = xmlNodeGetAttribute( theNode, "Serial" ) 
            if ( theValue == tostring(playerSerial) ) then  
                return theValue 
            else 
                return false 
            end 
        end 
    end 
end  

Posted

i try this but nothing and nothing in debug

function test2 (source)

local ban = getPlayerBanSerial ( source )

outputChatBox(ban)

end

addCommandHandler ( "test", test2 )

Posted
i try this but nothing and nothing in debug

function test2 (source)

local ban = getPlayerBanSerial ( source )

outputChatBox(ban)

end

addCommandHandler ( "test", test2 )

You can't use "test" as a command name.

Posted
function getPlayerBanSerial ( thePlayer ) 
    assert ( isElement ( thePlayer ) and getElementType ( thePlayer ) == "player", "Bad player element" ) 
    local playerSerial = getPlayerSerial(thePlayer) 
    if ( thePlayer ) and ( playerSerial ) then 
        local theBans = xmlNodeGetChildren( banlist ) 
        for i, theNode in ipairs( theBans ) do 
            local theValue = xmlNodeGetAttribute( theNode, "Serial" ) 
            if ( theValue == tostring(playerSerial) ) then 
                outputChatBox ( "getPlayerBanSerial: value of theValue is: ".. tostring ( theValue ) ) 
                return theValue 
            else 
                outputChatBox ( "getPlayerBanSerial: theValue doesn't match" ) 
                return false 
            end 
        end 
    end 
end 

Use that and see what it outputs to the chatbox when you use the command.

Posted
how fix ?

First check, if it is really an error. Maybe a boolean is a correct return value, but check what does it mean. (You can even do outputChatBox ( tostring ( bans ) ) to see if it's true or false.) Look at the returns in your script, look at what might they return and then find it out why exactly this boolean was returned.

Edit: and yes, as Solidsnake says, putting a lot of ouputChatBoxes in a script can always be helpful while debugging ;)

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...