'LinKin Posted April 2, 2014 Share Posted April 2, 2014 Hello, I'm using this script: https://community.multitheftauto.com/in ... ls&id=8567 I'm using it into a stats script which shows a graph of wins, 2nd, 3rd, and 4th+ finished positions in a race. The thing is, I've noticed that the server lags when the players are checking and requesting these charts.. Is there any solution for it? Maybe upgrading some server's features? (Idk which ones). This is an screenshot of it: Link to comment
Castillo Posted April 2, 2014 Share Posted April 2, 2014 You could try creating a PHP script to run the API, so you can use fetchRemote client side. Link to comment
Dealman Posted April 2, 2014 Share Posted April 2, 2014 I believe the reason why it causes lag is because the server has to download the image. fetchRemote can only download things externally via the server. The client can only use(as far as I know) fetchRemote to download files from the actual MTA server(IE models, textures and resources). Am glad the chart thing came to some use for someone, good job it looks pretty good! Edit: Castillo beat me to it, I have no experience with PHP so while I'd love to help - I'm afraid I can't. Luckily we have people like Castillo to help Link to comment
'LinKin Posted April 2, 2014 Author Share Posted April 2, 2014 I know nothing about PHP. And yeah. I have this server-side fetchRemote(theURL, callbackFunction_Handler, "", false, thePlayer) function callbackFunction_Handler(responseData, errorNumber, thePlayer) if(errorNumber == 0) then triggerClientEvent(thePlayer, "onServerReceivedImage", resourceRoot, responseData) else outputDebugString("FAG-CHART: Callback Failed! Error Number: "..tostring(errorNumber).." for: "..getPlayerName(thePlayer), 0, 187, 0, 0) end end Just like the script of Dealman (Btw, thanks for the comment ) I would really like to have this 'lag' thing fixed. Because the chart is what makes this script different from others. Do you know someone who knows PHP? Link to comment
.:HyPeX:. Posted April 2, 2014 Share Posted April 2, 2014 (edited) I'd just make the fecthRemote client side. i use it in my BF3 gamemode to download the sounds, and the server works pretty good. (As far as ik, fetchRemote uses client's connection to download whatever you specified, any link should do, even outside the mta server, since in my case its to an external webpage (Thought it is hosted on the same VPS as the server)). eg: joining song at my sv: http://bf3-mta.tk/songs/bf3.mp3 Edited April 2, 2014 by Guest Link to comment
'LinKin Posted April 2, 2014 Author Share Posted April 2, 2014 I'll try to use it client-side. Link to comment
Spajk Posted April 2, 2014 Share Posted April 2, 2014 Are these charts constantly changing? If not, some kind of local storage would be usefull. Link to comment
'LinKin Posted April 2, 2014 Author Share Posted April 2, 2014 Of course they change. It's based on 1st, 2nd, 3rd, 4th+ race rank. When you change between players, the chart of each one is different, thus it will download the new image. Link to comment
myonlake Posted April 3, 2014 Share Posted April 3, 2014 As you're going for an external chart instead of making your own one with the dx-functions, you will have to use the PHP image processing functions. However, I suggest you use someone else's script, Google API is useful yes, but not sure how they render everything, so the delay of the creation and download will be a pain. And like explained above, it's because the server downloads the image. There's currently 3 download processes happening (Google -> server -> client), when you could just have Google and client. Link to comment
'LinKin Posted April 3, 2014 Author Share Posted April 3, 2014 Is is possible to draw this chart with dx functions? Link to comment
cheez3d Posted April 3, 2014 Share Posted April 3, 2014 You can use dxDrawLine with some math and tocolor to draw it. dxDrawLine() tocolor() Link to comment
cheez3d Posted April 3, 2014 Share Posted April 3, 2014 The formula for points on a circle are: x = xcenter + radius * sin(theta) y = ycenter + radius * cos(theta) where xcenter and ycenter are the center of the circle, radius is the radius and theta is the angle. You simply have to iterate theta from your starting angle to your ending angle in small enough steps, and extract the x and y values for plotting, and keep in mind that most trigonometric functions take their arguments as radians (0 through 2*PI) rather than degrees (0 through 360) - adjust your start and end angles and your theta step to take this into account. http://stackoverflow.com/questions/8888 ... le-segment addEventHandler("onClientRender",root,function() for i=0,360,0.25 do dxDrawLine(300,300,300+100*math.sin(math.rad(i)),300+100*math.cos(math.rad(i)),(i>=0 and i<=50) and tocolor(60,60,60) or (i>50 and i<=180) and tocolor(255,50,50) or (i>180 and i<=360) and tocolor(0,255,70)) end end) You can use this simple function for an output like this: Link to comment
myonlake Posted April 3, 2014 Share Posted April 3, 2014 Then just apply Y rotation to make it look like 3D chart. That's not too hard to do, just some more math and I am sure you can find that by Googling. Then you can even animate the chart so it will look even more cooler and baws. Link to comment
.:HyPeX:. Posted April 3, 2014 Share Posted April 3, 2014 The formula for points on a circle are: x = xcenter + radius * sin(theta) y = ycenter + radius * cos(theta) where xcenter and ycenter are the center of the circle, radius is the radius and theta is the angle. You simply have to iterate theta from your starting angle to your ending angle in small enough steps, and extract the x and y values for plotting, and keep in mind that most trigonometric functions take their arguments as radians (0 through 2*PI) rather than degrees (0 through 360) - adjust your start and end angles and your theta step to take this into account. http://stackoverflow.com/questions/8888 ... le-segment addEventHandler("onClientRender",root,function() for i=0,360,0.25 do dxDrawLine(300,300,300+100*math.sin(math.rad(i)),300+100*math.cos(math.rad(i)),(i>=0 and i<=50) and tocolor(60,60,60) or (i>50 and i<=180) and tocolor(255,50,50) or (i>180 and i<=360) and tocolor(0,255,70)) end end) You can use this simple function for an output like this: That function doesnt looks totally right (The dark one does not totally reach the exact center of the circle.. Link to comment
Woovie Posted April 3, 2014 Share Posted April 3, 2014 The formula for points on a circle are: x = xcenter + radius * sin(theta) y = ycenter + radius * cos(theta) where xcenter and ycenter are the center of the circle, radius is the radius and theta is the angle. You simply have to iterate theta from your starting angle to your ending angle in small enough steps, and extract the x and y values for plotting, and keep in mind that most trigonometric functions take their arguments as radians (0 through 2*PI) rather than degrees (0 through 360) - adjust your start and end angles and your theta step to take this into account. http://stackoverflow.com/questions/8888 ... le-segment addEventHandler("onClientRender",root,function() for i=0,360,0.25 do dxDrawLine(300,300,300+100*math.sin(math.rad(i)),300+100*math.cos(math.rad(i)),(i>=0 and i<=50) and tocolor(60,60,60) or (i>50 and i<=180) and tocolor(255,50,50) or (i>180 and i<=360) and tocolor(0,255,70)) end end) You can use this simple function for an output like this: That function doesnt looks totally right (The dark one does not totally reach the exact center of the circle.. Fix it then. It's lua. Link to comment
.:HyPeX:. Posted April 4, 2014 Share Posted April 4, 2014 Sadly, i've not seen radians in maths. Even tho, im suspecting about absolute numbers: try like this: local x,y = guiGetScreenSize dxDrawLine(x*0.5,y*0.5,x*0.5 + ( x*0.1 *math.sin(math.rad(i))),y*0.5 + ( y*0.1 *math.cos(math.rad(i))),(i>=0 and i<=50) and tocolor(60,60,60) or (i>50 and i<=180) and tocolor(255,50,50) or (i>180 and i<=360) and tocolor(0,255,70)) 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