Jump to content

[Help] Vehicle Pushing


Rouzbeh

Recommended Posts

Hi, im working on a rpg server. i want when a player do handbrake then players can't Push that vehicle (just players, not other vehicles),

i have vehicle system include handbrake and etc , just need an idea for how to make this 'Anti Vehicle Pushing'?

i did tried freeze vehicle, but this is not good idea and socks for RPG...

Link to comment
I'm not sure if that is possible, I'm afraid. You could try to mess around with the vehicle handling, though I never got any decent successes.

i saw that in a MTA RP Server! and was very cool system

i already tried increase mass of vehicle but not work....

Link to comment
It's a bit of an weird way to do it, but I guess you could get the position and set it everytime it changes but it'll be too server or client intensive I guess.

hmm, this way have problems like when an another car hit or accident to the car will not move.... and maybe more bugs happend...

as i know that rp server did'nt freeze car... server name was: Owl-Gaming

Link to comment

What if you set the vehicle's mass to an extremely high value? I haven't tested if it makes you like a tank so you'll have to see for yourself.

https://wiki.multitheftauto.com/wiki/SetVehicleHandling

Here's some code I've written a while back, changed it a bit for you. (it's not perfect)

function resetHandling() 
    if isPedInVehicle(player) then 
        local veh = getPedOccupiedVehicle(player) 
        if veh then 
            local model = getElementModel(veh) 
            local propTable = getOriginalHandling(model) 
            for k,v in pairs(propTable) do 
                setVehicleHandling(veh,k,v) 
            end 
        end 
    end 
end 
  
function changeHandling(player) 
    if isPedInVehicle(player) then 
        local veh = getPedOccupiedVehicle(player) 
        if veh then 
            local model = getElementModel(veh) 
            local propTable = getOriginalHandling(model) 
     
            local prop = "mass" 
            local value = propTable[prop] 
            setVehicleHandling(veh,prop,value+70000) 
        end 
    end 
end 
  
function bindKeys(source) 
    bindKey(source,"lshift","down",changeHandling) 
    bindKey(source,"lshift","up",resetHandling) 
end 
addEventHandler("onVehicleEnter",root,bindKeys) 

Edited by Guest
Link to comment

It's not sure that onClientVehicleCollision will trigger when a player tries to push the vehicle as it's the player colliding to the vehicle and not the opposite, it's worth a try however. And once it triggers, the controls of the player may toggle temporary to force the player to stop using: SetControlState and ToggleControl. I've been using these for players with high latency for a while with good results so it might be a useful combination if implemented right. Good luck.

Link to comment

Why you ain't using setElementFrozen

Here is the script from the wiki.

-- Serverside --

-- This function freezes the specified player's vehicle, if he's in one 
function toggleFreezeStatus ( thePlayer ) 
    -- if he is in a vehicle, 
    if getPedOccupiedVehicle ( thePlayer ) then 
        -- get the vehicle element 
        local playerVehicle = getPlayerOccupiedVehicle ( thePlayer ) 
        -- get the current freeze status 
        local currentFreezeStatus = isElementFrozen ( playerVehicle ) 
        -- get the new freeze status (the opposite of the previous state) 
        local newFreezeStatus = not currentFreezeStatus 
        -- set the new freeze status 
        setElementFrozen ( playerVehicle, newFreezeStatus ) 
    end 
end 
  
-- now bind a key to this function for all players. 
-- first get a list of all players 
local connectedPlayers = getElementsByType ( "player" ) 
-- then, for each player, 
for i, aPlayer in ipairs(connectedPlayers) do 
    -- bind the player's "p" key to the toggleFreezeStatus function 
    bindKey ( aPlayer, "p", "down", "Toggle freeze status", toggleFreezeStatus ) 
end 

Link to comment

You can't set control state of a vehicle. There's one possible solution, placing a ped inside the vehicle while no one's there and making him apply the handbrake constantly, but then it'd be impossible to re-enter the car (can't jack peds, can't enter while they're inside). The only way to fix that second problem would be deleting the ped when the player enters, but the player won't enter at that instance therefore one will need to press F/Enter twice to re-enter a car.

Link to comment
You can't set control state of a vehicle. There's one possible solution, placing a ped inside the vehicle while no one's there and making him apply the handbrake constantly, but then it'd be impossible to re-enter the car (can't jack peds, can't enter while they're inside). The only way to fix that second problem would be deleting the ped when the player enters, but the player won't enter at that instance therefore one will need to press F/Enter twice to re-enter a car.

I think you can force the player to enter the car again afterwards, or maybe that only works on peds?

Link to comment

Freezing a vehicle/element would be a terrible thing to do.. a simple BMX could stop a freaking rhino with the handbrake applied to it. You can do a few things which indeed have been said in previous comments;

1. Whenever the vehicle gets streamed in, add a ped in there which applies the handbrake every now and then. This is however quite heavy for your server if you have let's say.. 50 people running around in a garage at different locations.

2. Increase the mass of the vehicle, since that didn't work for you early you might want to try and set it to the maximum value of 100000.0 which should actually work. Even though, a player with a higher ping has always been stronger than a person with a normal ping in MTA.

3. Resetting the vehicle's position would be a really bad idea too. It'll make it look like a shocking thing if it's done in a wrong way and your server won't like it. If you however do want to do it this way, make sure you're resetting it with an onClientRender. But then again, it will be really intensive for your server..

4. If changing the mass doesn't work, you might have to try these handlings: fDragMult (dragCoeff), nPercentSubmerged (percentSubmerged, a ped can't be heavier nor push more than 99999kg I guess.. ).

5. A last thing you could do, which is actually more of a thing that can be done in RPGs but not in RP scripts; disable the collision for the vehicles. They'll be unable to be pushed or standing on top of them and things like that, yet they can still be used to get in and things like that.

Link to comment

Changing the mass is also a bad idea since mass is included in vehicle damage calculations.

Also drag is air resistance, pretty sure it would not be of any help.

Best workaround I can think of is to spawn a ped and warp the ped into the driver seat. Make the ped invisible using setElementAlpha. Then use setControlState to make the ped apply the GTA handbrake.

Link to comment

@Dealman, putting the pet in there and making him use the handbrake will make it unable to get in the vehicle since the event isn't being fired. The people in previous comments said so, can't confirm this though. Never saw anyone able to hijack a ped. To actually get this working you should bind a custom function to your F ( or enter_vehicle key ) and check if there is a ped in the closest vehicle, check the distance, remove the ped and force the user to get into that vehicle by executing the enter function again. Won't be so much trouble after all, if it works.

Link to comment
  • 2 weeks later...

yes i did tried dealman's way and i have an idea:

i have a car alert system and i can add and put ped in vehicle when player lock his/her vehicle from outside and remove when unlock...

so players can't push personal vehicles when that vehicle locked ...

i think this is best way...

Link to comment
  • 2 weeks later...
  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...