Game Development Community

dev|Pro Game Development Curriculum

Digital Speedometer

by Tim Heldna · 02/16/2007 (9:20 am) · 6 comments

A digital speedometer that displays speed in km/h if you are mounted in (and driving) a vehicle. It works across a network and is completely scripted.

Credits go to Zod and Stefan Lundmark for their assistance in optimizing this code.

Installation

  • First download the files required by the display: digitalSpeedHud.zip (4 KB)

  • Extract the font file Digital Numbers 36 (ansi).uft to common/ui/cache

  • Add the following code to client/ui/customProfiles.cs
  • //--------------------------------------
    // Digital Speedometer GUI (Client)
    //--------------------------------------
    new GuiControlProfile ("DigitalNumbers")
    {
       opaque    = false;
       fontType  = "Digital Numbers";
       fontSize  = 36;
       fontColor = "0 240 25";
    };
    //--------------------------------------

  • Add this to client/init.cs
  • // Digital Speedometer GUI
       exec("./ui/vehicleHUD.gui");
       exec("./scripts/vehicleHUD.cs");
       // Digital Speedometer GUI

  • Place the vehicleHUD.gui file in client/ui

  • Place the vehicleHUD.cs file in client/scripts

  • Add this to the Armor::onMount method inside of player.cs
  • function Armor::onMount(%this,%obj,%vehicle,%node)
    {
       // Digital Speedometer GUI
       // Only show the speedometer for drivers & not passengers
       if(%node == 0)
          CommandToClient(%obj.client, 'vehicleHUD', "push");
       // Digital Speedometer GUI
    }

  • Add this to the Armor::onUnmount method inside of player.cs
  • function Armor::onUnmount( %this, %obj, %vehicle, %node )
    {
       // Digital Speedometer GUI
       CommandToClient(%obj.client, 'vehicleHUD', "pop");
       // Digital Speedometer GUI
    }

    That's it. Run your game, mount a vehicle and test it out.

    i5.photobucket.com/albums/y189/fjs/digitalSpeedHud.jpg

    #1
    02/17/2007 (6:51 pm)
    Very Useful. Looks Great!
    #2
    02/20/2007 (12:54 pm)
    Slick looking Gui!
    #3
    02/21/2007 (7:43 pm)
    Shutup, GUI's aren't my strong point :P
    #4
    04/01/2007 (6:34 pm)
    Your resource is great, but i settled on this basic gui element, i thought id post it as a quick speedometer alternative.
    //
    new GuiConsoleTextCtrl() {
    canSaveDynamicFields = "0";
    Profile = "GuiDefaultProfile";
    HorizSizing = "right";
    VertSizing = "bottom";
    position = "8 480";
    Extent = "61 13";
    MinExtent = "8 2";
    canSave = "1";
    Visible = "1";
    hovertime = "1000";
    expression = "getcontrolobjectspeed();";
    };
    #5
    04/10/2007 (7:55 am)
    Do the onmount and onunmount changes need to be replaced or added to?
    #6
    04/10/2007 (9:49 am)
    Added to.