WASSIm. Posted September 13, 2013 Share Posted September 13, 2013 hi guys. how make ban system ? What Bans system ?: ban system make can player banned join server but can't play. like this form CIT server Link to comment
csiguusz Posted September 13, 2013 Share Posted September 13, 2013 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. Link to comment
WASSIm. Posted September 13, 2013 Author Share Posted September 13, 2013 i make ban with serial and the serial save to file xml but how make save time and reason ? Link to comment
csiguusz Posted September 13, 2013 Share Posted September 13, 2013 Save time (a timestamp) and reason nex to the serial. Like this: <bans> <ban name="Joe" serial="123" time="57348957" reason="no reason" /> </bans> Link to comment
WASSIm. Posted September 13, 2013 Author Share Posted September 13, 2013 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) Link to comment
csiguusz Posted September 13, 2013 Share Posted September 13, 2013 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 Link to comment
WASSIm. Posted September 13, 2013 Author Share Posted September 13, 2013 thank you 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 Link to comment
Castillo Posted September 13, 2013 Share Posted September 13, 2013 What is the problem? Link to comment
WASSIm. Posted September 13, 2013 Author Share Posted September 13, 2013 i use function csiguusz its working but i make function get serial player if in ban list but not working Link to comment
Castillo Posted September 13, 2013 Share Posted September 13, 2013 Tried debugging it? ( No, I don't mean check debugscript, I mean see what everything is returning, to find out the cause of the problem ). Link to comment
WASSIm. Posted September 13, 2013 Author Share Posted September 13, 2013 i try this but nothing and nothing in debug function test2 (source) local ban = getPlayerBanSerial ( source ) outputChatBox(ban) end addCommandHandler ( "test", test2 ) Link to comment
Castillo Posted September 13, 2013 Share Posted September 13, 2013 You did what I told you to? debug the function by pieces? Link to comment
csiguusz Posted September 13, 2013 Share Posted September 13, 2013 i try this but nothing and nothing in debugfunction test2 (source) local ban = getPlayerBanSerial ( source ) outputChatBox(ban) end addCommandHandler ( "test", test2 ) You can't use "test" as a command name. Link to comment
WASSIm. Posted September 13, 2013 Author Share Posted September 13, 2013 (edited) how see returning function ? You can't use "test" as a command name. why ? Edited September 13, 2013 by Guest Link to comment
Castillo Posted September 13, 2013 Share Posted September 13, 2013 Ah, yeah, I forgot about that, there are some command names which won't work because they're used by MTA. Link to comment
WASSIm. Posted September 13, 2013 Author Share Posted September 13, 2013 i change command name and now show me in debug Bad argument @ 'outputChatBox' [Expected string at argument 1,got boolean] Link to comment
Castillo Posted September 13, 2013 Share Posted September 13, 2013 Which means that the function is returning a boolean: true or false/nil. Link to comment
Castillo Posted September 13, 2013 Share Posted September 13, 2013 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. Link to comment
csiguusz Posted September 13, 2013 Share Posted September 13, 2013 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 Link to comment
WASSIm. Posted September 14, 2013 Author Share Posted September 14, 2013 finish it working thx all Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now