Author Topic: Very basic vehicle speedometer bottom-print script - Help please.  (Read 2680 times)

Basically what the title asks. I'm looking for a simple script that you can copy-paste from car to car, and when you're ingame and driving the car, the bottom print says "MPH: [number here]", except MPH is yellow and the number is white.

Could anyone help me with a simple script like this? I'm in the need of it for an RP I'm working on, thanks for any future help, and I will credit you in the RP for whoever helps.

The script
  • Shows "MPH: [number here]" on bottom print, MPH yellow, number is white.
  • Needs to be universal so I can just paste it from car to car with ease
  • Be simple enough for a script-noob like me to understand, since I have 0% of knowlege in torque script and I don't have time to learn at this moment.

Thanks

I posted this here since aparantly it belongs here, even though I need help modifying vehicles, not requesting an addon to be made.

No it's not a server sided addon you enable for your server, it is a few lines of script that you paste in the vehicle's .cs file.
« Last Edit: March 28, 2016, 09:30:36 PM by Insert Name Here² »

If it hasn't been done by today evening, I'll do it.

If it hasn't been done by today evening, I'll do it.
Alrighty dannu, thanks man

Remember to make it as simple as you can, while still having the things I need and it being universal, that would be amazing

Code: (originally from Hydric.cs (Vehicle_Hydric)) [Select]
function XVehicle::onAdd(%this, %obj) //called when the vehicle is added
{
Parent::onAdd(%this, %obj); //make sure to call anything else that is supposed to be called and not just overwrite it with one
VehicleSpeedCheck(%obj); //call the speed checking function with the vehicle's object ID as the argument
}

function VehicleSpeedCheck(%obj)
{
if(!isObject(%obj)) //don't do anything if there's no vehicle
return;

%speed = vectorLen(%obj.getVelocity()); //get the vehicle's velocity

if(%speed < 0) //Keeps throwing random negative numbers when X is at dead stop apparently
    %speed = 0;

commandToClient(%obj.getControllingClient(), 'bottomPrint', "<color:FFFF00>MPH:" SPC "<color:FFFFFF>" @ mFloor((%speed / 2.64) * 6 * 3600 / 5280), 1); //the function that actually outputs the speed in MPH; code from port's Script_VehicleStatus

schedule(500, %obj, "VehicleSpeedCheck", %obj); //schedule's the function to be done over and over again; linked to the object so if the vehicle disappears, the function will not be called anymore
}
modify as needed
edit: actually, ignore the X placeholder thing for the function, only replace X in the first line for the vehicle's datablock name (example: HydricVehicle::onAdd) since the hydric's datablock name is HydricVehicle)
the best way to add it to many vehicles is to have the VehicleSpeedCheck function as a support script add-on so that you'd only need to have the first four lines in vehicles you want; if you want it like this instead tell me
« Last Edit: March 28, 2016, 01:17:24 AM by QuadStorm »

modify as needed (X is a placeholder name)
What do you replace X with..?

the best way to add it to many vehicles is to have the VehicleSpeedCheck function as a support script add-on so that you'd only need to have the first four lines in vehicles you want; if you want it like this instead tell me
Please do that, that'd be alot easier to do XD

Please do that, that'd be alot easier to do XD
https://hostr.co/zwXbv2b4VkXH
enable this add-on, so all you have to do is add this block of code to any vehicle you want to have this ability

Code: [Select]
function X::onAdd(%this, %obj) //replace X with the vehicle's datablock name
{
Parent::onAdd(%this, %obj);
VehicleSpeedCheck(%obj);
}

if the vehicle already has an ::onAdd function, just add VehicleSpeedCheck(%obj); somewhere in that code block (inside of it's brackets)
edit: forgeted up post's formating somehow
« Last Edit: March 28, 2016, 02:37:46 AM by QuadStorm »

Thanks so much for the help, I'll be sure to try it tomorrow morning! Quick question, how do you find the datablock name?

Thanks so much for the help, I'll be sure to try it tomorrow morning! Quick question, how do you find the datablock name?
look for
datablock WheeledVehicleData(JeepVehicle)
in the vehicle's scripts, where the bold part is the vehicle's datablock name (not including the parenthesis of course)
note that the underlined part (datablock type) could also be FlyingVehicleData or HoverVehicleData

look for
datablock WheeledVehicleData(JeepVehicle)
in the vehicle's scripts, where the bold part is the vehicle's datablock name (not including the parenthesis of course)
note that the underlined part (datablock type) could also be FlyingVehicleData or HoverVehicleData
Okay dude, thanks!

Yeah I pasted the script in and it isn't working, do you know what's up? It's at the bottom. If I did something wrong, do you mind making an example of how to do it exactly?

Code: [Select]
datablock WheeledVehicleData(KeiCarAltoVehicle)
{
isCitiVehicle = 1;

category = "Vehicles";
displayName = " ";
shapeFile = "./KeiCarAlto.dts"; //"~/data/shapes/skivehicle.dts"; //
emap = true;
minMountDist = 3;
   
   numMountPoints = 4;
   mountThread[0] = "sit";
   mountThread[1] = "sit";
   mountThread[2] = "sit";
   mountThread[3] = "sit";

maxDamage = 200.00;
destroyedLevel = 200.00;
energyPerDamagePoint = 160;
speedDamageScale = 1.04;
collDamageThresholdVel = 20.0;
collDamageMultiplier   = 0.02;

massCenter = "0 0.2 0.4";
   //massBox = "2 5 1";

maxSteeringAngle = 0.85;  // Maximum steering angle, should match animation
integration = 4;           // Force integration time: TickSec/Rate
//tireEmitter = VehicleTireEmitter; // All the tires use the same dust emitter

// 3rd person camera settings
cameraRoll = false;         // Roll the camera with the vehicle
cameraMaxDist = 8.5;         // Far distance from vehicle
cameraOffset = 4;        // Vertical offset from camera mount point
cameraLag = 0.0;           // Velocity lag of camera
cameraDecay = 0.75;        // Decay per sec. rate of velocity lag
cameraTilt = 0.3;
   collisionTol = 0.1;        // Collision distance tolerance
   contactTol = 0.1;

useEyePoint = false;

defaultTire = KeiCarTire;
defaultSpring = KeiCarSpring;
flatTire = jeepFlatTire;
flatSpring = jeepFlatSpring;

   numWheels = 4;

// Rigid Body
mass = 200;
density = 5.0;
drag = 4.5;
bodyFriction = 0.6;
bodyRestitution = 0.6;
minImpactSpeed = 10;        // Impacts over this invoke the script callback
softImpactSpeed = 10;       // Play SoftImpact Sound
hardImpactSpeed = 15;      // Play HardImpact Sound
groundImpactMinSpeed    = 10.0;

// Engine
engineTorque = 2500; //3500;       // Engine power
engineBrake = 200;         // Braking when throttle is 0
brakeTorque = 2000;        // When brakes are applied
maxWheelSpeed = 30;        // Engine scale by current speed / max speed

rollForce = 900;
yawForce = 600;
pitchForce = 1000;
rotationalDrag = 0;

// Advanced Steering
   steeringAutoReturn = true;
   steeringAutoReturnRate = 1;
   steeringAutoReturnMaxSpeed = 10;
   steeringUseStrafeSteering = true;
   steeringStrafeSteeringRate = 0.08;

// Energy
maxEnergy = 100;
jetForce = 3000;
minJetEnergy = 30;
jetEnergyDrain = 2;

splash = jeepSplash;
splashVelocity = 4.0;
splashAngle = 67.0;
splashFreqMod = 300.0;
splashVelEpsilon = 0.60;
bubbleEmitTime = 1.4;
splashEmitter[0] = VehicleFoamDropletsEmitter;
splashEmitter[1] = VehicleFoamEmitter;
splashEmitter[2] = VehicleBubbleEmitter;
mediumSplashSoundVelocity = 10.0;   
hardSplashSoundVelocity = 20.0;   
exitSplashSoundVelocity = 5.0;

//mediumSplashSound = "";
//hardSplashSound = "";
//exitSplashSound = "";

// Sounds
//   jetSound = ScoutThrustSound;
//engineSound = idleSound;
//squealSound = skidSound;
softImpactSound = slowImpactSound;
hardImpactSound = fastImpactSound;
//wheelImpactSound = slowImpactSound;

//   explosion = VehicleExplosion;
justcollided = 0;

   uiName = "KeiCar - Alto";
rideable = true;
lookUpLimit = 0.50;
lookDownLimit = 0.50;

paintable = true;
   
   damageEmitter[0] = VehicleBurnEmitter;
damageEmitterOffset[0] = "0.0 0.0 0.0 ";
damageLevelTolerance[0] = 0.99;

   damageEmitter[1] = VehicleBurnEmitter;
damageEmitterOffset[1] = "0.0 0.0 0.0 ";
damageLevelTolerance[1] = 1.0;

    handsOnVehicle = 1;

   numDmgEmitterAreas = 1;

   initialExplosionProjectile = KeiCarExplosionProjectile;
   initialExplosionOffset = 0;         //offset only uses a z value for now

   burnTime = 4000;

   finalExplosionProjectile = KeiCarFinalExplosionProjectile;
   finalExplosionOffset = 0.5;          //offset only uses a z value for now


   minRunOverSpeed    = 2;   //how fast you need to be going to run someone over (do damage)
   runOverDamageScale = 5;   //when you run over someone, speed * runoverdamagescale = damage amt
   runOverPushScale   = 1.2; //how hard a person you're running over gets pushed

function KeiCarAltoVehicle::onAdd(%this, %obj) //replace X with the vehicle's datablock name
{
Parent::onAdd(%this, %obj);
VehicleSpeedCheck(%obj);
}
};


It'd be much appreciated
Put the code outside of the vehicle's datablock (which begins with the first "{" and ends with "};".

Do you mind adding me on steam so that this would be a bit easier and faster to communicate between eachother? My steam is Insert Name Here

Quote from: corrected code
datablock WheeledVehicleData(KeiCarAltoVehicle)
{
   isCitiVehicle = 1;
   
   category = "Vehicles";
   displayName = " ";
   shapeFile = "./KeiCarAlto.dts"; //"~/data/shapes/skivehicle.dts"; //
   emap = true;
   minMountDist = 3;
   
   numMountPoints = 4;
   mountThread[0] = "sit";
   mountThread[1] = "sit";
   mountThread[2] = "sit";
   mountThread[3] = "sit";

   maxDamage = 200.00;
   destroyedLevel = 200.00;
   energyPerDamagePoint = 160;
   speedDamageScale = 1.04;
   collDamageThresholdVel = 20.0;
   collDamageMultiplier   = 0.02;

   massCenter = "0 0.2 0.4";
   //massBox = "2 5 1";

   maxSteeringAngle = 0.85;  // Maximum steering angle, should match animation
   integration = 4;           // Force integration time: TickSec/Rate
   //tireEmitter = VehicleTireEmitter; // All the tires use the same dust emitter

   // 3rd person camera settings
   cameraRoll = false;         // Roll the camera with the vehicle
   cameraMaxDist = 8.5;         // Far distance from vehicle
   cameraOffset = 4;        // Vertical offset from camera mount point
   cameraLag = 0.0;           // Velocity lag of camera
   cameraDecay = 0.75;        // Decay per sec. rate of velocity lag
   cameraTilt = 0.3;
   collisionTol = 0.1;        // Collision distance tolerance
   contactTol = 0.1;

   useEyePoint = false;   

   defaultTire   = KeiCarTire;
   defaultSpring   = KeiCarSpring;
   flatTire   = jeepFlatTire;
   flatSpring   = jeepFlatSpring;

   numWheels = 4;

   // Rigid Body
   mass = 200;
   density = 5.0;
   drag = 4.5;
   bodyFriction = 0.6;
   bodyRestitution = 0.6;
   minImpactSpeed = 10;        // Impacts over this invoke the script callback
   softImpactSpeed = 10;       // Play SoftImpact Sound
   hardImpactSpeed = 15;      // Play HardImpact Sound
   groundImpactMinSpeed    = 10.0;

   // Engine
   engineTorque = 2500; //3500;       // Engine power
   engineBrake = 200;         // Braking when throttle is 0
   brakeTorque = 2000;        // When brakes are applied
   maxWheelSpeed = 30;        // Engine scale by current speed / max speed

   rollForce      = 900;
   yawForce      = 600;
   pitchForce      = 1000;
   rotationalDrag      = 0;

   // Advanced Steering
   steeringAutoReturn = true;
   steeringAutoReturnRate = 1;
   steeringAutoReturnMaxSpeed = 10;
   steeringUseStrafeSteering = true;
   steeringStrafeSteeringRate = 0.08;
   
   // Energy
   maxEnergy = 100;
   jetForce = 3000;
   minJetEnergy = 30;
   jetEnergyDrain = 2;

   splash = jeepSplash;
   splashVelocity = 4.0;
   splashAngle = 67.0;
   splashFreqMod = 300.0;
   splashVelEpsilon = 0.60;
   bubbleEmitTime = 1.4;
   splashEmitter[0] = VehicleFoamDropletsEmitter;
   splashEmitter[1] = VehicleFoamEmitter;
   splashEmitter[2] = VehicleBubbleEmitter;
   mediumSplashSoundVelocity = 10.0;   
   hardSplashSoundVelocity = 20.0;   
   exitSplashSoundVelocity = 5.0;
      
   //mediumSplashSound = "";
   //hardSplashSound = "";
   //exitSplashSound = "";
   
   // Sounds
   //   jetSound = ScoutThrustSound;
   //engineSound = idleSound;
   //squealSound = skidSound;
   softImpactSound = slowImpactSound;
   hardImpactSound = fastImpactSound;
   //wheelImpactSound = slowImpactSound;

   //   explosion = VehicleExplosion;
   justcollided = 0;

   uiName = "KeiCar - Alto";
   rideable = true;
      lookUpLimit = 0.50;
      lookDownLimit = 0.50;

   paintable = true;
   
   damageEmitter[0] = VehicleBurnEmitter;
   damageEmitterOffset[0] = "0.0 0.0 0.0 ";
   damageLevelTolerance[0] = 0.99;

   damageEmitter[1] = VehicleBurnEmitter;
   damageEmitterOffset[1] = "0.0 0.0 0.0 ";
   damageLevelTolerance[1] = 1.0;

      handsOnVehicle = 1;

   numDmgEmitterAreas = 1;

   initialExplosionProjectile = KeiCarExplosionProjectile;
   initialExplosionOffset = 0;         //offset only uses a z value for now

   burnTime = 4000;

   finalExplosionProjectile = KeiCarFinalExplosionProjectil e;
   finalExplosionOffset = 0.5;          //offset only uses a z value for now


   minRunOverSpeed    = 2;   //how fast you need to be going to run someone over (do damage)
   runOverDamageScale = 5;   //when you run over someone, speed * runoverdamagescale = damage amt
   runOverPushScale   = 1.2; //how hard a person you're running over gets pushed
};

function KeiCarAltoVehicle::onAdd(%this, %obj)
{
   Parent::onAdd(%this, %obj);
   VehicleSpeedCheck(%obj);
}
note how the chunk of code is outside, and not inside of the datablock code chunk