Jump to content

output screen size on player connect


Xwad

Recommended Posts

Posted

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) 

Posted

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.

Posted

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.

Posted

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?

Posted

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) 

Posted

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) 

Posted
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 ) 

Posted

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) 

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