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.
Good.
m/s lol, is this a science class?
You can easily convert it.
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. :-\
Quote from: Doom_Kill3R on Mar 04, 2017, 09:42 AMQuote 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)
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
Nice work man.
Quote from: EK.IceFlake on Mar 04, 2017, 10:41 AMoh yeah?
...
Yeah.
https://www.youtube.com/watch?v=98iJ9179pvs&feature=youtu.be#
nice job
You don't really need streams for this though. You can put all the workload on the client.
Like this http://pastebin.com/1C3ajn6W
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...
Quote from: sseebbyy on Mar 05, 2017, 09:34 PMQuote 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.
Just tried client side coding for the first time :P
https://youtu.be/0xHkMHGXp2U
Quote from: sseebbyy on Mar 05, 2017, 09:34 PMQuote 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..