Xwad Posted August 23, 2016 Share Posted August 23, 2016 HI! I am trying to output the player screen size who connected. I have 2 problems: my first problem is that it's also out putting a chatbox for other players (players who not connected), and the second problem is that it's local, so other players cant see the outputchatbox of the connected player:/ server function outPutScreenResolution() triggerClientEvent("outPutScreen", source) end addEventHandler ("onPlayerConnect", getRootElement(), outPutScreenResolution) client function outPutScreen_client() local x,y = guiGetScreenSize() outputChatBox(""..x.."x"..y.."") end addEvent("outPutScreen", true) addEventHandler("outPutScreen", getRootElement(), outPutScreen_client) Link to comment
Bonsai Posted August 23, 2016 Share Posted August 23, 2016 Does this really have to be onPlayerConnect? If you could use the clientside event "onClientResourceStart", you would only have to trigger a server event passing the resolution. Then you can output it for everyone. Link to comment
Xwad Posted August 23, 2016 Author Share Posted August 23, 2016 yes, i really need it for onPlayerConnect event:/ Link to comment
StefanAlmighty Posted August 23, 2016 Share Posted August 23, 2016 In your meta.xml, which file loads first? The serverside or clientside? The code won't work if serverside loads first because it's calling a function immediately on start when the clientside file hasn't loaded yet. Link to comment
GTX Posted August 23, 2016 Share Posted August 23, 2016 You can't use onPlayerConnect (it's when player attempts to connect). The client script will never be loaded and therefore triggerClientEvent won't make it to client side. But why do you need onPlayerConnect? Link to comment
Xwad Posted August 24, 2016 Author Share Posted August 24, 2016 And will it work with set timer? Link to comment
Gravestone Posted August 24, 2016 Share Posted August 24, 2016 Use onPlayerJoin instead. Client: function outPutScreen() local x,y = guiGetScreenSize() outputChatBox(""..x.."x"..y.."") end addEvent("outPutScreen", true) addEventHandler("outPutScreen", getRootElement(), outPutScreen) Server: function outPutScreenResolution() triggerClientEvent("outPutScreen", source) end addEventHandler ("onPlayerJoin", root, outPutScreenResolution) Link to comment
Xwad Posted August 24, 2016 Author Share Posted August 24, 2016 On login event is also not good for me. It is more complicated Link to comment
Xwad Posted August 24, 2016 Author Share Posted August 24, 2016 But if its not possible to do then i will do jt in another way. I will make add command handler Link to comment
Gravestone Posted August 24, 2016 Share Posted August 24, 2016 onPlayerJoin is triggered when the player has successfully joined the server, not when the player login. onPlayerLogin is triggered then. Link to comment
Xwad Posted August 24, 2016 Author Share Posted August 24, 2016 ohh really lol. Well i created the script with onCLientPlayerJoin, but it has the same bug: outputchatbox is not synced, but i added root:/ other problem is that its out putting a chatbox for every player, and i want only to out put the chat box for the player who joined function outputScreenSize() local x,y = guiGetScreenSize(source) outputChatBox ( x.. "x" ..y, 255,255,255 ) end addEventHandler("onClientPlayerJoin", getRootElement(), outputScreenSize) Link to comment
Gravestone Posted August 24, 2016 Share Posted August 24, 2016 function checkResolutionOnStart () local x,y = guiGetScreenSize() --get their screen size outputChatBox (x.."x"..y ) end --attach the function to the event handler addEventHandler ( "onClientResourceStart", resourceRoot, checkResolutionOnStart ) Link to comment
StefanAlmighty Posted August 24, 2016 Share Posted August 24, 2016 Your issue is with onClientPlayerJoin: https://wiki.multitheftauto.com/wiki/OnClientPlayerJoin As stated on the wiki all players except the source player will have the event triggered which is why everybody but you is seeing the text. Try using this: https://wiki.multitheftauto.com/wiki/On ... ourceStart onClientResourceStart is triggered when the player first loads the client file (so pretty much seconds after they join or when the resource is restarted). function outputScreenSize(res) if res == getThisResource() then local x,y = guiGetScreenSize(getLocalPlayer()) outputChatBox ( x.. "x" ..y, 255,255,255 ) end end addEventHandler("onClientResourceStart", getRootElement(), outputScreenSize) 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