The online racing simulator
G Force Output Button
I was reading forum earlier about someone wanting a way to measure and show gforce (http://www.lfsforum.net/showthread.php?p=1502458#post1502458) and I wondered if it could be done with lapper.

Well, it can!

Assuming my maths is correct, the code is as follows:


<?php 
Event OnAcceleration
$userName )

$AccelerationStartSpeedMph 1# At which speed to start measuring time. In Mph
$AccelerationEndSpeedMph 60# At which speed to stop measuring time. In Mph
$AccelerationStartSpeed 1# At which speed to start measuring time. In km/h
$AccelerationEndSpeed 100# At which speed to stop measuring time. In km/h

$gravity_mph 21.93685# An acceleration of 21.93685 mph per second is equal to 1g (0 - 100 mph in 1 second = 4.56g)
$gravity_kph =35.30394# An acceleration of 35.30394 kp/h per second is equal to 1g

$ass GetCurrentPlayerVar("AccelerationStartSpeed"); # Starting speed
$aes GetCurrentPlayerVar("AccelerationEndSpeed"); # End speed
$at GetCurrentPlayerVar("AccelerationTime"); # Acceleration time achieved from start to end speed
$us GetCurrentPlayerVar("UnitSpeed"); # Unit of the speed of the player's car

$gforce_velocity_difference = ($aes $ass);
$gforce_accel $gforce_velocity_difference/$at;
$gforce_mph round(($gforce_accel/$gravity_mph),2);
$gforce_kph round(($gforce_accel/$gravity_kph),2);

IF (
$us "mph")
THEN
         openPrivButton
"gforce",77,60,46,8,5,5,32,langEngine("%{main_gforce}%",$gforce_mph ));        
ELSE
         
openPrivButton"gforce",77,60,46,8,5,5,32,langEngine("%{main_gforce}%",$gforce_kph ));
ENDIF                                                                                                 
EndEvent
?>


And don't forget to put following in your language file;

<?php 
LANG 
"EN"
main_gforce =  "^7You pulled ^1{0} ^7g's";
EndLang
?>


If you want to make increase or decrease the number of decimal places, (above code outputs to 2), so change the number at end of $gforce_mph and $gforce_kph to suit. If you take away the round() function, it gives 5 or 6 decimal places.

Also, not sure, but I suppose it's possible (but beyond me) to save the gforce "scores" in one of the lapper databases and output as a table to show best/highest gforce.

txt attachement is for my workings out - NOT lapper code.

Aide Memoir:
gravity = 9.80665 metres per second

9.80665 m/s = 21.936851 mph or 35.30394 km/h
Attached images
lapper gforce message.png
Attached files
lfs gforce.txt - 1.3 KB - 266 views
I implemented this in PRISM, your math is pretty close, enough for it to work.


<?php 
php
class gmeter extends Plugins {
    const 
NAME 'G-Force Meter';
    const 
AUTHOR "sinanju & Dygear";
    const 
VERSION '0.1.0';
    const 
DESCRIPTION 'Shows a G-Force meter.';

    private 
$MPH 21.93685;    # 1G = An acceleration delta of 21.93685 mph/second.
    
private $KPH 35.30394;    # 1G = An acceleration delta of 35.30394 kph/second.

    
private $BTNs = array();
    private 
$TIMEs = array();
    private 
$SPEEDs = array();

    public function 
__construct() {
        
$this->registerPacket('onMCI'ISP_MCI);
    }
    public function 
onMCI($Packet) {
        
$cTime microtime(TRUE);
        foreach (
$Packet->Info as $CompCar) {
            
// Spawn a new button instance if one is not here.
            
if (!isset($this->BTNs[$CompCar->PLID])) {
                
$this->BTNs[$CompCar->PLID] = new IS_BTN;
                
$this->BTNs[$CompCar->PLID]->T(184)->L(164)->W(10)->H(6)->BStyle(ISB_DARK ISB_RIGHT 1)->Send();
                
$this->BTNs[$CompCar->PLID]->W(0)->H(0);
            }
            
            
// Speeds
            
$cSpeed = (($CompCar->Speed 32768) * 100) * 2.2369362920544;
            
$lSpeed = (isset($this->SPEEDs[$CompCar->PLID])) ? $this->SPEEDs[$CompCar->PLID] : 0;

            
// Times
            
$lTime = (isset($this->TIMEs[$CompCar->PLID])) ? $this->TIMEs[$CompCar->PLID] : 0;

            
// Get gForce
            
$gForce round(($cSpeed $lSpeed) / ($cTime $lTime) / $this->MPH2);

            
// Update Button
            
$this->BTNs[$CompCar->PLID]->Text(sprintf('%.2f'$gForce))->Send();
            
            
// Save State
            
$this->TIMEs[$CompCar->PLID] = $cTime;
            
$this->SPEEDs[$CompCar->PLID] = $cSpeed;
        }
    }
}
?>

Also made a circular gforce button.

Might get in way of seeing where you're going a bit though.

You will need to unzip the gbutton.zip file and extract gbutton.lpr.

This is an add-on script, so put in your /includes folder and alter your addonsused.lpr script by adding following line;

include( "./gbutton.lpr");




EDIT: Thanks Dygear - I must have been typing this as you were loading your post
Attached images
lapper circular gforce message.png
Attached files
gbutton.zip - 1015 B - 249 views
Cool feature!
I'll implement the button in my script.

Keep up the good work

Tim
Amended the circular g-force button so it's in better position - not so intrusive when driving.
Attached images
Lapper circular gforce message _ alternate position.png
Attached files
gbutton _ alternate position.zip - 1 KB - 245 views
Very Nice Sinanju!
Quote from Dygear :I implemented this in PRISM, your math is pretty close, enough for it to work.

are buttons even out yet? :3
Quote from Fire_optikz001 :Very Nice Sinanju!

are buttons even out yet? :3

They are on the github repo for sure, 0.3.0 should of had a working buttons interface.

FGED GREDG RDFGDR GSFDG