Well first off, throw temp in front of variables that are only going to be used locally otherwise they're declared globally which is just annoying.
You should modify it so you can call the function and get the result from it. I.e:
PHP Code:
//#CLIENTSIDE
function onCreated() {
temp.val = calc(1, 2);
player.chat = temp.val;
}
function calc(a, b) {
temp.result = a + b;
return temp.result;
}
After you modify your formulas to work with coordinates since p1...4 = {x, y} and calculate using the respective coordinate in each formula. I.e:
PHP Code:
temp.nx = (1 - t)^3 * a[0] + 3 * (1 - t)^2 * t * b[0] + 3 * (1 - t) * t^2 * c[0] + t^3 * d[0];
temp.ny = (1 - t)^3 * a[1] + 3 * (1 - t)^2 * t * b[1] + 3 * (1 - t) * t^2 * c[1] + t^3 * d[1];
return {temp.nx, temp.ny};
The parameters for this will probably be something like..
PHP Code:
function calc_bezier(t, a, b, c, d) {
// your calculations
}
Also check out the diagrams here:
http://en.wikipedia.org/wiki/Bézier_curve