Jump to content

stopping rhino tank turret movoment


Xwad

Recommended Posts

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 by Guest
Link to comment
  • Moderators

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

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

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
  • Moderators

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

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

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

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