PHP Code:
if (this.dir > "6.25") {
this.dir = 0;
}
Why is 6.25 in quotes? All you're doing is adding more work for the engine by forcing it to be coerced to a number before it can be compared. You're doing the same thing here (among other places):
PHP Code:
//Speed variables
this.speed = "1";
this.leftrightspeed = "0.13";
this.movespeed = "0";
this.acceleration = "0.10";
I'm not really sure what you're trying to do with acceleration. I'm assuming you want the longer you hold down the up key, the faster it goes, so you need to accelerate while it's held down, not when it's first pushed.
PHP Code:
//#CLIENTSIDE
const MAX_SPEED = 3;
const FRICTION = 0.1;
const ACCELERATION = 1.2;
function onCreated() {
disableDefMovement();
this.trigger("timeOut");
}
function onTimeOut() {
// show car (you should do this in a GANI attribute so you don't have
// to have this timeout; it'll look smoother for other players too)
with (findImg(1)) {
image = "block.png";
attachToOwner = true;
rotation = thiso.angle;
}
// turn the car
if (keyDown(1)) {
// turn left
this.angle += 0.1;
} else if (keyDown(3)) {
// turn right
this.angle -= 0.1;
}
// accelerate or deccelerate
if (keyDown(0)) {
// increase speed
this.speed = min(MAX_SPEED, max(0.1, this.speed * ACCELERATION));
} else {
// decrease speed
this.speed *= (1 - FRICTION);
}
player.chat = "speed=" @ this.speed;
// move the car
player.x -= sin(this.angle) * this.speed;
player.y -= cos(this.angle) * this.speed;
// reset the timeout
this.setTimer(0.05);
}
Something like this is all you need for a basic car. There's no need to complicate it.
And stop worrying about people stealing your scripts. It's not as big of a deal as you might think.