BlackHamm3rJack Posted April 6, 2015 Share Posted April 6, 2015 I have this snippet of code: -- Process all the players function language_onResourceStart() for index, player in ipairs(getElementsByType("player")) do -- If the player is not logged in, then show language window if isGuestAccount(getPlayerAccount(player)) then triggerClientEvent(player, "language_showWindow", player) end end end addEventHandler("onResourceStart", root, language_onResourceStart) -- Called when a new player joins function language_onPlayerJoin() -- Check player account if isGuestAccount(getPlayerAccount(source)) then triggerClientEvent(source, "language_showWindow", source) end end addEventHandler("onPlayerJoin", root, language_onPlayerJoin) The problem is: when a player joins, the function language_onPlayerJoin successfully triggers the client event language_showWindow, but when the resource is started, with the function language_onResourceStart the event is instead not triggered (when it should trigger the event for each client). What is happening with this code? I tried to check if the for loop gets executed, and it does. It also finds the correct players, so the local variable player just seems to be correct. I just don't know what's wrong. Any help appreciated, thanks. Link to comment
Et-win Posted April 6, 2015 Share Posted April 6, 2015 triggerClientEvent(player, "language_showWindow", player) https://wiki.multitheftauto.com/wiki/OnResourceStart 'player' will not be defined. Instead of that, use 'getRootElement()' or 'getElementsByType("player")' Link to comment
BlackHamm3rJack Posted April 6, 2015 Author Share Posted April 6, 2015 Maybe you misunderstood, if i use getRootElement inside the function, it will trigger the event to every client, but i want the event to be triggered to all the clients that are not logged in. Link to comment
ALw7sH Posted April 6, 2015 Share Posted April 6, 2015 Idont think the problem is from the server side, because i cant see anything worng on this code Link to comment
TAPL Posted April 6, 2015 Share Posted April 6, 2015 You should attach the event onResourceStart to resourceRoot. Your problem is that the server side start BEFORE the client side, the solution is make trigger from the client when it ready to the server side and then trigger again to the client, which mean you won't need onPlayerJoin nor onResourceStart. 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