Jump to content

output screen size on player connect


Xwad

Recommended Posts

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

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

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

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

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

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