Jump to content

Google Chart API


'LinKin

Recommended Posts

Posted

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

Need a clanwar script? Click here!

Do you want some free scripts for your DD server? Visit my website.

Posted

You could try creating a PHP script to run the API, so you can use fetchRemote client side.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

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?

Need a clanwar script? Click here!

Do you want some free scripts for your DD server? Visit my website.

Posted (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 by Guest

My ingame nick is ~HyPeX~

BF3 Gamemode Progress: ~30% - Currently working on AI & MapManager

gKhdyRJ.png

Posted

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.

Need a clanwar script? Click here!

Do you want some free scripts for your DD server? Visit my website.

Posted

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.

If I helped you, please click the like button on the right ;) Thanks!

Posted

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

Posted

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.

If I helped you, please click the like button on the right ;) Thanks!

Posted

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

My ingame nick is ~HyPeX~

BF3 Gamemode Progress: ~30% - Currently working on AI & MapManager

gKhdyRJ.png

Posted

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.

"The humble beet is the answer to all riddles." - Rolf

Posted

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

My ingame nick is ~HyPeX~

BF3 Gamemode Progress: ~30% - Currently working on AI & MapManager

gKhdyRJ.png

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