Jump to content

Disconnect


FuriouZ

Recommended Posts

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 ) 

Link to comment
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.
Link to comment

Doesn't work

--Quit Button 
function quitButton ( playerSource, commandName ) 
         if ( playerSource ) 
         executeCommandHandler ( "quit", playerSource ) 
end 
end 
addEvent( "quitButton", true ) 
addEventHandler( "quitButton", getRootElement(), quitButton ) 

Link to comment

You forgot 'then'

--Quit Button 
function quitButton ( playerSource, commandName ) 
         if ( playerSource ) then 
         executeCommandHandler ( "quit", playerSource ) 
end 
end 
addEvent( "quitButton", true ) 
addEventHandler( "quitButton", getRootElement(), quitButton ) 

Link to comment

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)

mta-screen_2013-05-11_21-10-46.png

Link to comment

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 ) 

Link to comment

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 
) 
Link to comment
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 :|

Link to comment
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 !

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