Jump to content

OnPlayerJoin after downloading resources


anybox

Recommended Posts

Hi. I have this code

addEventHandler("onPlayerJoin", getRootElement(),  
    function () 
        triggerClientEvent ("playerJoinEventClient", source) 
    end 
) 

in the server-side script. So when I first time join the server nothing happens, the funcion "playerJoinEventClient" just doesn't work. But the second time when i join the server the function works perfectly. I think the problem is missing client-side script on the first launch, so maybe I can check if all the resources are downloaded then call triggerClientEvent? Thanks.

Link to comment

The rest of the code on server-side script is not so important for this thread.

This is on the client side.

function playerJoinHandler() 
    outputChatBox("Client joined") 
    fadeCamera(true, 3) 
    showPlayerHudComponent("radar", false); 
    showPlayerHudComponent("area_name", false); 
    setCameraMatrix(-911.46545410156, 1931.513671875, 
    130.02493286133, -392.18316650391, 1589.7071533203, 101.35176849365) 
end 
  
addEvent("playerJoinEventClient", true) 
addEventHandler("playerJoinEventClient", getRootElement(), playerJoinHandler) 

Link to comment

I don't see a need for trigger from the server to the client.

This will do the job on client side only.

function playerJoinHandler() 
    outputChatBox("Client joined") 
    fadeCamera(true, 3) 
    showPlayerHudComponent("radar", false); 
    showPlayerHudComponent("area_name", false); 
    setCameraMatrix(-911.46545410156, 1931.513671875, 
    130.02493286133, -392.18316650391, 1589.7071533203, 101.35176849365) 
end 
addEventHandler("onClientResourceStart", resourceRoot, playerJoinHandler) 

Btw. your trigger is actually wrong, this way it going trigger for all clients not only who join.

triggerClientEvent ("playerJoinEventClient", source) 

Should be:

triggerClientEvent (source, "playerJoinEventClient", source) 

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