KillaMarci Posted January 1, 2011 Share Posted January 1, 2011 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
Jumper_Mych Posted January 1, 2011 Share Posted January 1, 2011 Unless theVehicle = getPedOccupiedVehicle( getLocalPlayer()) function grav () setVehicleGravity(theVehicle,0,1,0) end addEventHandler("onClientResourceStart",getRootElement,grav) Link to comment
Aibo Posted January 1, 2011 Share Posted January 1, 2011 because theVehicle can be false if player is not in a vehicle. hence the bad argument. Link to comment
KillaMarci Posted January 1, 2011 Author Share Posted January 1, 2011 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
Aibo Posted January 1, 2011 Share Posted January 1, 2011 but vehicle can change, and you're not updating theVehicle variable. Link to comment
KillaMarci Posted January 1, 2011 Author Share Posted January 1, 2011 Jumper's script also worked once right now...he only had an error in the EventHandler (had to be getRootElement()) Link to comment
Jumper_Mych Posted January 1, 2011 Share Posted January 1, 2011 Try, Without with Element theVehicle = getPedOccupiedVehicle( getLocalPlayer()) function grav () setVehicleGravity(theVehicle,0,1,0) end addEventHandler("onClientResourceStart",grav) Link to comment
KillaMarci Posted January 2, 2011 Author Share Posted January 2, 2011 @Jumper: Doesn't work either (not even once like the other one) Bad Argument @ addEventHandler @Aiboforcen: What exactly do you mean by updating theVehicle variable? I'm struggeling to get something to work Link to comment
Jumper_Mych Posted January 2, 2011 Share Posted January 2, 2011 theVehicle = getPedOccupiedVehicle( getLocalPlayer()) function grav () setVehicleGravity(theVehicle,0,1,0) end addEventHandler("onClientResourceStart",rootElement,grav) Try Link to comment
KillaMarci Posted January 2, 2011 Author Share Posted January 2, 2011 Nope, again Bad Argument @ EventHandler (most likely because of the rootElement) Link to comment
Aibo Posted January 2, 2011 Share Posted January 2, 2011 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
trustno1 Posted January 2, 2011 Share Posted January 2, 2011 function grav (mister) if mister == getLocalPlayer() then theVehicle = getPedOccupiedVehicle(mister) setVehicleGravity(theVehicle,0,1,0) end end addEventHandler("onClientVehicleEnter",getRootElement(),grav) Link to comment
KillaMarci Posted January 2, 2011 Author Share Posted January 2, 2011 works like a charm man...thanks alot! Link to comment
KillaMarci Posted January 6, 2011 Author Share Posted January 6, 2011 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
SDK Posted January 6, 2011 Share Posted January 6, 2011 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
KillaMarci Posted January 6, 2011 Author Share Posted January 6, 2011 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 ) Gonna try what you suggested in a bit, thanks EDIT: Works great. Thanks a lot man mr. green might get a new map today Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now