• All, I am currently in the process of migrating domain registrations. During this time there may be some intermittent outages or slowdowns. Please contact staff if you have any questions.

Converting c++ script to openbor script

bWWd

Well-known member
Can someone help me to convert this car movement script from this tutorial to openbor scripting ? I think its very doable but im not sure how to go about it, i converted most of the syntax but im not sure how to use it when applying velocity  and angle with drawmethod.

Code:
	anim	follow2
		@script
                void self = getlocalvar("self");
				 int sped = getentityproperty(self, "speed");
				  setlocalvar("vsped",getentityproperty(self, "speed")); 
                int iPIndex = getentityproperty(self,"playerindex"); //Get player index
                void a1 = playerkeys(iPIndex, 0, "attack");
                void j1 = playerkeys(iPIndex, 0, "jump");
              	void right 	=  playerkeys(iPIndex, 0, "moveright");
	            void left 	=  playerkeys(iPIndex, 0, "moveleft");
				float x = 3, y =3;
				float speed =0;
				float angle =0;
				float maxSpeed = getentityproperty(self, "speed");
				float acc =0.2;
				float dec =0.3;
				float turnSpeed =0.08;

if ( a1 && speed < maxSpeed ){
	  if (speed < 0){
  speed += dec;
     changeentityproperty(self, "velocity", sin (angle) * acc + speed , cos(angle) * acc + speed);


  }
  else{
  speed += acc;

}
		}
		if ( j1 && speed > -maxSpeed ){
			  settextobj(1, 150 , 100 , 1, 1, "-max", openborvariant("elapsed_time")+2000);
  if (speed > 0){
  speed -= dec;

  }
  else{
  speed -= acc;

}
		}
		if ( !a1 && !j1 ){
  if (speed - dec > 0){
  speed -= dec;

  }
  else if (speed + dec < 0){
  speed += dec;
  changeentityproperty(self, "velocity", x ,y);
}
  else {
  speed = 0;
  changeentityproperty(self, "velocity", x ,y);
}
		
 if ( right && speed !=0 ){
  angle +=  turnSpeed * speed/maxSpeed;
  }
   if ( left && speed !=0 ){
  angle -=  turnSpeed * speed/maxSpeed;
  }
  x += sin (angle) * speed;
  y -= cos(angle) * speed;
  
              		}
		
	@end_script		
	loop	1 
	offset	22 23
	bbox	6 5 83 98
	delay	1

	frame	data/chars/car/car.gif
	frame	data/chars/car/car.gif

Heres the video on 0:27

 
It should work but you will have to do trial and error until you can get it working I did something similar with a pendulum script.  The most important thing is trying to understand the script as this is a speed run nothing is explained find a tutorial with more information on what controls what and how it works.

I would give this a try but I am too busy with other stuff right now.
 
Hey bWWd, sorry I don't have time to type out all the details right now, but I can offer this:

The video you posted - well it sucks. Moreover it's pretty much a rip off of this guy. I think you should check him out. He's an amazing coder and really explains everything as he goes along. Almost everythig he does is applicable to OpenBOR script with a bit of tinkering. He even has a top down race car project video:


Also, bit of general advice - you need to get away from using @script and @end_script tags. That stuff needs to be in functions called with @cmd or run by event scripts. There are many reasons why, but right up front is efficiency. You get much more bang for your buck keeping the code out of model text.

Hope that helps some.

DC
 
Back
Top Bottom