Jump to content

Attaching object to rhinos turret


Xwad

Recommended Posts

I made the script but its not working correctly:/ I set the rotation of the object but i also need to set the position. How can i do that? pls help

  
function object() 
local veh = getPedOccupiedVehicle ( localPlayer ) 
local x,y,z = getElementPosition(veh) 
local id = getElementModel ( veh ) 
if id == 432 then 
object = createObject ( 356, x,y,z) 
attachElements ( object, veh, 0, 0, 0, 0, 7, 96 ) 
addEventHandler("onClientRender", getRootElement(), rotate_object) 
end 
end 
addEventHandler("onClientVehicleEnter", getRootElement(), object) 
  
  
  
function rotate_object() 
local veh = getPedOccupiedVehicle ( localPlayer ) 
local tx,ty = getVehicleTurretPosition ( veh ) 
ty = math.deg ( -ty ) 
tx = math.deg ( tx ) 
setElementAttachedOffsets ( object, 0.56, 1.15, 1.3, 0, ty+7, tx+96) 
end 
  

Link to comment

one more question: why is this code not working? the projectile is not shooting

function shootProjectile() 
    local veh = getPedOccupiedVehicle(localPlayer) 
    if(veh) and getVehicleModel(veh) == 601 then     
    local tx, ty = getVehicleTurretPosition ( veh) 
        createProjectile(veh, 19, tx,ty,2) 
    end 
end 

Link to comment

Attaching an object to the center and then attach another object to rotate it correctly is honestly a genius way to get around the offset calculations lol

I do the same thing for a different usage

GetVehicleModel is deprecated, use getElementModel lol

Link to comment

I already did that. Now i have a new problem. Since 1.5.2 released your vreload script causes always game crashes so i decided to make a new script like yours. I created a script that makes possible to shoot projectiles with the swat tank. My problem is that the projectile is not shooting to the direction where the turret is looking at. I hope you can help me. Thanks

  
function shootProjectile()    local veh =getPedOccupiedVehicle(localPlayer)    if(veh) and getVehicleModel(veh) == 601then       local tx, ty = getVehicleTurretPosition (veh)        createProjectile(veh, 19, tx,ty,2)    endend 
  

Link to comment
- Change the cords for the crosshair issue solved..

Download the resource and you will see that its not so easy as you think, Its more complicated. If i change i crosshairs position that will not change the shooting direction..

now my only question is: I want to set the projectiles direction to the turrets direction. Whats the problem in my script?

function shootProjectile()    
local veh =getPedOccupiedVehicle(localPlayer)    
 if(veh) and getVehicleModel(veh) == 601then        
local tx, ty = getVehicleTurretPosition (veh)         
createProjectile(veh, 19, tx,ty,2)    endend 
  

Link to comment
- Change the cords for the crosshair issue solved..

Download the resource and you will see that its not so easy as you think, Its more complicated. If i change i crosshairs position that will not change the shooting direction..

now my only question is: I want to set the projectiles direction to the turrets direction. Whats the problem in my script?

function shootProjectile()    
local veh =getPedOccupiedVehicle(localPlayer)    
 if(veh) and getVehicleModel(veh) == 601then        
local tx, ty = getVehicleTurretPosition (veh)         
createProjectile(veh, 19, tx,ty,2)    endend 
  

function shootProjectile()   
local veh = getPedOccupiedVehicle(localPlayer)   
if(veh) and getVehicleModel(veh) == 601 then       
local tx, ty = getVehicleTurretPosition (veh)         
createProjectile(veh, 19, tx,ty,2)     
     end 
end 

Link to comment
  • 2 weeks later...

one more question: Why is the rx rotating in the wrong direction? it should be rotate up when the tanks turret barrel is rotating up. Its rotating to the opposite direction:/ the rz is working correctly! heres the code. Thanks in advance!

client.lua

function rotate_object(veh) 
local veh = getPedOccupiedVehicle ( localPlayer ) 
  
local _,_,rz = getVehicleComponentRotation(veh, "misc_a") 
local rx,_,_ = getVehicleComponentRotation(veh, "misc_b") 
  
triggerServerEvent("rotate_object", localPlayer, veh,rx,rz, localPlayer) 
end  

server.lua

  
function rotate_object(veh,rx,rz) 
  
local object = getElementData ( veh, "object" ) 
local object2 = getElementData ( veh, "object2" ) 
  
local weapon = getElementData ( veh, "weapon" ) 
  
setElementAttachedOffsets ( object, 0, 0, 0, 0, 7, rz+95) 
setElementAttachedOffsets ( object2, 0.9, -0.6, 3, 0, rx+0, 0) 
setElementAttachedOffsets ( weapon, 0.9, -0.6, 3, rx+7, 0, 0) 
end 
addEvent("rotate_object", true) 
addEventHandler("rotate_object", root, rotate_object) 
  

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