Jump to content

onplayerconnect


aintaro

Recommended Posts

Hello when I use the onplayerconnect event from the mtasa wiki example nothing happens :

--when a player connects 
function playerConnect (playerNick, playerIP, playerUsername, playerSerial, playerVersionNumber) 
    if playerNick == "Player" then --check if his nick is "Player" 
        cancelEvent(true,"The nick \"Player\" is not allowed, please change it to something else. You can change your nick in Settings menu Multiplayer tab.") --in that case refuse the connection 
    else 
        --output some data about the player 
        outputChatBox (playerNick.." just connected to the server.") 
        outputChatBox ("IP: "..playerIP.." Username: "..playerUsername.." Serial: "..playerSerial) 
    end 
end 
  
--add the playerConnect function as a handler for onPlayerConnect 
addEventHandler ("onPlayerConnect", getRootElement(), playerConnect) 

is this event broken?

Link to comment

I found the issue :

onplayerconnect will only execute when another player joins the server.

So basicly when you are testing on your machine you will not get the message with your ip and such because it only sends it to other players that are already connect on the server.

Therefor I found another server event wich is called onPlayerJoin.

onPlayerJoin will handle the player that just connected to the server instead of handling all the other players that are already connected.

so the sum it all up :

If you want other players to get a message when a specific player logs in then use : onPlayerConnect

If you want the player that just connected to get a welcome message then use : onPlayerJoin

Thanks again everybody for the help that you offered.

Greetz, Aintaro

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