karimsqualli96 Posted August 27, 2014 Share Posted August 27, 2014 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
karimsqualli96 Posted August 27, 2014 Author Share Posted August 27, 2014 found the solution myself : i had to provide the right to the resource to use kickPlayer function, by adding the resource to the admin group in acl.xml file Link to comment
lcd12321 Posted August 27, 2014 Share Posted August 27, 2014 better use cancelEvent instead of kickplayer and use 2nd parametr of cancelEvent for kick reason Link to comment
karimsqualli96 Posted August 27, 2014 Author Share Posted August 27, 2014 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 Posted August 27, 2014 Share Posted August 27, 2014 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. Link to comment
karimsqualli96 Posted August 27, 2014 Author Share Posted August 27, 2014 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
lcd12321 Posted August 27, 2014 Share Posted August 27, 2014 sry my mistake. U can use event onPlayerConnect. It has canceleffect Link to comment
karimsqualli96 Posted August 27, 2014 Author Share Posted August 27, 2014 how to know where can i use cancelEvent and when i cannot?? there is nothing on the wiki that indicate it Link to comment
Moderators IIYAMA Posted August 27, 2014 Moderators Share Posted August 27, 2014 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
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