Xwad Posted March 15, 2016 Share Posted March 15, 2016 Hi. Is there any function to stop the rhinos turret roration? Thanks. Link to comment
Addlibs Posted March 15, 2016 Share Posted March 15, 2016 (edited) Try setVehicleAdjustableProperty setVehicleTurretPosition on onClientRender Sightly Offtopic: Please don't post if you don't know, you can make a dev wasting his time with your wrong "solutions". 1) I never claimed this to be the solution, I offered this as a possible solution. 2) I was pretty sure I used the method already once and it worked for me - seems like I remembered wrong, no need to get so rude. 3) Experimenting is never a waste of time Edited March 15, 2016 by Guest Link to comment
Xwad Posted March 15, 2016 Author Share Posted March 15, 2016 but on the rhino there are nothing adjustable:/ Link to comment
Moderators Citizen Posted March 15, 2016 Moderators Share Posted March 15, 2016 setVehicleAdjustableProperty on onClientRender Please don't post if you don't know, you can make a dev wasting his time with your wrong "solutions". I never tried to do that but my first attempt would be to use the getVehicleTurretPosition to get the rotations and if it is over the MAX_VALUE you want, then set it to MAX_VALUE using setVehicleTurretPosition . Just do that in an onClientRender. (Same for the MIN_VALUE). This should take I guess less than 10 lines of code. Link to comment
Xwad Posted March 15, 2016 Author Share Posted March 15, 2016 yeah i tryed that but its not working:/ function stop_turret_rotation() local veh = getPedOccupiedVehicle(localPlayer) local id = getElementModel ( veh ) if id == 432 or id == 601 then local x, y = getVehicleTurretPosition (veh) setVehicleTurretPosition ( veh, x, y ) end end function event() addEventHandler("onClientRender", root, stop_turret_rotation) end addCommandHandler("event", event) Link to comment
MIKI785 Posted March 15, 2016 Share Posted March 15, 2016 Well that makes no sense, you're simply setting it to what it is, it's like if the code didn't do anything at all. If you want to stop it altogether just try using setVehicleTurretPosition ( veh, 0, 0 ) It might need some adjustments if you want it to face forwards. Also, this: getElementModel ( veh ) Will throw warnings if the player is not in a vehicle, just put simple if not veh then return end before it. Link to comment
Xwad Posted March 15, 2016 Author Share Posted March 15, 2016 setVehicleTurretPosition ( veh, 0, 0 ) i dont want to make it like this. I want to stop the rhinos turret where it is looking at the time when i stop it Link to comment
Moderators Citizen Posted March 15, 2016 Moderators Share Posted March 15, 2016 I don't understand when you say "when I stop it" but I understood (I guess) that you want to be able to totaly freeze a turret when you stop the engine of the vehicle. So I made a reusable function (setVehicleTurretFrozen) to freeze a turret (will work if my attempt proposition from the previous post is working): addEventHandler("onClientRender", root, function () for k, veh in ipairs(getElementsByType("vehicle")) do local frozenPos = getElementData(veh, "_turretFrozenPos") if frozenPos then setVehicleTurretPosition(veh, frozenPos[1], frozenPos[2]) end end end) function setVehicleTurretFrozen(vehicle, frozen) if not vehicle or getElementType(vehicle) ~= "vehicle" then return false end if frozen == nil or type(frozen) ~= "bool" then return false end local model = getElementModel(veh) if model ~= 432 and model ~= 601 then return false end local value = nil if frozen then value = {getVehicleTurretPosition(vehicle)} end return setElementData(vehicle, "_turretFrozenPos", value) end Syntax: bool setVehicleTurretFrozen(vehicle turretVehicle, bool frozen) Returns: Returns true if the turret has been successfully frozen, false otherwise. Link to comment
Xwad Posted March 17, 2016 Author Share Posted March 17, 2016 so is this function (setVehicleTurretFrozen) exported? Link to comment
Addlibs Posted March 17, 2016 Share Posted March 17, 2016 This is a function you need to embed into your code (preferably at the top, or in another file [e.g. utils.lua] which would need to be loaded before the main code [loading order in meta.xml]). You will use it like an ordinary function, since it is the same as if you were to write up a function of your own in the code. Link to comment
Simple0x47 Posted March 17, 2016 Share Posted March 17, 2016 yeah i tryed that but its not working:/ Try this: local localPlayer = getLocalPlayer() function stop_turret_rotation() local veh = getPedOccupiedVehicle(localPlayer) local id = getElementModel ( veh ) if id == 432 or id == 601 then local x, y = getVehicleTurretPosition(veh) if x and y then setVehicleTurretPosition(veh, x, y) -- Forward Look end end end function event() addEventHandler("onClientRender", root, stop_turret_rotation) end addCommandHandler("event", event) Link to comment
Xwad Posted March 17, 2016 Author Share Posted March 17, 2016 Citizen i also tryed your code and its not working too:// Link to comment
Captain Cody Posted March 17, 2016 Share Posted March 17, 2016 You realize all that code does is set the turrent positon to the current position? -- Try thus -- local localPlayer = getLocalPlayer() function stop_turret_rotation() local veh = getPedOccupiedVehicle(localPlayer) local id = getElementModel ( veh ) if id == 432 or id == 601 then local x, y = getVehicleTurretPosition(veh) if x and y then setVehicleTurretPosition(veh, 0, 0) -- Forward Look end end end function event() addEventHandler("onClientRender", root, stop_turret_rotation) end addCommandHandler("event", event) Link to comment
Xwad Posted March 17, 2016 Author Share Posted March 17, 2016 I dont want to set it foward. I want to make that if i enter the command then the turret will stop at the position where it is. Link to comment
Captain Cody Posted March 17, 2016 Share Posted March 17, 2016 local localPlayer = getLocalPlayer() function stop_turret_rotation() local veh = getPedOccupiedVehicle(localPlayer) local id = getElementModel ( veh ) if id == 432 or id == 601 then setVehicleTurretPosition(veh, x1, y1) end end function event() addEventHandler("onClientRender", root, stop_turret_rotation) x1, y1 = getVehicleTurretPosition ( getPedOccupiedVehicle(localPlayer) ) end addCommandHandler("lockturrent", event) function event2 () removeEventHandler("onClientRender", root, stop_turret_rotation) end addCommandHandler("unlockturrent", event2) Link to comment
Moderators Citizen Posted March 19, 2016 Moderators Share Posted March 19, 2016 Citizen i also tryed your code and its not working too:// I tested my code and I actually did 2 typos (line 12 and 14), but now it's working (this is a client-side function and it's not exported ofc): client: addEventHandler("onClientRender", root, function () for k, veh in ipairs(getElementsByType("vehicle")) do local frozenPos = getElementData(veh, "_turretFrozenPos") if frozenPos then setVehicleTurretPosition(veh, frozenPos[1], frozenPos[2]) end end end) function setVehicleTurretFrozen(vehicle, frozen) if not vehicle or getElementType(vehicle) ~= "vehicle" then return false end if frozen == nil or type(frozen) ~= "boolean" then return false end local model = getElementModel(vehicle) if model ~= 432 and model ~= 601 then return false end local value = nil if frozen then value = {getVehicleTurretPosition(vehicle)} end return setElementData(vehicle, "_turretFrozenPos", value) end Sorry for the delay ! Best regards, Citizen Link to comment
Xwad Posted March 19, 2016 Author Share Posted March 19, 2016 Thanks Citizen! I go try it. Link to comment
Xwad Posted March 19, 2016 Author Share Posted March 19, 2016 both code are now working! thanks guys!! 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