Jump to content

Google Chart API


'LinKin

Recommended Posts

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:

STATSINK.png

Link to comment

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

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

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 by Guest
Link to comment

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

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: spX3CK8.png

Link to comment

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: spX3CK8.png

That function doesnt looks totally right (The dark one does not totally reach the exact center of the circle..

Link to comment

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: spX3CK8.png

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

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

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