Peastolz Posted February 28, 2022 Share Posted February 28, 2022 Hello, Everyone. ** My english is not good sorry ** I have a question about setElementData function. Question : if my server has so many setElementData it will has a problem with my server? for example : My script is like as Lobby's Script it will have lobby and player can join the lobby and play gamemode in lobby on my script. So my lobby has time's play it will change data in setElementData -1 every 1 seconds when time's lobby == 0 then end gamemode lobby's i get setElementData for show Ui in client. It is dxDrawText("Time : " ..math.floor(getElementData(localPlayer,"timelobby") , ... ,... ,...) Ex: Time : 00.15 for player back to my question : i have so many lobby . it will setElementData "time" too much. if i have 30 lobby it will have 30 time data and have 30 ( a data is check player in lobby ex: "inLobby1") it will be lags or cache for this script ? Or Is it has better way for this script ? Thank you very much. : D Link to comment
Mkl Posted February 28, 2022 Share Posted February 28, 2022 Hi, I'm not sure to understand. Do you want, when a player starts a "lobby", a timeleft which stops the game when it reaches 0? If yes, why don't you use setTimer ? To display the time, I would have use getTickCount() instead of using getElementData everyframe. Check the second example of https://wiki.multitheftauto.com/wiki/GetTickCount that counts time, same logic can be used to create a timeleft to diplay. 1 Link to comment
Moderators IIYAMA Posted February 28, 2022 Moderators Share Posted February 28, 2022 2 hours ago, Peastolz said: Or Is it has better way for this script ? It is unwanted network information. > > > setElementData. (getElementData doesn't use network) Every layer of information, means that you have less data to spare for future resources that also use the network. The servertimesync resource uses getTickCount(which Mkl explains) to synchronize time between the client and the server. Now all you have to do is send future time to the client, which will sets it's counter to the right time. Untested example, feel free to optimise it even more. Server -- set when a new round starts (NOT every second) local timeNow = exports.servertimesync:getServerTime() if timeNow then setElementData(resourceRoot,"lobbyEndTime", timeNow + 60000) end Client local timeNow = exports.servertimesync:getServerTime() if timeNow then local lobbyEndTime = getElementData(resourceRoot,"lobbyEndTime") if lobbyEndTime then local remainingTime = (lobbyEndTime - timeNow) / 1000 if remainingTime < 0 then remainingTime = 0 end dxDrawText("Time : " ..math.floor(remainingTime), 300, 300 ) end end 1 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