Kubimate Posted December 28, 2014 Share Posted December 28, 2014 (edited) Hi! I have a problem making a script with custom vehicle handling for race gamemode. I made a script that uses setModelHandling (also tried setVehicleHandling) and onResourceStart. It works, but when a player dies and respawns, the handling of his vehicle restores back to default. I don't know if I should somehow force the handling change to be permanent on resource start or if I should somehow make these changes apply everytime a player respawns? One solution i think of was to make an invisible marker on every checkpoint, and make setVehicleHandling onMarkerHit (which i managed to succesfully write), but it feels like a dumb solution and i know it can be done more efficient by good scripting. I tried using onClientPlayerSpawn, which is client side, and setVehicleHandling appears to be server side. I have no idea yet how to connect scripts like that, but I'm still learning. My tuning on marker hit script: function tuning(hitMarker, matchingDimension) if (matchingDimension) then local theVehicle = getPedOccupiedVehicle(source) if theVehicle then outputChatBox ("Tuned!") setVehicleHandling(theVehicle, "engineAcceleration", 35.0) end end end addEvent("onPlayerMarkerHit", true) addEventHandler("onPlayerMarkerHit", getRootElement(), tuning) My handling test script: function handlingChange ( ) setVehicleHadling(504, "EngineAcceleration", 35.0) end addEventHandler ( "onPlayerSpawn", getLocalPlayer(), handlingChange ) TL;DR How to keep starting handling changes after player respawn in a race gamemode? I'm a scripting beginner, please be nice to me! Any help will be appreciated! Edited December 30, 2014 by Guest Link to comment
Bonsai Posted December 28, 2014 Share Posted December 28, 2014 Try to use: https://wiki.multitheftauto.com/wiki/On ... hicleEnter Link to comment
Sterchit Posted December 29, 2014 Share Posted December 29, 2014 (edited) Idea with markers it's not so good as for me. So, edit :race/race_server.lua Find: -- launchRace function unfreezePlayerWhenReady(player) if not isValidPlayer(player) then outputDebug( 'MISC', 'unfreezePlayerWhenReady: not isValidPlayer(player)' ) return end if isPlayerNotReady(player) then outputDebug( 'MISC', 'unfreezePlayerWhenReady: isPlayerNotReady(player) for ' .. tostring(getPlayerName(player)) ) TimerManager.createTimerFor("map",player):setTimer( unfreezePlayerWhenReady, 500, 1, player ) else RaceMode.playerUnfreeze(player) outputDebug( 'MISC', 'unfreezePlayerWhenReady: setElementFrozen false for ' .. tostring(getPlayerName(player)) ) end end Under RaceMode.playerUnfreeze(player) Add your code local theVehicle = getPedOccupiedVehicle(source) if theVehicle then outputChatBox ("Tuned!") setVehicleHandling(theVehicle, "engineAcceleration", 35.0) end If you want to do this only for you then do: if getPlayerSerial(player) == "twoj_serial" then local theVehicle = getPedOccupiedVehicle(source) if theVehicle then outputChatBox ("Tuned!") setVehicleHandling(theVehicle, "engineAcceleration", 35.0) end end Edited December 29, 2014 by Guest Link to comment
Castillo Posted December 29, 2014 Share Posted December 29, 2014 This is the english section, please go to the polish section to speak polish. viewforum.php?f=124 Link to comment
Sterchit Posted December 29, 2014 Share Posted December 29, 2014 This is the english section, please go to the polish section to speak polish.viewforum.php?f=124 Edited my post then. Link to comment
Kubimate Posted December 29, 2014 Author Share Posted December 29, 2014 I don't really want to edit server files, I just need a 'standalone' resource which would only be used in one race map, edited and used in another, eventually. onPlayerSpawn Does not work, kinda... I made this script: function player_Spawn ( posX, posY, posZ, spawnRotation, theTeam, theSkin, theInterior, theDimension ) outputChatBox("SPAWNED") if isPedInVehicle (source) then outputChatBox("IN CAR") setModelHandling(504, "EngineAcceleration", 40) end end addEventHandler ( "onPlayerSpawn", getRootElement(), player_Spawn ) When I start the race, I got 'SPAWNED' message and my handling is changed, but it don't says 'IN CAR' as if the player was not in a car. So... why is handling applied? So, I tried removing isPedInVehicle check: function player_Spawn ( posX, posY, posZ, spawnRotation, theTeam, theSkin, theInterior, theDimension ) outputChatBox("SPAWNED") --if isPedInVehicle (source) then outputChatBox("IN CAR") setModelHandling(504, "EngineAcceleration", 40) --end end addEventHandler ( "onPlayerSpawn", getRootElement(), player_Spawn ) I got both messages and custom handling. Died, respawned, again both messages, but no handling. Next i tried with onPlayerVehicleEnter function enterVehicle ( theVehicle, seat, jacked ) outputChatBox("ENTERED") if isPedInVehicle (source) then outputChatBox("IN CAR") setVehicleHandling(theVehicle, "EngineAcceleration", 40) end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) Result: same as script above - I got both messages and custom handling. Died, respawned, again both messages, but no handling. So now the main question of this tread is going to be: what function is used by race gamemode to 'respawn' players in cars after they die, and what event should i listen to to execute handling change? Alternatively, I think about to make my script change handling to every players' car every second, so when a player dies and respawns, after 1 second my handling would be back. (This feels like the marker-on-every-checkpoint-poor-idea one ) Link to comment
Bonsai Posted December 29, 2014 Share Posted December 29, 2014 What does "setVehicleHandling" return? outputChatBox(tostring(setVehicleHandling(theVehicle, "EngineAcceleration", 40))) Link to comment
Kubimate Posted December 29, 2014 Author Share Posted December 29, 2014 I restarted MTA, and none of scripts from my previous post actually apply handling changes... What do I have to do to reload my script when testing? Anyway, as you asked, function enterVehicle ( theVehicle, seat, jacked ) if isPedInVehicle (source) then outputChatBox(tostring(setVehicleHandling(theVehicle, "EngineAcceleration", 40))) end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) returns false Link to comment
Bonsai Posted December 30, 2014 Share Posted December 30, 2014 The solution might be: "engineAcceleration" instead of "EngineAcceleration" e != E Link to comment
Kubimate Posted December 30, 2014 Author Share Posted December 30, 2014 Yes, you are right, it has to be lowercase e, now it works like a charm Thank you all for help! Final product: function enterVehicle ( theVehicle, seat, jacked ) if isPedInVehicle (source) and getElementModel (theVehicle) == 478 then setVehicleHandling(theVehicle, "mass", 1050.0) setVehicleHandling(theVehicle, "turnMass", 2000.0) setVehicleHandling(theVehicle, "dragCoeff", 3.3) setVehicleHandling(theVehicle, "centerOfMass", { 0.0, 0.1, -0.25 } ) setVehicleHandling(theVehicle, "percentSubmerged", 75) setVehicleHandling(theVehicle, "tractionMultiplier", 0.65) setVehicleHandling(theVehicle, "tractionLoss", 0.85) setVehicleHandling(theVehicle, "tractionBias", 0.5) setVehicleHandling(theVehicle, "numberOfGears", 4) setVehicleHandling(theVehicle, "maxVelocity", 130.0) setVehicleHandling(theVehicle, "engineAcceleration", 8.0) setVehicleHandling(theVehicle, "engineInertia", 3.0) setVehicleHandling(theVehicle, "driveType", "rwd") setVehicleHandling(theVehicle, "engineType", "petrol") setVehicleHandling(theVehicle, "brakeDeceleration", 6.5) setVehicleHandling(theVehicle, "brakeBias", 0.5) setVehicleHandling(theVehicle, "ABS", false) setVehicleHandling(theVehicle, "steeringLock", 35.0) setVehicleHandling(theVehicle, "suspensionForceLevel", 1.15) setVehicleHandling(theVehicle, "suspensionDamping", 0.1) setVehicleHandling(theVehicle, "suspensionHighSpeedDamping", 0.0) setVehicleHandling(theVehicle, "suspensionUpperLimit", 0.14) setVehicleHandling(theVehicle, "suspensionLowerLimit", -0.1) setVehicleHandling(theVehicle, "suspensionFrontRearBias", 0.55) setVehicleHandling(theVehicle, "suspensionAntiDiveMultiplier", 0.3) setVehicleHandling(theVehicle, "seatOffsetDistance", 0.25) setVehicleHandling(theVehicle, "collisionDamageMultiplier", 0.70) setVehicleHandling(theVehicle, "modelFlags", 0x40002804) setVehicleHandling(theVehicle, "handlingFlags", 0x4000001) setVehicleHandling(theVehicle, "headLight", long) setVehicleHandling(theVehicle, "tailLight", small) setVehicleHandling(theVehicle, "animGroup", 1) --outputChatBox("Handling changed successfully !") end end addEventHandler ( "onPlayerVehicleEnter", getRootElement(), enterVehicle ) 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