Xwad Posted April 4, 2016 Posted April 4, 2016 Im trying to brake the vehicle when i stop pressing the "w". Its not working function brake() local vehicle = getPedOccupiedVehicle(localPlayer) local id = getElementModel ( vehicle ) if id == 432 then setControlState ( vehicle,"handbrake", true ) end end bindKey ( "w", "up", brake )
Dealman Posted April 4, 2016 Posted April 4, 2016 It's running client-side I suppose since you're using localPlayer? Read the wiki entry for setControlState more thoroughly. Only server-side need an element, a player element - not a vehicle element. Using it client-side, you needn't enter any element since it's run on the client. So it's obvious you want to do it on the client. function brake() local vehicle = getPedOccupiedVehicle(localPlayer) local id = getElementModel(vehicle) if(id == 432) then setControlState("handbrake", true) end end bindKey("w", "up", brake) Other than that, make sure you use debugscript to catch any errors and warnings. Go to the wiki to further study the function that is outputting an error and thus help yourself instead of rushing to the forums. In my opinion, trial and error is what programming and scripting is all about - best way to learn it.
Dealman Posted April 5, 2016 Posted April 5, 2016 So try and debug it. Try without checking if the id is 432, add output messages to see where it fails or if it runs at all.
Deepu Posted April 6, 2016 Posted April 6, 2016 Bro.. Simple logic... Just figure this logic-map out... function something( ... ) if(getPedControlState("w") == false) then setPedControlState("s"); -- I know the function is wrong.. this is just the logic map end end I hope you understood. if you didn't then I'll show it in the codes.
Deepu Posted April 6, 2016 Posted April 6, 2016 Bro.. Simple logic... Just figure this logic-map out... function something( ... ) if(getPedControlState("w") == false) then setPedControlState("s"); -- I know the function is wrong.. this is just the logic map end end I hope you understood. if you didn't then I'll show it in the codes.
KariiiM Posted April 6, 2016 Posted April 6, 2016 Bro.. Simple logic... Just figure this logic-map out... function something( ... ) if(getPedControlState("w") == false) then setPedControlState("s"); -- I know the function is wrong.. this is just the logic map end end I hope you understood. if you didn't then I'll show it in the codes. Deepu, you're totally wrong, "(getPed/setPed)ControlState works only with the peds not with local player since it's client sided
KariiiM Posted April 6, 2016 Posted April 6, 2016 Bro.. Simple logic... Just figure this logic-map out... function something( ... ) if(getPedControlState("w") == false) then setPedControlState("s"); -- I know the function is wrong.. this is just the logic map end end I hope you understood. if you didn't then I'll show it in the codes. Deepu, you're totally wrong, "(getPed/setPed)ControlState works only with the peds not with local player since it's client sided
Xwad Posted April 6, 2016 Author Posted April 6, 2016 I just want to brake the vehicle when i stop pressing the "w"
Xwad Posted April 6, 2016 Author Posted April 6, 2016 I just want to brake the vehicle when i stop pressing the "w"
KariiiM Posted April 6, 2016 Posted April 6, 2016 @Xwad, I tried to make a proper code for you: Here you go: try it and tell me the result, because it's not tested --client sided ! bindKey("w","up", function () local localPlayer = getLocalPlayer() local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle then local driver = getVehicleController(vehicle) local theID = getElementModel(vehicle) if (driver == localPlayer and theID == 432) then setControlState("handbrake", true) end end end)
KariiiM Posted April 6, 2016 Posted April 6, 2016 @Xwad, I tried to make a proper code for you: Here you go: try it and tell me the result, because it's not tested --client sided ! bindKey("w","up", function () local localPlayer = getLocalPlayer() local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle then local driver = getVehicleController(vehicle) local theID = getElementModel(vehicle) if (driver == localPlayer and theID == 432) then setControlState("handbrake", true) end end end)
Xwad Posted April 6, 2016 Author Posted April 6, 2016 not working:/ nothing happens.. Not even debugscript appears!
Xwad Posted April 6, 2016 Author Posted April 6, 2016 not working:/ nothing happens.. Not even debugscript appears!
Xwad Posted April 6, 2016 Author Posted April 6, 2016 Wait! Now i tested it with another id and its working! So its only not working with the rhino! Why is that?
Xwad Posted April 6, 2016 Author Posted April 6, 2016 Wait! Now i tested it with another id and its working! So its only not working with the rhino! Why is that?
KariiiM Posted April 6, 2016 Posted April 6, 2016 Yeah I got it, try it now bindKey("w","up", function () local localPlayer = getLocalPlayer() local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle then local driver = getVehicleController(vehicle) local theID = getElementModel(vehicle) if (driver == localPlayer and theID == 432) then setControlState("handbrake", false) end end end)
KariiiM Posted April 6, 2016 Posted April 6, 2016 Yeah I got it, try it now bindKey("w","up", function () local localPlayer = getLocalPlayer() local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle then local driver = getVehicleController(vehicle) local theID = getElementModel(vehicle) if (driver == localPlayer and theID == 432) then setControlState("handbrake", false) end end end)
Deepu Posted April 6, 2016 Posted April 6, 2016 @Xwad.. Make sure that yu have attached the function to the right event cuz that might cause problems and bugs too. If its alright proceed to step 2: if getControlState("accelerate") == false then setControlState("handbrake", true); end if its not working in client side use it in server side by placing the first argument as "playername" in both of the functions
Deepu Posted April 6, 2016 Posted April 6, 2016 @Xwad.. Make sure that yu have attached the function to the right event cuz that might cause problems and bugs too. If its alright proceed to step 2: if getControlState("accelerate") == false then setControlState("handbrake", true); end if its not working in client side use it in server side by placing the first argument as "playername" in both of the functions
Xwad Posted April 6, 2016 Author Posted April 6, 2016 Deepu the problem is with the rhino. I think this is an mta sa bug. Its working 100% with all vehicles only with the rhino not!
Xwad Posted April 6, 2016 Author Posted April 6, 2016 Deepu the problem is with the rhino. I think this is an mta sa bug. Its working 100% with all vehicles only with the rhino not!
KariiiM Posted April 6, 2016 Posted April 6, 2016 Deeputhe problem is with the rhino. I think this is an mta sa bug. Its working 100% with all vehicles only with the rhino not! Did you even used my last code?
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