Jump to content

[Question]Aiming System


HustraDev

Recommended Posts

Hello Community,

i'm working on a tactical vehicle script , Basiclly i'm attaching a (machine gun) to the back of the (bobcat) vehicle, so that the player can hop in and used 

to be honest, i'm not sure that i have the entire idea on how to code it because ( i don't know how to make an aiming system ) i want to draw a crosshair on the screen and  i want the player to be able to rotate the weapon. so my question is how can i make an ( aiming system ) for this.

Edited by HustraDev
Link to comment
  • Moderators

There are several ways to do it.
One, if you use ped's camera rotation to rotate the minigun.

Basic example:
 

-- SERVER
createVehicle(getVehicleModelFromName("Bobcat"), 0, 5, 3)

addCommandHandler("aim", function(player)
    local vehicle = getPedOccupiedVehicle(player)
    if not vehicle then return outputChatBox("Use in vehicle...", player) end
	removePedFromVehicle(player)

    local object = createObject(2985, 0, 0, 0)
    setElementCollisionsEnabled(object, false)
	attachElements(object, vehicle, 0, -1.5, -0.25)
    attachElements(player, object,  -0.4, 0, 0.8)
    
    triggerClientEvent(player, "aim", resourceRoot, vehicle, object)
end)
-- CLIENT

local current

addEvent("aim", true)
addEventHandler("aim", resourceRoot, function(vehicle, object)
	current = { vehicle=vehicle, object=object }
	addEventHandler("onClientRender", root, aim)
end)

function aim()
	local camRot = getPedCameraRotation(localPlayer)
	setElementAttachedOffsets(current.object, 0, -1.5, -0.25, 0, 0, -camRot+90)
end

 

Edited by Patrick
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...