Jump to content

kickPlayer in client side?


iPanda

Recommended Posts

How can i use function kickPlayer in client side for my GUI?

I have code, but it don`t work! Help.

server side:

addEvent("kikcPlayer", true) 
addEventHandler("kikcPlayer", getRootElement(), function(kicked) 
    if (type(kicked) == "player") then 
        kickPlayer(client, kicked) 
    end 
end) 

Then in client side i use

client side:

triggerServerEvent("kickPlayer", getLocalPlayer(), getLocalPlayer()) 

Edited by Guest
Link to comment

Client-side

triggerServerEvent( "kickPlayer", localPlayer ) 

Server-side

addEvent( "kickPlayer", true ) 
addEventHandler( "kickPlayer", root, 
    function( kicker ) 
        if ( source ~= client ) then return end 
        kickPlayer( client, ( ( isElement( kicker ) and getElementType( kicker ) == "player" ) and kicker or client ) ) 
    end 
) 

Link to comment

I've got one more question.

How can I cancel a kick-timer, pressing the button?

kickme = guiCreateButton(0.2, 0.52, 0.15, 0.05, "kick me", true) 
cancel = guiCreateButton(0.2, 0.60, 0.15, 0.05, "cancel", true) 
  
kickTimer = setTimer(function() triggerServerEvent("kickPlayer", getLocalPlayer()) end, 5000, 1) 
addEventHandler("onClientGUIClick", getRootElement(), function() 
    if (source == kickme) then 
        if isTimer(kickTimer) then resetTimer(kickTimer) end 
    elseif (source == cancel) then 
        if isTimer(kickTimer) then killTimer(kickTimer) end 
    end 
end) 

The problem is that I was kicked from server without pressing any buttons.

Also, the cancel button kick-timer is not running.

Help.

Link to comment

You reset the timer when pressing the kickme button. You have to execute the event manually by doing the following.

kickme = guiCreateButton( 0.2, 0.52, 0.15, 0.05, "kick me", true ) 
cancel = guiCreateButton( 0.2, 0.60, 0.15, 0.05, "cancel", true ) 
  
kickTimer = setTimer( triggerServerEvent, 5000, 1, "kickPlayer", localPlayer ) 
  
addEventHandler( "onClientGUIClick", root, 
    function( ) 
        if ( source == kickme ) then 
            triggerServerEvent( "kickPlayer", localPlayer ) 
        elseif ( source == cancel ) then 
            if ( isTimer( kickTimer ) then 
                killTimer( kickTimer ) 
            end 
        end 
    end, false 
) 

Link to comment
kickme = guiCreateButton( 0.2, 0.52, 0.15, 0.05, "kick me", true ) 
cancel = guiCreateButton( 0.2, 0.60, 0.15, 0.05, "cancel", true ) 
  
addEventHandler( "onClientGUIClick", root, 
    function( ) 
        if ( source == kickme ) then 
            kickTimer = setTimer( triggerServerEvent, 5000, 1, "kickPlayer", localPlayer ) 
        elseif ( source == cancel ) then 
            if (kickTimer) and ( isTimer( kickTimer ) then 
                killTimer( kickTimer ) 
            end 
        end 
    end, false 
) 

Link to comment
kickme = guiCreateButton( 0.2, 0.52, 0.15, 0.05, "kick me", true ) 
cancel = guiCreateButton( 0.2, 0.60, 0.15, 0.05, "cancel", true ) 
  
addEventHandler( "onClientGUIClick", root, 
    function( ) 
        if ( source == kickme ) then 
            kickTimer = setTimer ( triggerServerEvent, 5000, 1, "kickPlayer", localPlayer ) 
        elseif ( source == cancel ) then 
            if isTimer( kickTimer ) then 
                killTimer( kickTimer ) 
            end 
        end 
    end 
) 

Link to comment

There was an unknown error to me. I have no idea what's going on ...

Client.lua:

T28yqgP42j4.jpg

Server.lua:

1USP02AogeU.jpg

At the command prompt on my server says: Acces denied @ "kickPlayer"

ps. Do not pay attention to the incomplete code on the picture, I took the new variables and syntax observed.

Link to comment
  • Moderators
make your resource on ACL

By that, he means that you have to add your resource to the Admin group in acl.xml (located at the same place as mtaserver.conf)

<acl> 
    ... 
    <group name="Admin"> 
        ... 
        <object name="resource.yourResourceName" /> 
        ... 
    </group> 
    ... 
</acl> 

More information about acl here:

https://wiki.multitheftauto.com/wiki/Access_Control_List

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