FuriouZ Posted May 11, 2013 Posted May 11, 2013 Hey, i have a question what i doesn't find from wiki. How to sctipt disconnceting from server,what functions i need ? Like i created a gui and i need that if i click to 'quit' button,then i disconnet from server. What i have to paste here ? Serverside: function quitButton ( ) [[HERE]] end addEvent( "quitButton", true ) addEventHandler( "quitButton", getRootElement(), quitButton )
3NAD Posted May 11, 2013 Posted May 11, 2013 Hmm.. i guess you need to use " disconnect " or " quit " command by this executeCommandHandler Or Use this kickPlayer
TAPL Posted May 11, 2013 Posted May 11, 2013 Hmm.. i guess you need to use " disconnect " or " quit " command by this executeCommandHandler NOTE: You can only execute commands created by Lua. You cannot execute MTA harcoded commands due to security reasons.
FuriouZ Posted May 11, 2013 Author Posted May 11, 2013 Doesn't work --Quit Button function quitButton ( playerSource, commandName ) if ( playerSource ) executeCommandHandler ( "quit", playerSource ) end end addEvent( "quitButton", true ) addEventHandler( "quitButton", getRootElement(), quitButton )
iPrestege Posted May 11, 2013 Posted May 11, 2013 Hmmm..You can make a function with a command handler then execute the command : addCommandHandler executeCommandHandler kickPlayer * You can use the same command handler with execute with any resource .
Sasu Posted May 11, 2013 Posted May 11, 2013 You forgot 'then' --Quit Button function quitButton ( playerSource, commandName ) if ( playerSource ) then executeCommandHandler ( "quit", playerSource ) end end addEvent( "quitButton", true ) addEventHandler( "quitButton", getRootElement(), quitButton )
iPrestege Posted May 11, 2013 Posted May 11, 2013 Hmm.. i guess you need to use " disconnect " or " quit " command by this executeCommandHandler NOTE: You can only execute commands created by Lua. You cannot execute MTA harcoded commands due to security reasons. @ Sasuke !
iPrestege Posted May 11, 2013 Posted May 11, 2013 As i said above read my post #1 You have to create function to kick the player and add the command handler then execute the command that's all .
FuriouZ Posted May 11, 2013 Author Posted May 11, 2013 I tryed both of them but still nothing Server: --Quit Button function quitButton ( playerSource, commandName ) if ( playerSource ) then executeCommandHandler ( "disconnect", playerSource ) end end addEvent( "quitButton", true ) addEventHandler( "quitButton", getRootElement(), quitButton ) A part from client: addEventHandler("onClientGUIClick", root, function() if source == GUIEditor.button[1] then triggerServerEvent ( "quitButton", getLocalPlayer() ) elseif source == GUIEditor.button[3] then triggerServerEvent ( "commandButton", getLocalPlayer() ) end end ) And debug (tryed restarting,pressing quit button,but no errors)
Castillo Posted May 11, 2013 Posted May 11, 2013 1: Do you even read what they said? you can't execute hard coded commands. 2: 'playerSource' and 'commandName' is nil on your code, you must use 'source'.
3NAD Posted May 11, 2013 Posted May 11, 2013 You triggered with ' localPlayer ' .. triggerServerEvent ( "quitButton", getLocalPlayer() ) So the ' source ' @ server side; will be the player who triggered the event, I didn't try it. function quitButton ( ) kickPlayer ( source, source, "Quit" ) -- needs resource permissions end addEvent ( "quitButton", true ) addEventHandler ( "quitButton", root, quitButton )
Cadu12 Posted May 11, 2013 Posted May 11, 2013 "NOTE: You can only execute commands created by Lua. You cannot execute MTA harcoded commands due to security reasons." Why don't you can read wiki what they are saying? It doesn't work if you are using "quit", "disconnect", "connect", etc Here is command list: https://wiki.multitheftauto.com/wiki/Client_Commands
iPrestege Posted May 11, 2013 Posted May 11, 2013 addCommandHandler("QuitFromServer", function ( player ) kickPlayer ( player , "The Reason" ) end ) addEvent( "quitButton", true ) addEventHandler( "quitButton", getRootElement(), function ( ) local player = source if not ( isElement ( player ) ) then return end executeCommandHandler ( "QuitFromServer", player ) end )
FuriouZ Posted May 11, 2013 Author Posted May 11, 2013 addCommandHandler("QuitFromServer", function ( player ) kickPlayer ( player , "The Reason" ) end ) addEvent( "quitButton", true ) addEventHandler( "quitButton", getRootElement(), function ( ) local player = source if not ( isElement ( player ) ) then return end executeCommandHandler ( "QuitFromServer", player ) end ) Debug: s_settings.lua:12: Access denied @ 'executeCommandHandler' still doesn't work
xXMADEXx Posted May 11, 2013 Posted May 11, 2013 In the admin ACL put: <object name="resource.YourResourceName" />
3NAD Posted May 12, 2013 Posted May 12, 2013 You triggered with ' localPlayer ' .. triggerServerEvent ( "quitButton", getLocalPlayer() ) So the ' source ' @ server side; will be the player who triggered the event, I didn't try it. function quitButton ( ) kickPlayer ( source, source, "Quit" ) -- needs resource permissions end addEvent ( "quitButton", true ) addEventHandler ( "quitButton", root, quitButton ) Talking to myself !
FuriouZ Posted May 12, 2013 Author Posted May 12, 2013 Okay,it works,thanks,but there isn't other way widhout kick'ing player ?
TAPL Posted May 12, 2013 Posted May 12, 2013 Other way? I am thinking about redirect the player to fake IP and Port.
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