[Release] Speed-o-Meter

Started by DizzasTeR, Mar 04, 2017, 07:38 AM

Previous topic - Next topic

DizzasTeR

I mean why do you even send streams from server to client when it can be simply achieved on client-side.

Paste the following code in their appropriate functions.

- SERVER SIDE-
function onPlayerEnterVehicle(player, vehicle, door) {
    local Stream = Stream();
Stream.WriteInt( 50 );
Stream.WriteInt( vehicle.ID );
Stream.WriteString( "true" );
Stream.SendStream( player );
}

function onPlayerExitVehicle(player, vehicle) {
    local Stream = Stream();
Stream.WriteInt( 50 );
Stream.WriteInt( 0 );
Stream.WriteString( "false" );
Stream.SendStream( player );
}

- CLIENT SIDE -
sX <- GUI.GetScreenSize().X;
sY <- GUI.GetScreenSize().Y;

Speedometer <- {
GUI = { SpeedLabel = null },
Time = null,
PVehicle = null
}

function Script::ScriptLoad() {
Speedometer.GUI.SpeedLabel <- GUILabel( VectorScreen( sX * 0.06, sY * 0.65 ), Colour( 255, 255, 255, 255 ), "Speed: N/A" );
Speedometer.GUI.SpeedLabel.FontSize = 15;
Speedometer.GUI.SpeedLabel.FontFlags = GUI_FLAG_TEXT_TAGS | GUI_FFLAG_BOLD | GUI_ALIGN_CENTER;
}

function Script::ScriptProcess() {
if( !Speedometer.PVehicle ) {
Speedometer.GUI.SpeedLabel.Text = "Speed: N/A";
return true;
}

if( Speedometer.PVehicle.Type == OBJ_VEHICLE ) {
local speed = Speed( Speedometer.PVehicle );
Speedometer.GUI.SpeedLabel.Text = "Speed: " + speed + " m/s";
}
}

function Server::ServerData(stream) {
    local type = stream.ReadInt();

    switch(type) {
        case 50:
        local vehicleID = stream.ReadInt();
        local Toggle = stream.ReadString();

        if( Toggle == "true" ) {
            Speedometer.PVehicle = World.FindVehicle( vehicleID );
        }
        else {
            Speedometer.PVehicle = null;
        }
        break;
    }
}

function Speed(vehicle)
{
local sX = ::pow( vehicle.Speed.X, 2 )
local sY = ::pow( vehicle.Speed.Y, 2 )
local sZ = ::pow( vehicle.Speed.Z, 2 )

local SumSpeed = ( sX + sY + sZ );

local avgSpeed = ::sqrt( SumSpeed ) * 50 * 3.6;
return round( avgSpeed, 0 );
}

function round(value, precision) {
    local factor = ::pow(10.0, precision);
    return ::floor(value * factor + 0.5) / factor;
}

- PREVIEW -


Credits: round function taken from kennedyarz's post.

Zone_Killer

Bohemia Is God Of Punjabi Rap
Yo Yo Honey Singh tou chutiya hai

EK.IceFlake

m/s lol, is this a science class?

NicusorN5

You can easily convert it.

DizzasTeR

Quote from: EK.IceFlake on Mar 04, 2017, 09:18 AMm/s lol, is this a science class?

Couldn't expect anything better from you mate. :-\

EK.IceFlake


DizzasTeR

Are you literally challenging me? I didn't point to you in the sense that you can't make a better script I actually meant the comment of yours

Jekko


DizzasTeR


Luis_Labarca

My server RP
IP: 51.222.28.159:8194

Shadow

#10
You don't really need streams for this though. You can put all the workload on the client.

Like this http://pastebin.com/1C3ajn6W
QuotePS:is trash is ur home language??

Sebastian

Quote from: Shadow on Mar 04, 2017, 08:22 PMYou can put all the workload on the client.

vehicle.GetOccupant( slotID ) seems bugged to me...

DizzasTeR

Quote from: sseebbyy on Mar 05, 2017, 09:34 PM
Quote from: Shadow on Mar 04, 2017, 08:22 PMYou can put all the workload on the client.

vehicle.GetOccupant( slotID ) seems bugged to me...

It is bugged. I tried it.

Xmair

#13
Just tried client side coding for the first time :P
https://youtu.be/0xHkMHGXp2U

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

Shadow

Quote from: sseebbyy on Mar 05, 2017, 09:34 PM
Quote from: Shadow on Mar 04, 2017, 08:22 PMYou can put all the workload on the client.

vehicle.GetOccupant( slotID ) seems bugged to me...

It worked pretty well for me in the race server..
QuotePS:is trash is ur home language??