Noah_Antilles Posted May 16, 2017 Share Posted May 16, 2017 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
Addlibs Posted May 16, 2017 Share Posted May 16, 2017 (edited) Is hydraGuns() ever called? Maybe make it on a command or attach it to onClientVehicleEnter Edited May 16, 2017 by MrTasty 1 Link to comment
Noah_Antilles Posted May 16, 2017 Author Share Posted May 16, 2017 Thanks for your reply, as far as I can see the uzi should spawn when I enter a Hydra. On one point I actually managed to have the uzi spawn, but soon after it didn't work anymore. would it be better to have the uzi spawn when I press left mouse? Link to comment
Elmatus Posted May 16, 2017 Share Posted May 16, 2017 Spawning a weapon doesn't make it fire. You can use the function setWeaponState (theWeapon, "firing") to make it fire (i.e when you press the left mouse button) Link to comment
Noah_Antilles Posted May 17, 2017 Author Share Posted May 17, 2017 @Elmatus I know spawning a weapon doesn't make it fire, but since I am a beginner I try to make my script in little steps. First try to spawn the weapon > try to attach it to the vehicle > make it fire on left click. Right now I am stuck on spawning the weapon, that's why I asked for help Link to comment
Mr.Loki Posted May 17, 2017 Share Posted May 17, 2017 After creating the weapon attach it to the Hydra with attachElements Link to comment
Noah_Antilles Posted May 17, 2017 Author Share Posted May 17, 2017 @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
pa3ck Posted May 17, 2017 Share Posted May 17, 2017 (edited) 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 May 17, 2017 by pa3ck 1 Link to comment
Noah_Antilles Posted May 17, 2017 Author Share Posted May 17, 2017 Oh of course I am a retard. I totally forgot that. I got it working now, an uzi spawns and is attached to the Hydra. Now I will try to make it fire on left mouse button Thanks for helping me! 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