Jump to content

Creating a weapon and attaching it on a vehicle


Recommended Posts

Hello there,

I've been trying to create a weapon (uzi) and attach it on a vehicle (hydra) the weapon should fire when I click the left mouse button.

I am stuck at the very beginning of the script (trying to get the uzi to spawn) and I just cannot progress any further.

function hydraGuns()
    local vehicle = getPedOccupiedVehicle(localPlayer)
    if(vehicle)then
        if getElementModel(vehicle) == 520 then
            local x, y, z = getElementPosition(vehicle)
            local weapon = createWeapon("uzi", x, y, z)
			outputChatBox ("Hydra guns are installed")
        end
    end
end

What am I doing wrong?

 

 

Link to comment

@Mr.Loki

Thanks for your reply but you´re giving me tips on my next step which I haven´t reached yet.

Right now I am trying to get the uzi to spawn, but it doesn´t work for some reason. 

I think the problem might be that the uzi spawns somewhere, but not on the x,y,z coordinates of the player/vehicle.

What could the problem be that the uzi doesn´t spawn?

Link to comment

Is that your full code (the one you posted)? If so, you never attached that function to an eventHandler. How would MTA know, you want that piece of code to run when the player enters a hydra?

Edited by pa3ck
  • Like 1
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...