Mohamed_king Posted November 17, 2016 Share Posted November 17, 2016 local key = "mouse1" local isFirstView = false ------------- --------------------------------------------------------------------------------------------- local weapon = { } local weaponsobj = {} function CreateWeapon_c (vehicle,x,y,z) weaponsobj[source] = createObject(2953,0,0,0) weapon[source] = createWeapon("minigun",0,0+1,0) setWeaponAmmo(weapon[source],500) setWeaponProperty(weapon[source], "fire_rotation", 0,-40,0) setWeaponProperty(weapon[source], "damage",80) setElementAlpha(weapon[source],0) setElementAlpha(weaponsobj[source],0) attachElements(weapon[source],weaponsobj[source],0,-0.6,0,0,305,90) attachElements(weaponsobj[source],vehicle,0,-2.26,1.1,270,270,270) local vehicle = getPedOccupiedVehicle ( localPlayer ) if ( vehicle ) and ( getElementModel( vehicle ) == 400 ) then bindKeys () addHandllers () end addEvent("onBindToFire",true) addEventHandler("onBindToFire",root,CreateWeapon_c) function bindKeys () bindKey(key,"both","fire") bindKey(key,"up","ready") bindKey("v","up","viw") bindKey("k","down",toggleOfMy14Wea) setCameraClip(false,false) end function unBindKeys () unbindKey(key,"both","fire") unbindKey(key,"up","ready") unbindKey("v","up","viw") unbindKey("k","down", toggleOfMy14Wea) end function destroyElementsWEa () destroyElement(weapon[localPlayer]) destroyElement( weaponsobj[localPlayer]) setCameraClip(true,true) triggerServerEvent("destoryMYPUPWeapon",localPlayer,getWeaponVehicle ()) end function addHandllers () addEventHandler("onClientRender",root,drawAmmo) addEventHandler("onClientCursorMove",root,updateWeaponAndObj) --addEventHandler("onClientRender",root,updateWeaponAndObj) -- addCommandHandler('ready',readyState) addCommandHandler('fire',fireState) addCommandHandler("viw",viewChange) end function removeHandllers () removeEventHandler("onClientRender",root,drawAmmo) removeEventHandler ("onClientPreRender", root, updateCamera) removeEventHandler ("onClientCursorMove",root, freecamMouse) removeEventHandler("onClientCursorMove",root,updateWeaponAndObj) --- removeEventHandler("onClientRender",root,updateWeaponAndObj) -- removeCommandHandler('ready',readyState) removeCommandHandler('fire',fireState) removeCommandHandler("viw",viewChange) end function toggleOfMy14Wea () local veh = getWeaponVehicle () triggerServerEvent("destoryMYPUPWeapon",localPlayer,veh) destroyElementsWEa () unBindKeys () removeHandllers () setCameraTarget(localPlayer) end function drawAmmo (player) local x,y = guiGetScreenSize() local ammo = getWeaponAmmo(weapon[localPlayer]) local cammo = getWeaponClipAmmo(weapon[localPlayer]) dxDrawText ("Ammo :"..cammo.."-"..ammo, x*(1090/1366),y*( 240/768),x*( 55.0/1366), y*(182.0/768), tocolor ( 255, 255, 255, 255 ), 1.2, "pricedown", "left", "top", false, false, false ) dxDrawImage(x/2-70, y/2-160,128,128 , "cross.png", 0, 0, 0, tocolor(250, 4, 4, 255), false) if cammo <= 0 and ammo == 0 then toggleOfMy14Wea () end end local function getCameraRotation () local px, py, pz, lx, ly, lz = getCameraMatrix() local rotz = 6.2831853071796 - math.atan2 ( ( lx - px ), ( ly - py ) ) % 6.2831853071796 local rotx = math.atan2 ( lz - pz, getDistanceBetweenPoints2D ( lx, ly, px, py ) ) --Convert to degrees rotx = math.deg(rotx) rotz = -math.deg(rotz) return rotx, 180, rotz end function updateWeaponAndObj (_,_,_,_,worldx,worldy,worldz) local x,y,z = getElementPosition(weaponsobj[localPlayer]) local veh = getWeaponVehicle() local _,_,vehr = getElementRotation(veh) local rotationY = 0 local rotationZ = -getPedCameraRotation(localPlayer)-vehr -- -getPedCameraRotation(localPlayer) --getCameraRotation() local rotationX = (getCameraRotation())+270 setElementAttachedOffsets(weaponsobj[localPlayer],0,-2.26,1.1, rotationX,rotationY,rotationZ) local _,_,rotz = getElementRotation(weaponsobj[localPlayer]) triggerServerEvent("onClientMoveWeaponWe",localPlayer,rotz,x,y,z,rotationX,rotationY,rotationZ) end function getWeaponVehicle () local veh = getElementAttachedTo(weaponsobj[localPlayer]) if getElementData(veh,"isWeaponCar") == true then return veh end end function viewChange () if isFirstView == false then addEventHandler ("onClientPreRender", root, updateCamera) addEventHandler ("onClientCursorMove",root, freecamMouse) isFirstView = true elseif isFirstView == true then setCameraTarget(localPlayer) removeEventHandler ("onClientPreRender", root, updateCamera) removeEventHandler ("onClientCursorMove",root, freecamMouse) isFirstView = false end end function makeEff(elemnt,hitx,hity,hitz) if source == weapon[localPlayer] then triggerServerEvent("onClientPlayer14WeaponFilr",localPlayer,hitx,hity,hitz) end end addEventHandler("onClientWeaponFire",root,makeEff) --[[ function onExplorer () unBindKeys () destroyElement(weapon[localPlayer]) destroyElement( weaponsobj[localPlayer]) setCameraTarget(localPlayer) triggerServerEvent("destoryMYPUPWeapon",localPlayer,getWeaponVehicle()) removeHandllers () end addEvent("onExplodeer",true) addEventHandler('onExplodeer',getRootElement(),onExplorer) --]] function destoryMyWeapon () triggerServerEvent("destoryMYPUPWeapon",localPlayer,getWeaponVehicle()) destroyElement(weapon[localPlayer]) destroyElement( weaponsobj[localPlayer]) setCameraClip(true,true) unBindKeys () removeHandllers () setCameraTarget(localPlayer) end addEvent("onDestory",true) addEventHandler("onDestory",root,destoryMyWeapon) function onUnbindKeysCl () unBindKeys () end addEvent("onUnbindKeysCl",true) addEventHandler("onUnbindKeysCl",root,onUnbindKeysCl) function fireState (state) setWeaponState(weapon[localPlayer],"firing") setWeaponFiringRate(weapon[localPlayer],80) sendFireAndSoundForAll() end function readyState (stater) setWeaponState(weapon[localPlayer],"ready") stopFireAndSound () end function stopFireAndSound () triggerServerEvent("stopThatWea",localPlayer) end function sendFireAndSoundForAll () triggerServerEvent("sendFireStateToAll",localPlayer) end function sendMoveToAll (position,veh) triggerServerEvent("sendMyWeaponRTToAll",localPlayer,position,veh) end function OnVehEnter () bindKeys () end addEvent("onEnter",true) addEventHandler("onEnter",getRootElement(),OnVehEnter) function onWast () unBindKeys () toggleOfMy14Wea () removeHandllers () setCameraClip(true,true) end addEvent("onPlayerWasted14",true) addEventHandler("onPlayerWasted14",getRootElement(),onWast) local PI = math.pi local wasInVehicle = isPedInVehicle(localPlayer) local mouseSensitivity = 0.1 local rotX, rotY = 0,0 local mouseFrameDelay = 0 local idleTime = 2500 local fadeBack = false local fadeBackFrames = 50 local executeCounter = 0 local recentlyMoved = false local Xdiff,Ydiff function updateCamera () local nowTick = getTickCount() -- check if the last mouse movement was more than idleTime ms ago if wasInVehicle and recentlyMoved and not fadeBack and startTick and nowTick - startTick > idleTime then recentlyMoved = false fadeBack = true if rotX > 0 then Xdiff = rotX / fadeBackFrames elseif rotX < 0 then Xdiff = rotX / -fadeBackFrames end if rotY > 0 then Ydiff = rotY / fadeBackFrames elseif rotY < 0 then Ydiff = rotY / -fadeBackFrames end end if fadeBack then executeCounter = executeCounter + 1 if rotX > 0 then rotX = rotX - Xdiff elseif rotX < 0 then rotX = rotX + Xdiff end if rotY > 0 then rotY = rotY - Ydiff elseif rotY < 0 then rotY = rotY + Ydiff end if executeCounter >= fadeBackFrames then fadeBack = false executeCounter = 0 end end local camPosXr, camPosYr, camPosZr = getElementPosition(weapon[localPlayer]) --local camPosXr, camPosYr, camPosZr = getPedBonePosition (localPlayer, 6) local camPosXl, camPosYl, camPosZl = getElementPosition(weaponsobj[localPlayer]) --local camPosXl, camPosYl, camPosZl = getPedBonePosition (localPlayer, 7) local camPosX, camPosY, camPosZ = (camPosXr + camPosXl) / 2, (camPosYr + camPosYl) / 2, (camPosZr + camPosZl) / 2 local roll = 0 inVehicle = isPedInVehicle(localPlayer) -- note the vehicle rotation if inVehicle then local rx,ry,rz = getElementRotation(getPedOccupiedVehicle(localPlayer)) roll = -ry if rx > 90 and rx < 270 then roll = ry - 150 -- 180 end if not wasInVehicle then rotX = rotX + math.rad(rz) --prevent camera from rotation when entering a vehicle if rotY > -PI/5 then --force camera down if needed rotY = -PI/5 end end cameraAngleX = rotX - math.rad(rz) cameraAngleY = rotY + math.rad(rx) if getControlState("vehicle_look_behind") or ( getControlState("vehicle_look_right") and getControlState("vehicle_look_left") ) then cameraAngleX = cameraAngleX + math.rad(180) --cameraAngleY = cameraAngleY + math.rad(180) elseif getControlState("vehicle_look_left") then cameraAngleX = cameraAngleX - math.rad(90) --roll = rx doesn't work out well elseif getControlState("vehicle_look_right") then cameraAngleX = cameraAngleX + math.rad(90) --roll = -rx end else local rx, ry, rz = getElementRotation(localPlayer) if wasInVehicle then rotX = rotX - math.rad(rz) --prevent camera from rotating when exiting a vehicle end cameraAngleX = rotX cameraAngleY = rotY end wasInVehicle = inVehicle --Taken from the freecam resource made by eAi -- work out an angle in radians based on the number of pixels the cursor has moved (ever) local freeModeAngleZ = math.sin(cameraAngleY) local freeModeAngleY = math.cos(cameraAngleY) * math.cos(cameraAngleX) local freeModeAngleX = math.cos(cameraAngleY) * math.sin(cameraAngleX) -- calculate a target based on the current position and an offset based on the angle local camTargetX = camPosX + freeModeAngleX * 100 local camTargetY = camPosY + freeModeAngleY * 100 local camTargetZ = camPosZ + freeModeAngleZ * 100 -- Work out the distance between the target and the camera (should be 100 units) local camAngleX = camPosX - camTargetX local camAngleY = camPosY - camTargetY local camAngleZ = 0 -- we ignore this otherwise our vertical angle affects how fast you can strafe -- Calulcate the length of the vector local angleLength = math.sqrt(camAngleX*camAngleX+camAngleY*camAngleY+camAngleZ*camAngleZ) -- Normalize the vector, ignoring the Z axis, as the camera is stuck to the XY plane (it can't roll) local camNormalizedAngleX = camAngleX / angleLength local camNormalizedAngleY = camAngleY / angleLength local camNormalizedAngleZ = 0 -- We use this as our rotation vector local normalAngleX = 0 local normalAngleY = 0 local normalAngleZ = 1 -- Perform a cross product with the rotation vector and the normalzied angle local normalX = (camNormalizedAngleY * normalAngleZ - camNormalizedAngleZ * normalAngleY) local normalY = (camNormalizedAngleZ * normalAngleX - camNormalizedAngleX * normalAngleZ) local normalZ = (camNormalizedAngleX * normalAngleY - camNormalizedAngleY * normalAngleX) -- Update the target based on the new camera position (again, otherwise the camera kind of sways as the target is out by a frame) camTargetX = camPosX + freeModeAngleX * 100 camTargetY = camPosY + freeModeAngleY * 100 camTargetZ = camPosZ + freeModeAngleZ * 100 -- Set the new camera position and target setCameraMatrix (camPosX,camPosY, camPosZ+0.09, camTargetX, camTargetY, camTargetZ, roll) end function freecamMouse (cX,cY,aX,aY) --ignore mouse movement if the cursor or MTA window is on --and do not resume it until at least 5 frames after it is toggled off --(prevents cursor mousemove data from reaching this handler) if isCursorShowing() or isMTAWindowActive() then mouseFrameDelay = 5 return elseif mouseFrameDelay > 0 then mouseFrameDelay = mouseFrameDelay - 1 return end startTick = getTickCount() recentlyMoved = true -- check if the mouse is moved while fading back, if so abort the fading if fadeBack then fadeBack = false executeCounter = 0 end -- how far have we moved the mouse from the screen center? local width, height = guiGetScreenSize() aX = aX - width / 2 aY = aY - height / 2 rotX = rotX + aX * mouseSensitivity * 0.01745 rotY = rotY - aY * mouseSensitivity * 0.01745 local pRotX, pRotY, pRotZ = getElementRotation (localPlayer) pRotZ = math.rad(pRotZ) if rotX > PI then rotX = rotX - 2 * PI elseif rotX < -PI then rotX = rotX + 2 * PI end if rotY > PI then rotY = rotY - 2 * PI elseif rotY < -PI then rotY = rotY + 2 * PI end -- limit the camera to stop it going too far up or down if isPedInVehicle(localPlayer) then if rotY < -PI / 4 then rotY = -PI / 4 elseif rotY > -PI/15 then rotY = -PI/15 end else if rotY < -PI / 4 then rotY = -PI / 4 elseif rotY > PI / 2.1 then rotY = PI / 2.1 end end end السلام عليكم اني سويت مود دوشكة بدي مساعدة بدي شخص ادا ركب للسيارة وضغط ماوس1 يتم نقله للسيارة لليطلقة نار ممكن مساعدة ف كود وشكرا 1 Link to comment
#BrosS Posted November 17, 2016 Share Posted November 17, 2016 warpPedIntoVehicle ليش طارح كل المود 1 Link to comment
Mohamed_king Posted November 18, 2016 Author Share Posted November 18, 2016 9 hours ago, #BrosS said: warpPedIntoVehicle ليش طارح كل المود ممكن اضيفه لي انا معرفت وين انضيفه 9 hours ago, #BrosS said: warpPedIntoVehicle ليش طارح كل المود ولله طرحته مش كل يفهم طلبي Link to comment
mahmod3 Posted November 23, 2016 Share Posted November 23, 2016 كان انت عرفت ادير هادا كله معقولة معرفتش اديره انه ينقلك في السيارة من ورى ؟ 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