Vehicle Speed Limiter?

Started by Kewun, Aug 08, 2016, 06:50 PM

Previous topic - Next topic

Kewun

I want to limit vehicle speeds, or if player drives too fast, he must pay a fine of $500

is there a possible way to do that? if so, how ?

Stormeus

#1
Your best bet would be to check the player's speed on the client side and ping the server with a special packet when the player is going too fast. Trying to do this on the server side would be too CPU-intensive for a realtime system like a VC:MP server.

What you would do is check on every frame if:
1. The player is in a vehicle.
2. Their vehicle is going above a certain speed.

And when that happens, you send a stream to the server that then triggers a fine.

Bear in mind that you also need to determine what other conditions lead to a fine. Using this naive approach without any modification will trigger a $500 fine for every single frame that a player is driving overspeed, or $15,000 per second at 30fps. If you set a flag when the player goes over initially and set it to false when they're below the speed limit, they'd risk getting charged by accident for holding the W key down for just a little too long.

Personally I'm not sure this is something that is perfectly solvable by a script, and since I've mostly been involved with roleplay servers, I'd say this is an issue for someone roleplaying a police officer to handle.

Kewun

;c cuz im doing a roleplay serv.. well, shit.. what about Vehicle.Speed function?

Kewun

or, saving the fine to ini ( worst way ), then adding a player wanted level + 1, if he is continously speeding, then just cancel if he has a fine already
thats the worst wayi trought

Stormeus

Quote from: Kewun on Aug 08, 2016, 07:19 PM;c cuz im doing a roleplay serv.. well, shit.. what about Vehicle.Speed function?

You will probably lag the server.

Quote from: Kewun on Aug 08, 2016, 07:23 PMor, saving the fine to ini ( worst way ), then adding a player wanted level + 1, if he is continously speeding, then just cancel if he has a fine already

You will definitely lag the server.

Mötley

Maybe, Just maybe if you could get the handling data similar to Theremins code in [LU] you might have something.

http://forum.liberty-unleashed.co.uk/index.php/topic,2498.0.html

anything above whatever your speed limits are just fine them. but other than that possibility no clue man.

@Stormeus might have a good response for that,

Stormeus

If you're comfortable with reconfiguring handling and don't need a system for fining people like you suggested, yes, you could just use VC:MP's vehicle handling functions to throttle everyone's top speed.

Kewun

hmm.. maybe maybe.

Is there any Vehicle.Gear function ? or i will have to mod handling in server
i wanted to add gears up, down ;c

aXXo

It is possible to add gears using vehicle handling.
Get vehicle's top speed by reading handling data. Divide it by 5 to split it into 5 numbers.
Add gears to keybinds. When player notches up a gear, increase vehicle's top speed. On going down a gear, decrease the top speed.

Kewun

But it will also set it for other players ;c

Kewun

else if (cmd == "gear")
{
if ( !player.Vehicle ) {
MessagePlayer("[#ff0000]You must be in vehicle to change gears!",player)
return false;
}
if ( text == "7" )
{
player.Vehicle.SetHandlingData(13,350)
MessagePlayer("[#00ff00]Oye!! you changed your gear to 7, watchout for cops",player)
}
if ( text == "6" )
{
player.Vehicle.SetHandlingData(13, 300)
MessagePlayer("[#00ff00]You changed your vehicle gear to 6",player)
}
else if ( text == "5" )
{
player.Vehicle.SetHandlingData(13,250)
MessagePlayer("[#00ff00]You changed your vehicle gear to 5",player)
}
else if (text=="4")
{
player.Vehicle.SetHandlingData(13,200)
MessagePlayer("[#00ff00]You changed your vehicle gear to 4",player)
}
else if (text=="3")
{
player.Vehicle.SetHandlingData(13,150)
MessagePlayer("[#00ff00]You changed your vehicle gear to 3",player)
}
else if (text=="2")
{
player.Vehicle.SetHandlingData(13,100)
MessagePlayer("[#00ff00]You changed your vehicle gear to 2", player);
}
else if (text=="1")
{
player.Vehicle.SetHandlingData(13,50)
MessagePlayer("[#00ff00]You changed your vehicle gear to 1", player);
}
}

somehow i made it eh

Kewun

+ bind keys

function onScriptLoad()
{
gear1 <- BindKey(true, 0x31,0,0)
gear2 <- BindKey(true, 0x32,0,0)
gear3 <- BindKey(true, 0x33,0,0)
gear4 <- BindKey(true, 0x34,0,0)
gear5 <- BindKey(true, 0x35,0,0)
gear6 <- BindKey(true, 0x36,0,0)
gear7 <- BindKey(true, 0x37,0,0)
}
function onKeyDown(player,key)
{
if ( key == gear1 )
{
onPlayerCommand(player,"gear","1")
}
if ( key == gear2 )
{
onPlayerCommand(player,"gear","2")
}
if ( key == gear3)
{
onPlayerCommand(player,"gear","3")
}
if ( key == gear4 )
{
onPlayerCommand(player,"gear","4")
}
if ( key == gear5 )
{
onPlayerCommand(player,"gear","5")
}
if ( key == gear6 )
{
onPlayerCommand(player,"gear","6")
}
if ( key == gear7 )
{
onPlayerCommand(player,"gear","7")
}
}

KAKAN

That's shit, why would you need to make a command though?
Just put them inside the if conditions :p
oh no

Kewun

put it then.  i only posted a example how it would look like

Kewun

and i found bug in bind keys
if you have numbers in your password in login or register, for example, if u write /login 123456, the bindkeys will be executed after you press enter