Xwad Posted March 7, 2015 Posted March 7, 2015 Hi. I want to make a script like this. What functions need i use? Thanks.
Dimmitry007 Posted March 7, 2015 Posted March 7, 2015 (edited) nvm mistake Edited March 7, 2015 by Guest
Xwad Posted March 7, 2015 Author Posted March 7, 2015 NoHope what do you mean that there is no createweapon function? What functions need i use than?
xeon17 Posted March 7, 2015 Posted March 7, 2015 Ignore him , the functions exist. https://wiki.multitheftauto.com/wiki/CreateWeapon https://wiki.multitheftauto.com/wiki/FireWeapon https://wiki.multitheftauto.com/wiki/Cl ... _functions
Xwad Posted March 7, 2015 Author Posted March 7, 2015 I made this but it does not work and i think i must give a bind for mouse 1 no? function attach ( source, commandName ) local vehicle = getElementPosition ( source ) --Get the vehicle position attachElements ( minigun, source, 0, 0, 5 ) --Attach the weapon to the vehicle. local weapon = createWeapon("minigun", x, y, z + 1) --Create a Weapon setWeaponClipAmmo(weapon, 99999) setWeaponState(weapon, "firing") setWeaponProperty(weapon, "fire_rotation", 0, -30, 0) -- Optionally adjust for model rotation (this value will be different for other weapons) end addCommandHandler ( "attach", attach )
xeon17 Posted March 7, 2015 Posted March 7, 2015 There was so much errors in your code , try this should work but i didn't tested it function attach ( ) local theVehicle = getPedOccupiedVehicle ( localPlayer ) if theVehicle then local x,y,z = getElementPosition ( theVehicle ) local weapon = createWeapon("minigun", x, y, z + 1) attachElements ( minigun, theVehicle, 0, 0, 5 ) setWeaponClipAmmo(weapon, 99999) setWeaponState(weapon, "firing") setWeaponProperty(weapon, "fire_rotation", 0, -30, 0) end end addCommandHandler ( "attach", attach )
Xwad Posted March 7, 2015 Author Posted March 7, 2015 It works but not like in the video. Its always fireing and i want to make it possible to enter the minigun and shoot with mouse 1. I think i need for that an another function no?
Dealman Posted March 7, 2015 Posted March 7, 2015 You need a lot more than just that, you can set it up to fire in a variety of ways. For one, you can use getKeyState inside a render event. Or you can just bind a key using bindKey. As looking around with it, I was working on something like this before, got pretty close to release - but as always I keep jumping between projects of mine. Here's a little snippet of what I used to look around with my weapons(with restrictions and sensitivity); local aimSensitivity = 30; function rotateGun_Handler(cX, cY, aX, aY, wX, wY, wZ) local oX, oY, oZ, oRX, oRY, oRZ = getElementAttachedOffsets(theWeapon); if (oRX-((cY-0.5)*aimSensitivity) > 345 or oRX-((cY-0.5)*aimSensitivity) < 30) then -- Pitch Restriction oRX = oRX-((cY-0.5)*aimSensitivity); end if (oRZ-((cX-0.5)*aimSensitivity) > 330 or oRZ-((cX-0.5)*aimSensitivity) < 50) then -- Yaw Restriction oRZ = oRZ-((cX-0.5)*aimSensitivity); end setElementAttachedOffsets(theWeapon, oX, oY, oZ, oRX, oRY, oRZ); setCursorPosition(screenW/2, screenH/2); end I updated these with onClientCursorMove.
Xwad Posted March 7, 2015 Author Posted March 7, 2015 Thanks and what functions do i need to enter the minigun and fire with it?
Addlibs Posted March 7, 2015 Posted March 7, 2015 To fire it, use either fireWeapon(weapon) (single fire) or setWeaponState(weapon, "firing") (continouos firing)
Xwad Posted March 7, 2015 Author Posted March 7, 2015 And what function need i use to enter the weapon like in the video?
Addlibs Posted March 7, 2015 Posted March 7, 2015 setElementPosition, attachElements, etc. You need to write up your own function that would handle mounting the weapon.
Xwad Posted March 7, 2015 Author Posted March 7, 2015 i think that i did something wrong function attach ( ) local theVehicle = getPedOccupiedVehicle ( localPlayer ) if theVehicle then local x,y,z = getElementPosition ( theVehicle ) local weapon = createWeapon("minigun", x, y, z + 1) attachElements ( minigun, theVehicle, 0, 0, 5 ) setWeaponClipAmmo(weapon, 99999) setWeaponState(weapon, "firing") setWeaponProperty(weapon, "fire_rotation", 0, -30, 0) end end addCommandHandler ( "attach", attach ) local aimSensitivity = 30; function rotateGun_Handler(cX, cY, aX, aY, wX, wY, wZ) local oX, oY, oZ, oRX, oRY, oRZ = getElementAttachedOffsets(theWeapon); if (oRX-((cY-0.5)*aimSensitivity) > 345 or oRX-((cY-0.5)*aimSensitivity) < 30) then -- Pitch Restriction oRX = oRX-((cY-0.5)*aimSensitivity); end if (oRZ-((cX-0.5)*aimSensitivity) > 330 or oRZ-((cX-0.5)*aimSensitivity) < 50) then -- Yaw Restriction oRZ = oRZ-((cX-0.5)*aimSensitivity); end setElementAttachedOffsets(theWeapon, oX, oY, oZ, oRX, oRY, oRZ); setCursorPosition(screenW/2, screenH/2); end function consoleSetPlayerPosition ( source, commandName, posX, posY, posZ ) setElementPosition ( source, posX, posY, posZ ) end addCommandHandler ( "setpos", consoleSetPlayerPosition )
Dealman Posted March 7, 2015 Posted March 7, 2015 Well yeah, all you did was copy and paste the stuff and make no changes for it to work whatsoever...
3B00DG4MER Posted March 7, 2015 Posted March 7, 2015 Not sure local screenW,screenH = guiGetScreenSize() local weapon function attach ( ) local theVehicle = getPedOccupiedVehicle ( localPlayer ) if theVehicle then local x,y,z = getElementPosition ( theVehicle ) weapon = createWeapon("minigun", x, y, z + 1) attachElements ( weapon, theVehicle, 0, 0, 1 ) setWeaponClipAmmo(weapon, 99999) setWeaponState(weapon, "firing") setWeaponProperty(weapon, "fire_rotation", 0, -30, 0) end end addCommandHandler ( "attach", attach ) local aimSensitivity = 30; function rotateGun_Handler(cX, cY, aX, aY, wX, wY, wZ) local oX, oY, oZ, oRX, oRY, oRZ = getElementAttachedOffsets(weapon); if (oRX-((cY-0.5)*aimSensitivity) > 345 or oRX-((cY-0.5)*aimSensitivity) < 30) then -- Pitch Restriction oRX = oRX-((cY-0.5)*aimSensitivity); end if (oRZ-((cX-0.5)*aimSensitivity) > 330 or oRZ-((cX-0.5)*aimSensitivity) < 50) then -- Yaw Restriction oRZ = oRZ-((cX-0.5)*aimSensitivity); end --setCameraTarget(localPlayer,weapon) setCameraTarget(weapon) --setCameraMatrix(wX,wY,wZ) setElementAttachedOffsets(weapon, oX, oY, oZ, oRX, oRY, oRZ); setCursorPosition(screenW/2, screenH/2); end addEventHandler( "onClientCursorMove", getRootElement( ), rotateGun_Handler)
Xwad Posted March 7, 2015 Author Posted March 7, 2015 its alwys shooting and i cant enter the minigun
Dealman Posted March 7, 2015 Posted March 7, 2015 Do you even read the code? When you create the minigun, you have this line of code; setWeaponState(weapon, "firing") Of course it will always be firing when you set its weapon state to firing Edit: To "enter" the minigun, you're best off using collision spheres, attach it to the minigun and trigger an event whenever a client enters it. So whenever a player is inside that sphere, and he press for example E, he will be attached to the minigun.
Xwad Posted March 8, 2015 Author Posted March 8, 2015 I tryed to make it but i cant. If i want to change the state for no fireing than what need i write ?
steadyfi Posted March 8, 2015 Posted March 8, 2015 I tryed to make it but i cant. If i want to change the state for no fireing than what need i write ? To change the state of firing replace "firing" to "ready" https://wiki.multitheftauto.com/wiki/SetWeaponState
Xwad Posted March 8, 2015 Author Posted March 8, 2015 Thanks! And what function need i use to enter the minigun?
steadyfi Posted March 8, 2015 Posted March 8, 2015 Thanks! And what function need i use to enter the minigun? To "enter" the minigun, you're best off using collision spheres, attach it to the minigun and trigger an event whenever a client enters it. So whenever a player is inside that sphere, and he press for example E, he will be attached to the minigun.
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