Jump to content

kick player OnPlayerJoin


Recommended Posts

hi, i've made i little script that check if the player name follow a specified pattern , and if not it will kick the player

but the problem is that even if the player get the message that he will be kicked and the kickPlayer function is executed the player still connected ?? why??

function check_account() 
    local pName = getPlayerName(source) 
     
    if(string.len(pName) <=4 or string.len(pName) >=30 or not string.match(pName, "[a-zA-Z]+_[a-zA-Z]+")) then 
        outputChatBox("Votre pseudo est invalide, veuillez mettre un pseudo de la forme : Prenom_Nom", source) 
        kickPlayer(source) 
    end 
-- ...... 
end 
addEventHandler("onPlayerJoin", getRootElement(), check_account) 
  
  

Link to comment

i have used it but nothing happen like if nothing was executed

  
function check_account() 
    local pName = getPlayerName(source) 
     
    if(string.len(pName) <=4 or string.len(pName) >=30 or not string.match(pName, "[a-zA-Z]+_[a-zA-Z]+")) then 
        cancelEvent(true, "invalid nickname") 
    else 
        fadeCamera(source, true) 
        outputChatBox("Bienvenu dans mon serveur", source) 
  
        if(getAccount(getPlayerName(source))) then 
            triggerClientEvent(source, "showLoginGui", source) 
        else 
            triggerClientEvent(source, "showRegisterGui", source) 
        end 
    end 
end 
addEventHandler("onPlayerJoin", getRootElement(), check_account) 
  

Link to comment
  xXMADEXx said:
  lcd12321 said:
better use cancelEvent instead of kickplayer and use 2nd parametr of cancelEvent for kick reason

cancelEvent doesn't work for onPlayerJoin: https://wiki.multitheftauto.com/wiki/OnPlayerJoin -- There isn't a cancel effect.

Make sure the script has access to function.kickPlayer in the ACL.

ok thanks, i gave the resource access to function.kickPlayer and it work, but i found that the server continue the execution on the function even if i kick the player, so i had to put an if-else on the whole block after the kick

Link to comment
  • Moderators

On most of the pages it is there.

This is probably one of the few events which has no information about that.

Also you can figure out very easy if an event can be cancelled.

If the event triggers before the "effect" it can be cancelled*.

Doesn't count for all.*

When the event triggers on the devise where the effect was created, there is more chance it can be cancelled.

"onClientPlayerDamage" -- client triggers before the damage("effect") So can be cancelled. 
  
"onPlayerDamage"  -- server triggers after the damage has been done. The player/his-ped might be already dead by now on the client his pc.  

You have to think with logic.

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