Jump to content

[HELP] How to Avoid empty cars pushing


Rouzbeh

Recommended Posts

Yes, when you freeze an element it cannot be moved unless you change it's state.

  
function toggleFreezeState(thePlayer, theSeat) 
    if(theSeat == 0) 
       if(isElementFrozen(source)) then 
           setElementFrozen(source, false) 
       else 
           setElementFrozen(source, true) 
       end 
    end 
end 
addEventHandler("onVehicleExit", root, toggleFreezeState) 
addEventHandler("onVehicleEnter", root, toggleFreezeState) 
  

Link to comment
You could try freezing the cars client-side for players that are on foot.

That's not possible, unless a client side freeze only applies to the client it's triggered for, haven't tested that tho and you would still have the issue that you can't see the difference wherever the his player is on foot or in a vehicle.

I've also seen some disadvantages with implementations like this such as players who use a packer truck to rise a frozen vehicle up in the air, then it just hangs there which would look really strange on a roleplay server.

Solution

Something you could try is to use the code by crismar and then add a clientside part which triggers on the event: onClientVehicleCollision. Now, as you can see this has a hitelement which you basically pass to the server side, if the hit element is a vehicle then set the vehicle unfrozen, otherwise ignore.

Client:

addEventHandler("onClientVehicleCollision", root, 
function(collider,force, bodyPart, x, y, z, nx, ny, nz) 
    if collider and isElement(collider) and getElementType(collider) == "vehicle" then 
        triggerServerEvent("disableFrozenState", localPlayer, collider) 
    end    
end) 

Server:

function disableFrozen( theElement ) 
    setElementFrozen(theElement, false) 
end 
addEvent("disableFrozenState", true ) 
addEventHandler("disableFrozenState", resourceRoot, disableFrozen) 

Link to comment

You could manipulate handling so that all vehicles are too heavy for on-foot people to push. Since all cars would have increased mass, one vehicle would be able to push another just like previously, while peds/players would be unable to push it. I have done this in my server. Note that this solution will require you to completely change vehicle handling since higher mass = more momentum, thus braking deceleration, engine inertia, engine acceleration, and possibly braking bias would need to be changed in order to compensate for higher mass. You should also increase drag by the same multiplier as mass, so your car will decelerate at normal speed when accelerator button is released.

You don't have to trigger the Event

that function is shared (client and Server Sides)

Clientside setElementFrozen would change the state only on the current client - what if another client was syncing the car? It would't move on the server...

Link to comment
You could manipulate handling so that all vehicles are too heavy for on-foot people to push. Since all cars would have increased mass, one vehicle would be able to push another just like previously, while peds/players would be unable to push it. I have done this in my server. Note that this solution will require you to completely change vehicle handling since higher mass = more momentum, thus braking deceleration, engine inertia, engine acceleration, and possibly braking bias would need to be changed in order to compensate for higher mass. You should also increase drag by the same multiplier as mass, so your car will decelerate at normal speed when accelerator button is released.

i did try your method and changed mass, braking deceleration, engine inertia, engine acceleration and ... but now cars seems a bit unnormally :roll:

Link to comment

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...