Jump to content

setVehicleGravity not working


KillaMarci

Recommended Posts

Hey I'm kinda new to scripting so be easy on me here :)

I got the following script:

root=getRootElement() 
function grav () 
theVehicle = getPedOccupiedVehicle( getLocalPlayer()) 
setVehicleGravity(theVehicle,0,1,0) 
end 
addEventHandler("onClientResourceStart",root,grav) 
  

It's supposed to change the vehicles gravity to the value I've given. It has worked once (the very first time) but after that it didn't work anymore.

Debug says "Bad Argument @ setVehicleGravity"

I've tried literally anything but it doesn't want to work. Any ideas? Thanks in advance

Link to comment

Hey just tried it, doesn't work either :/ Thank You for trying though!

@Aiboforcen: Well he is in a vehicle (spawning in a vehicle, race mode)

EDIT: Thought I'd let you guys know that the gravity change works with the colspheres I've made, I only need this to test the map basically since I had to split the map file in two parts

Link to comment

on resource start you're getting a vehicle (which player is in) pointer to a variable (theVehicle).

later player vehicle can change, but theVehicle variable will point to the old vehicle.

also the gravity of the new vehicle will be standard again.

so either get player vehicle and set graivty with marker/colshape events (but dont place vehicle change pickups if you dont want the gravity to be reset)

or use some vehicle event like onClientVehicleEnter.

Link to comment

Alright I need to pick this topic up again since I've got another problem...

When the player dies during the map the gravity is normal again on respawn. I want the gravity to be the same as the one in the last colsphere so I did this:

actioncol10 = createColSphere (-51.339508056641,331.89874267578,204.09896850586, 26 ) 
function col10i (kaka, matchingDimensions ) 
if kaka == getLocalPlayer() then 
theVehicle = getPedOccupiedVehicle(kaka) 
setVehicleGravity(theVehicle,0,0,-1) 
x,y,z = getVehicleGravity(theVehicle) -- gets the gravity so I can use it below  
end 
end 
addEventHandler("onClientColShapeHit",actioncol10,col10i) 
  
function backup (dplayer) 
if dplayer == getLocalPlayer() then 
theVehicle = getPedOccupiedVehicle(dplayer) 
setVehicleGravity(theVehicle,x,y,z) -- this is where the gravity of the last colsphere is supposed to go when player spawns 
end 
end 
addEventHandler("onClientPlayerSpawn",getRootElement(),backup) 

This just doesn't work...no errors, no anything. Guess it's because of what Aiboforcen meant with updating theVehicle variable...well how could I do that? :? (without colspheres or markers or anything)

Link to comment

Hai thar

The updating is fine, it's cause spawning in race is a little bit different. onClientPlayerSpawn is when the player respawns, but race hasn't put him in his vehicle yet. I usually use on(Client)PlayerVehicleEnter when scripting for race (re)spawns.

I still see another problem with your "backup" tho, what if the player keeps respawning untill he's past one or more previous colshapes?

What you could do is create a table that links all checkpoints to a colshape, and restore the gravity that way.

Link to comment

I still see another problem with your "backup" tho, what if the player keeps respawning untill he's past one or more previous colshapes?

What you could do is create a table that links all checkpoints to a colshape, and restore the gravity that way.

I put 5-6 checkpoints after each gravity change to prevent exactly that from happening (ofc it can still happen if you really tried :P)

Gonna try what you suggested in a bit, thanks

EDIT: Works great. Thanks a lot man :P mr. green might get a new map today

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