Vice City: Multiplayer

Server Development => Scripting and Server Management => Client Scripting => Topic started by: DizzasTeR on Mar 04, 2017, 07:38 AM

Title: [Release] Speed-o-Meter
Post by: DizzasTeR on Mar 04, 2017, 07:38 AM
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 -
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FuYTuccM.png&hash=946da4ce8ec0ba43ca38b766129864b6de026de5)

Credits: round function taken from kennedyarz's post.
Title: Re: [Release] Speed-o-Meter
Post by: Zone_Killer on Mar 04, 2017, 09:13 AM
Good.
Title: Re: [Release] Speed-o-Meter
Post by: EK.IceFlake on Mar 04, 2017, 09:18 AM
m/s lol, is this a science class?
Title: Re: [Release] Speed-o-Meter
Post by: NicusorN5 on Mar 04, 2017, 09:34 AM
You can easily convert it.
Title: Re: [Release] Speed-o-Meter
Post by: DizzasTeR on Mar 04, 2017, 09:42 AM
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. :-\
Title: Re: [Release] Speed-o-Meter
Post by: EK.IceFlake on Mar 04, 2017, 10:41 AM
Quote from: Doom_Kill3R on Mar 04, 2017, 09:42 AM
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. :-\
Oh yeah?
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi.imgur.com%2F4csCWLQ.jpg&hash=ae98cb83a7be6df0f3ed2401b98bbdb018231409)
Title: Re: [Release] Speed-o-Meter
Post by: DizzasTeR on Mar 04, 2017, 10:44 AM
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
Title: Re: [Release] Speed-o-Meter
Post by: Jekko on Mar 04, 2017, 12:54 PM
Nice work man.
Title: Re: [Release] Speed-o-Meter
Post by: DizzasTeR on Mar 04, 2017, 01:11 PM
Quote from: EK.IceFlake on Mar 04, 2017, 10:41 AMoh yeah?
...

Yeah.

https://www.youtube.com/watch?v=98iJ9179pvs&feature=youtu.be#

Title: Re: [Release] Speed-o-Meter
Post by: Luis_Labarca on Mar 04, 2017, 04:56 PM
nice job
Title: Re: [Release] Speed-o-Meter
Post by: Shadow on Mar 04, 2017, 08:22 PM
You don't really need streams for this though. You can put all the workload on the client.

Like this http://pastebin.com/1C3ajn6W
Title: Re: [Release] Speed-o-Meter
Post by: Sebastian 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...
Title: Re: [Release] Speed-o-Meter
Post by: DizzasTeR on Mar 06, 2017, 01:28 AM
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.
Title: Re: [Release] Speed-o-Meter
Post by: Xmair on Mar 06, 2017, 08:46 AM
Just tried client side coding for the first time :P
https://youtu.be/0xHkMHGXp2U
Title: Re: [Release] Speed-o-Meter
Post by: Shadow on Mar 06, 2017, 09:45 AM
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..