HustraDev

Members
  • Content Count

    129
  • Joined

  • Last visited

Community Reputation

0 Neutral

About HustraDev

  • Rank
    Poot-butt

Details

  • Gang
    Hustra

Recent Profile Visitors

575 profile views
  1. السلام عليكم ورحمة الله وباركته اخواني لدي مشكلة في مود رشاش المود جاهز حملته من الموقع بس الفكرة اني ابي اعدل عليه واخلي الرشاش تابت في خلف ال Bobcat في سيارة بوب كات بس ابيه يركب وراء في الخلف الكود طويل لكن مو صعب انا حاولت اسوي attachElements للرشاش والسيارة ولكن فشلت ف ارجوكم ساعدوني لاني والله احتاجه لسيرفري الخاص وبارك الله فيكم اخواني Client : inUse = false inUse_s = false inUse_s2 = false inUse_s3 = false w, h = guiGetScreenSize () function create_client(weapon,weapon2,weapon3) local x,y,z = getElementPosition (weapon) local weapon_c = createWeapon("minigun", x,y,z) setElementCollisionsEnabled( weapon_c, false ) setWeaponState ( weapon_c, "ready" ) setElementAlpha ( weapon_c, 255 ) setWeaponFiringRate ( weapon_c , 60 ) setElementParent( weapon_c, weapon ) setWeaponProperty( weapon_c, "damage", 0) setWeaponProperty ( weapon_c, "fire_rotation", 0, -27, -5.5 ) setWeaponProperty ( weapon_c, "weapon_range", 10000 ) setWeaponProperty ( weapon_c, "target_range", 10000 ) setWeaponClipAmmo( weapon_c, 250 ) setElementData ( weapon_c, "owner", player ) setElementData ( localPlayer, "gun", weapon_c ) attachElements ( weapon_c, weapon, 1.1, -0.12, 0.152, -6, 3, -2 ) local x,y,z = getElementPosition (weapon2) local weapon_c2 = createWeapon("minigun", x,y,z) setElementCollisionsEnabled( weapon_c2, false ) setWeaponState ( weapon_c2, "ready" ) setElementAlpha ( weapon_c2, 0 ) setWeaponFiringRate ( weapon_c2 , 60 ) setElementParent( weapon_c2, weapon2 ) setWeaponProperty( weapon_c2, "damage", 0) setWeaponProperty ( weapon_c2, "fire_rotation", 0, -27, -5.5 ) setWeaponProperty ( weapon_c2, "weapon_range", 10000 ) setWeaponProperty ( weapon_c2, "target_range", 10000 ) setWeaponClipAmmo( weapon_c2, 250 ) setElementData ( weapon_c2, "owner", player ) setElementData ( localPlayer, "gun2", weapon_c2 ) attachElements ( weapon_c2, weapon2, 1.1, -0.12, 0.152, -6, 3, -2 ) local x,y,z = getElementPosition (weapon3) local weapon_c3 = createWeapon("minigun", x,y,z) setElementCollisionsEnabled( weapon_c3, false ) setWeaponState ( weapon_c3, "ready" ) setElementAlpha ( weapon_c3, 0 ) setWeaponFiringRate ( weapon_c3 , 60 ) setElementParent( weapon_c3, weapon3 ) setWeaponProperty( weapon_c3, "damage", 0) setWeaponProperty ( weapon_c3, "fire_rotation", 0, -27, -5.5 ) setWeaponProperty ( weapon_c3, "weapon_range", 10000 ) setWeaponProperty ( weapon_c3, "target_range", 10000 ) setWeaponClipAmmo( weapon_c3, 250 ) setElementData ( weapon_c3, "owner", player ) setElementData ( localPlayer, "gun2", weapon_c3 ) attachElements ( weapon_c3, weapon3, 1.1, -0.12, 0.152, -6, 3, -2 ) end addEvent("createRealWeapon", true) addEventHandler("createRealWeapon",root, create_client) function enterMG() if inUse == true then setTimer ( exitMG, 100, 1) else if not isPedInVehicle(localPlayer) and inUse == false then local text = getElementData ( localPlayer, "text" ) if isElement(text) then inUse = true setElementAlpha ( localPlayer, 0 ) triggerServerEvent ( "attachPlayerToMG", localPlayer) addEventHandler('onClientRender', root, renderVehCross ) addEventHandler('onClientRender', root, updatePlayerWeapon ) toggleCockpitView() destroyElement(text) local text2 = guiCreateLabel ( 0.470, 0.32, 4, 2, "Press USE [G] to drop", true ) guiSetFont ( text2, "default-bold-small" ) setElementData (localPlayer, "text2", text2) end end end end bindKey ( "g", "down", enterMG) --1 function inUse_server() inUse_s = true end addEvent("inUse_server", true) addEventHandler("inUse_server",getRootElement(), inUse_server) function noUse_server() inUse_s = false end addEvent("noUse_server", true) addEventHandler("noUse_server",getRootElement(), noUse_server) --2 function inUse_server2() inUse_s2 = true end addEvent("inUse_server2", true) addEventHandler("inUse_server2",getRootElement(), inUse_server2) function noUse_server2() inUse_s2 = false end addEvent("noUse_server2", true) addEventHandler("noUse_server2",getRootElement(), noUse_server2) --3 function inUse_server3() inUse_server3 = true end addEvent("inUse_server3", true) addEventHandler("inUse_server3",getRootElement(), inUse_server3) function noUse_server3() noUse_server3 = false end addEvent("noUse_server3", true) addEventHandler("noUse_server3",getRootElement(), noUse_server3) function exitMG() inUse = false isEnabled = false setCameraTarget (localPlayer, localPlayer) removeEventHandler ("onClientPreRender", root, updateCamera) removeEventHandler ("onClientCursorMove", root, freecamMouse) removeEventHandler('onClientRender', root, updatePlayerWeapon ) removeEventHandler('onClientRender', root, renderVehCross ) triggerServerEvent("detachPlayerFromMG", localPlayer) setElementAlpha ( localPlayer, 255 ) local text2 = getElementData ( localPlayer, "text2" ) destroyElement(text2) local text = guiCreateLabel( 0.470, 0.32, 4, 2, "Press USE [G] to use", true) guiSetFont ( text, "default-bold-small" ) setElementData (localPlayer, "text", text) toggleControl ("fire", true) toggleCockpitView() end addEvent("getOutFromMacineGun", true) addEventHandler("getOutFromMacineGun",getRootElement(), exitMG) function onWasted () if inUse == true then inUse = false isEnabled = false setCameraTarget (localPlayer, localPlayer) removeEventHandler ( "onClientPreRender", root, updateCamera ) removeEventHandler ( "onClientCursorMove", root, freecamMouse ) removeEventHandler ( 'onClientRender', root, updatePlayerWeapon ) removeEventHandler ( 'onClientRender', root, renderVehCross ) triggerServerEvent ( "detachPlayerFromMG", localPlayer ) setElementAlpha ( localPlayer, 255 ) toggleControl ("fire", true) toggleCockpitView() local text = getElementData ( localPlayer, "text" ) local text2 = getElementData ( localPlayer, "text2" ) local img = getElementData ( localPlayer, "img" ) destroyElement(text) destroyElement(text2) destroyElement(img) end end addEventHandler ( "onClientPlayerWasted", getLocalPlayer(), onWasted ) function onDemage() if inUse == true then setPedAnimationProgress(localPlayer, "SilenceCrouchfire", 0.7) triggerServerEvent ( "demage_anim", localPlayer) end end addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), onDemage ) function renderVehCross () if inUse == true then dxDrawImage (w/2-34, h/2-38,68,68,"files/crosshair.png",0,0,0) setCameraFieldOfView("player",70) else removeEventHandler('onClientRender', root, renderVehCross ) end end function fireCustomVehWeapon () if inUse == true then local px,py,pz = getElementPosition (localPlayer) local x,y,z = getWorldFromScreenPosition ( w/2, h/2, 50 ) setElementData ( localPlayer, "attachedToWeapon_aim", {x,y,z} ) setElementData ( localPlayer, "attachedToWeapon_fire", true) setTimer ( updateWeaponTargetOnFire, 200, 1 ) triggerServerEvent("fire_server", localPlayer, localPlayer,px,py,pz) end end bindKey ("mouse1", "down", fireCustomVehWeapon) function updateWeaponTargetOnFire () if getKeyState ("mouse1") and inUse == true then local x,y,z = getWorldFromScreenPosition ( w/2, h/2, 75 ) setElementData ( localPlayer, "attachedToWeapon_aim", {x,y,z} ) setTimer ( updateWeaponTargetOnFire, 100, 1 ) else setElementData ( localPlayer, "attachedToWeapon_fire", false) end end function fire_client(player,px,py,pz) local sound_mg = getElementData ( localPlayer, "sound_mg" ) if not isElement(sound_mg) then local gun = getElementData ( localPlayer, "gun" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition (localPlayer) local sound_mg = playSound3D ( "files/mg.wav", px,py,pz, true ) setSoundMaxDistance ( sound_mg, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setElementData ( localPlayer, "sound_mg", sound_mg ) setTimer ( fireCustomWeapInTime, 50, 1, gun, player ) end local sound_mg = getElementData ( localPlayer, "sound_mg" ) if not isElement(sound_mg) then local gun = getElementData ( localPlayer, "gun2" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition ( gun ) local sound_mg = playSound3D ( "files/mg.wav", x,y,z, true ) setSoundMaxDistance ( sound_mg, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setTimer ( fireCustomWeapInTime, 50, 1, gun, player ) setElementData ( localPlayer, "sound_mg", sound_mg ) end end addEvent("fire_client", true) addEventHandler("fire_client",getRootElement(), fire_client) function fireCustomWeapInTime (gun, player) if isElement ( player ) and getElementData ( player, "attachedToWeapon_fire" ) then local aim = getElementData ( player, "attachedToWeapon_aim" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) timer = setTimer ( fireCustomWeapInTime, 100, 1, gun, player ) else local sound_mg = getElementData ( localPlayer, "sound_mg" ) local x,y,z = getElementPosition ( player ) setWeaponState ( gun, "ready" ) stopSound(sound_mg) end end function fire_client2(player,px,py,pz) local sound_mg2 = getElementData ( localPlayer, "sound_mg2" ) if not isElement(sound_mg2) then local gun = getElementData ( localPlayer, "gun2" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition (localPlayer) local sound_mg2 = playSound3D ( "files/mg.wav", px,py,pz, true ) setSoundMaxDistance ( sound_mg2, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setElementData ( localPlayer, "sound_mg2", sound_mg2 ) setTimer ( fireCustomWeapInTime2, 50, 1, gun, player ) end local sound_mg2 = getElementData ( localPlayer, "sound_mg2" ) if not isElement(sound_mg2) then local gun = getElementData ( localPlayer, "gun2" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition ( gun ) local sound_mg2 = playSound3D ( "files/mg.wav", x,y,z, true ) setSoundMaxDistance ( sound_mg2, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setTimer ( fireCustomWeapInTime2, 50, 1, gun, player ) setElementData ( localPlayer, "sound_mg2", sound_mg2 ) end end addEvent("fire_client2", true) addEventHandler("fire_client2",getRootElement(), fire_client2) function fireCustomWeapInTime2 (gun, player) if isElement ( player ) and getElementData ( player, "attachedToWeapon_fire" ) then local aim = getElementData ( player, "attachedToWeapon_aim" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) timer = setTimer ( fireCustomWeapInTime2, 100, 1, gun, player ) else local sound_mg2 = getElementData ( localPlayer, "sound_mg2" ) local x,y,z = getElementPosition ( player ) setWeaponState ( gun, "ready" ) stopSound(sound_mg2) end end function fire_client3(player,px,py,pz) local sound_mg3 = getElementData ( localPlayer, "sound_mg3" ) if not isElement(sound_mg3) then local gun = getElementData ( localPlayer, "gun3" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition (localPlayer) local sound_mg3 = playSound3D ( "files/mg.wav", px,py,pz, true ) setSoundMaxDistance ( sound_mg3, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setElementData ( localPlayer, "sound_mg3", sound_mg3 ) setTimer ( fireCustomWeapInTime3, 50, 1, gun, player ) end local sound_mg3 = getElementData ( localPlayer, "sound_mg3" ) if not isElement(sound_mg3) then local gun = getElementData ( localPlayer, "gun3" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition ( gun ) local sound_mg3 = playSound3D ( "files/mg.wav", x,y,z, true ) setSoundMaxDistance ( sound_mg3, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setTimer ( fireCustomWeapInTime3, 50, 1, gun, player ) setElementData ( localPlayer, "sound_mg3", sound_mg3 ) end end addEvent("fire_client3", true) addEventHandler("fire_client3",getRootElement(), fire_client2) function fireCustomWeapInTime3 (gun, player) if isElement ( player ) and getElementData ( player, "attachedToWeapon_fire" ) then local aim = getElementData ( player, "attachedToWeapon_aim" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) timer = setTimer ( fireCustomWeapInTime3, 100, 1, gun, player ) else local sound_mg3 = getElementData ( localPlayer, "sound_mg3" ) local x,y,z = getElementPosition ( player ) setWeaponState ( gun, "ready" ) stopSound(sound_mg3) end end function stop_client() if inUse == true then local x,y,z = getElementPosition (localPlayer) triggerServerEvent("ready_server", localPlayer, x,y,z) end end bindKey ("mouse1", "up", stop_client) function stop(x,y,z) local sound_lastshoot = playSound3D ( "files/mg_lastshoot.wav", x,y,z ) setSoundMaxDistance ( sound_lastshoot, 500 ) end addEvent("ready_client", true) addEventHandler("ready_client",getRootElement(), stop) function createCol(posX,posY) local col = createColCircle ( posX+1,posY, 0.9 ) addEventHandler ( "onClientColShapeHit", col, onHit ) addEventHandler ( "onClientColShapeLeave", col, onLeave ) end addEvent("createCol", true) addEventHandler("createCol",getRootElement(), createCol) function onHit( theElement ) if inUse_s == false then if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text2 = getElementData ( localPlayer, "text2" ) if not isElement(text2) then local text = guiCreateLabel( 0.470, 0.32, 4, 2, "Press USE [G] to use", true) local img = guiCreateStaticImage(0.57, 0.3, 0.09, 0.06, "files/mg42.png", true) guiSetFont ( text, "default-bold-small" ) setElementData (localPlayer, "text", text) setElementData (localPlayer, "img", img) end end end end function onLeave( theElement ) if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text = getElementData ( localPlayer, "text" ) local img = getElementData ( localPlayer, "img" ) destroyElement(text) destroyElement(img) end end function createCol2(posX,posY) local col2 = createColCircle ( posX+1,posY, 0.9 ) addEventHandler ( "onClientColShapeHit", col2, onHit2 ) addEventHandler ( "onClientColShapeLeave", col2, onLeave2 ) end addEvent("createCol2", true) addEventHandler("createCol2",getRootElement(), createCol2) function onHit2(theElement) if inUse_s2 == false then if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text2 = getElementData ( localPlayer, "text2" ) if not isElement(text2) then local text = guiCreateLabel( 0.470, 0.32, 4, 2, "Press USE [G] to use", true) local img = guiCreateStaticImage(0.57, 0.3, 0.09, 0.06, "files/mg42.png", true) guiSetFont ( text, "default-bold-small" ) setElementData (localPlayer, "text", text) setElementData (localPlayer, "img", img) end end end end function onLeave2(theElement) if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text = getElementData ( localPlayer, "text" ) local img = getElementData ( localPlayer, "img" ) destroyElement(text) destroyElement(img) end end function createCol3(posX,posY) local col3 = createColCircle ( posX+1,posY, 0.9 ) addEventHandler ( "onClientColShapeHit", col3, onHit3 ) addEventHandler ( "onClientColShapeLeave", col3, onLeave3 ) end addEvent("createCol3", true) addEventHandler("createCol3",getRootElement(), createCol3) function onHit3(theElement) if inUse_s3 == false then if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text2 = getElementData ( localPlayer, "text2" ) if not isElement(text2) then local text = guiCreateLabel( 0.470, 0.32, 4, 2, "Press USE [G] to use", true) local img = guiCreateStaticImage(0.57, 0.3, 0.09, 0.06, "files/mg42.png", true) guiSetFont ( text, "default-bold-small" ) setElementData (localPlayer, "text", text) setElementData (localPlayer, "img", img) end end end end function onLeave3(theElement) if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text = getElementData ( localPlayer, "text" ) local img = getElementData ( localPlayer, "img" ) destroyElement(text) destroyElement(img) end end function causeCustomWeaponDamage(hitElement) if hitElement then local owner = getElementData(source,"owner") if getElementType ( hitElement ) == "vehicle" then triggerServerEvent ( "causeVehicleDamageFromMG", localPlayer, hitElement ) end end end addEventHandler("onClientWeaponFire", getRootElement(), causeCustomWeaponDamage) function DamageToPlayersFromCustomWeapons(target) if target == localPlayer then setElementHealth ( target, getElementHealth(target) - 8 ) end end addEventHandler("onClientWeaponFire", root, DamageToPlayersFromCustomWeapons) function getPositionInfrontOfElement(x,y,rotation, meters) posX = x - math.sin(math.rad(rotation)) * meters posY = y + math.cos(math.rad(rotation)) * meters return posX, posY, posZ end function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end; return t; end 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 ) ) rotx = math.deg(rotx) rotz = -math.deg(rotz) return rotx, 180, rotz end function updatePlayerWeapon () if inUse == true then local x, y, z, lx, ly, lz = getCameraMatrix () local rot = findRotation ( x,y,lx,ly ) local rot2_x, rot_y, rot2_z = getCameraRotation() setElementRotation ( localPlayer, 0, 0, rot, "default", true ) triggerServerEvent ("rotatePlayerWeapon",localPlayer,rot,rot2_x) end end local root = getRootElement() local localPlayer = getLocalPlayer() local PI = math.pi local isEnabled = false 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 local forceFadeBack = false function toggleCockpitView() if (not isEnabled) then isEnabled = true addEventHandler ("onClientPreRender", root, updateCamera) addEventHandler ("onClientCursorMove",root, freecamMouse) else --reset view isEnabled = false setCameraTarget (localPlayer, localPlayer) removeEventHandler ("onClientPreRender", root, updateCamera) removeEventHandler ("onClientCursorMove", root, freecamMouse) end end function updateCamera () if (isEnabled) then 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) or forceFadeBack 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 = getPedBonePosition (localPlayer, 6) 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 not inVehicle then 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 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 local normalX = (camNormalizedAngleY * normalAngleZ - camNormalizedAngleZ * normalAngleY) local normalY = (camNormalizedAngleZ * normalAngleX - camNormalizedAngleX * normalAngleZ) local normalZ = (camNormalizedAngleX * normalAngleY - camNormalizedAngleY * normalAngleX) camTargetX = camPosX + freeModeAngleX * 100 camTargetY = camPosY + freeModeAngleY * 100 camTargetZ = camPosZ + freeModeAngleZ * 100 setCameraMatrix (camPosX, camPosY, camPosZ+0.2, camTargetX-140, camTargetY, camTargetZ, roll) end end function freecamMouse (cX,cY,aX,aY) if isCursorShowing() or isMTAWindowActive() then mouseFrameDelay = 5 return elseif mouseFrameDelay > 0 then mouseFrameDelay = mouseFrameDelay - 1 return end startTick = getTickCount() recentlyMoved = true if fadeBack then fadeBack = false executeCounter = 0 end 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 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 function fps() if inUse == true then toggleCockpitView() end end --bindKey ( "mouse3", "down", fps) function aim_in() if inUse == true then removeEventHandler('onClientRender', root, renderVehCross ) addEventHandler('onClientRender', root, renderVehCross2 ) else removeEventHandler('onClientRender', root, renderVehCross ) end end --bindKey ("mouse2", "down", aim_in) function aim_out() if inUse == true then removeEventHandler('onClientRender', root, renderVehCross2 ) addEventHandler('onClientRender', root, renderVehCross ) end end --bindKey ("mouse2", "up", aim_out) function renderVehCross2 () if inUse == true then dxDrawImage (w/2-28, h/2-32,58,58,"files/crosshair.png",0,0,0) setCameraFieldOfView("player",50) end end function replaceskin() txd = engineLoadTXD ( "files/m4.txd" ) engineImportTXD ( txd, 356) dff = engineLoadDFF ( "files/m4.dff", 356) engineReplaceModel ( dff, 356) end addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), replaceskin) addCommandHandler( "on", function () setDevelopmentMode ( true ) end ) server : --CREATING THE MG function mg_pos() createMG(-2861.9, 20.4, 8, 0, -10, 188) createMG2(-2862.1, -65.5, 14.72, 0, -10, 188) createMG3(-2743.2, 89.1, 15.1, 0, -10, 190) end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), mg_pos) --MG 1 function createMG(posX,posY,posZ,rotX,rotY,rotZ) mg = createObject ( 356, 0,0,0) local weapon_base = createObject ( 1897, posX,posY,posZ,rotX,rotY,rotZ) local weapon = createObject ( 356, 0,0,0) attachElements ( weapon, weapon_base, -0.55, 0, 1.75, 0, 0, 0) setElementData ( mg, "weapon_base", weapon_base) setElementData ( mg, "weapon", weapon) setElementAlpha(weapon_base, 0) setTimer ( event, 500, 1 ) setTimer ( col, 500, 1, posX,posY ) end function col(posX,posY) triggerClientEvent("createCol", root, posX,posY) col_s = createColCircle ( posX,posY, 3 ) end function createMG2(posX,posY,posZ,rotX,rotY,rotZ) mg2 = createObject ( 356, 0,0,0) local weapon_base = createObject ( 1897, posX,posY,posZ,rotX,rotY,rotZ) local weapon = createObject ( 356, 0,0,0) attachElements ( weapon, weapon_base, -0.55, 0, 1.75, 0, 0, 0) setElementData ( mg2, "weapon_base", weapon_base) setElementData ( mg2, "weapon", weapon) setElementAlpha(weapon_base, 0) setTimer ( col2, 500, 1, posX,posY ) end function col2(posX,posY) triggerClientEvent("createCol2", root, posX,posY) col_s2 = createColCircle ( posX,posY, 3 ) end function createMG3(posX,posY,posZ,rotX,rotY,rotZ) mg3 = createObject ( 356, 0,0,0) local weapon_base = createObject ( 1897, posX,posY,posZ,rotX,rotY,rotZ) local weapon = createObject ( 356, 0,0,0) attachElements ( weapon, weapon_base, -0.55, 0, 1.75, 0, 0, 0) setElementData ( mg3, "weapon_base", weapon_base) setElementData ( mg3, "weapon", weapon) setElementAlpha(weapon_base, 0) setTimer ( col3, 500, 1, posX,posY ) end function col3(posX,posY) triggerClientEvent("createCol3", root, posX,posY) col_s3 = createColCircle ( posX,posY, 3 ) end function event() local weapon = getElementData ( mg, "weapon" ) local weapon2 = getElementData ( mg2, "weapon" ) local weapon3 = getElementData ( mg3, "weapon" ) triggerClientEvent("createRealWeapon", root, weapon,weapon2,weapon3) end --ENTERING THE MG function attach() local detection = isElementWithinColShape ( source, col_s ) local detection2 = isElementWithinColShape ( source, col_s2 ) local detection3 = isElementWithinColShape ( source, col_s3 ) if detection then local weap = getElementData ( mg, "weapon_base" ) attachElements ( source, weap, -1.2, 0.22, 1.75, 0, 0, 0 ) triggerClientEvent("inUse_server", root) elseif detection2 then local weap = getElementData ( mg2, "weapon_base" ) attachElements ( source, weap, -1.2, 0.22, 1.75, 0, 0, 0 ) triggerClientEvent("inUse_server2", root) elseif detection3 then local weap = getElementData ( mg3, "weapon_base" ) attachElements ( source, weap, -1.2, 0.22, 1.75, 0, 0, 0 ) triggerClientEvent("inUse_server3", root) end setPedAnimation ( source, "SILENCED", "SilenceCrouchfire", 0.7, false, false, false, true ) setPedAnimationProgress(source, "SilenceCrouchfire", 0.7) toggleControl (source,"fire", false) setElementData ( source, "attachedToWeapon_w", weap ) setTimer ( refresh_anim, 1000, 1, source ) end addEvent("attachPlayerToMG", true) addEventHandler("attachPlayerToMG",getRootElement(), attach) function refresh_anim(source) setPedAnimationProgress(source, "SilenceCrouchfire", 0.7) end function detach() local detection = isElementWithinColShape ( source, col_s ) local detection2 = isElementWithinColShape ( source, col_s2 ) local detection3 = isElementWithinColShape ( source, col_s3 ) if detection then triggerClientEvent("noUse_server", root) elseif detection2 then triggerClientEvent("noUse_server2", root) elseif detection3 then triggerClientEvent("noUse_server3", root) end local attachTo = getElementData(source,"attachedToWeapon_w") setPedAnimation ( source, "ped","SEAT_UP", false ) setTimer(setPedAnimation, 1300,1,source,false) detachElements(source,attachTo) setElementCollisionsEnabled ( source, true ) toggleControl (source,"fire", true) setElementData ( source, "attachedToWeapon_w", nil ) setElementData ( source,"attachedToWeapon",false) end addEvent("detachPlayerFromMG", true) addEventHandler("detachPlayerFromMG",getRootElement(),detach) function dmg_anim() setPedAnimationProgress(source, "SilenceCrouchfire", 0.7) end addEvent("demage_anim", true) addEventHandler("demage_anim",getRootElement(),dmg_anim) function rotate(rot,rot2_x) local detection = isElementWithinColShape ( source, col_s ) local detection2 = isElementWithinColShape ( source, col_s2 ) local detection3 = isElementWithinColShape ( source, col_s3 ) if detection then local weap = getElementData ( mg, "weapon_base" ) local weap2 = getElementData ( mg, "weapon" ) local x,y,z = getElementRotation (weap) setElementRotation ( weap, 0,0,rot+97) if rot < 40 then --outputChatBox ( "< 40" ) --triggerClientEvent("right", root) end if rot > 140 then --outputChatBox ( "> 180" ) --triggerClientEvent("left", root) end local x,y,z,rx,ry,rz = getElementAttachedOffsets (weap2) if -rot2_x < 8 then setElementAttachedOffsets ( weap2, x, y, z, rx, -rot2_x+10, rz) end elseif detection2 then local weap = getElementData ( mg2, "weapon_base" ) local weap2 = getElementData ( mg2, "weapon" ) local x,y,z = getElementRotation (weap) setElementRotation ( weap, 0,0,rot+97) if rot < 40 then --outputChatBox ( "< 40" ) --triggerClientEvent("right", root) end if rot > 140 then --outputChatBox ( "> 180" ) --triggerClientEvent("left", root) end local x,y,z,rx,ry,rz = getElementAttachedOffsets (weap2) if -rot2_x < 8 then setElementAttachedOffsets ( weap2, x, y, z, rx, -rot2_x+10, rz) end elseif detection3 then local weap = getElementData ( mg3, "weapon_base" ) local weap2 = getElementData ( mg3, "weapon" ) local x,y,z = getElementRotation (weap) setElementRotation ( weap, 0,0,rot+97) if rot < 40 then --outputChatBox ( "< 40" ) --triggerClientEvent("right", root) end if rot > 140 then --outputChatBox ( "> 180" ) --triggerClientEvent("left", root) end local x,y,z,rx,ry,rz = getElementAttachedOffsets (weap2) if -rot2_x < 8 then setElementAttachedOffsets ( weap2, x, y, z, rx, -rot2_x+10, rz) end end end addEvent("rotatePlayerWeapon", true) addEventHandler("rotatePlayerWeapon",getRootElement(), rotate) function fire_server(player,px,py,pz) local detection = isElementWithinColShape ( source, col_s ) local detection2 = isElementWithinColShape ( source, col_s2 ) local detection3 = isElementWithinColShape ( source, col_s3 ) if detection then triggerClientEvent("fire_client", getRootElement(), player,px,py,pz) elseif detection2 then triggerClientEvent("fire_client2", getRootElement(), player,px,py,pz) elseif detection3 then triggerClientEvent("fire_client3", getRootElement(), player,px,py,pz) end end addEvent("fire_server", true) addEventHandler("fire_server",getRootElement(), fire_server) function ready_server(player,x,y,z) triggerClientEvent("ready_client", getRootElement(), player,x,y,z) end addEvent("ready_server", true) addEventHandler("ready_server",getRootElement(), ready_server) function vehicle_demage(veh) local vehicleHP = getElementHealth(veh) if vehicleHP > 0 then setElementHealth(veh,vehicleHP-10) elseif not ( isVehicleBlown ( veh ) ) then blowVehicle ( veh ) end end addEvent("causeVehicleDamageFromMG", true) addEventHandler("causeVehicleDamageFromMG", getRootElement(), vehicle_demage) ارجو المساعدة اخواني ويلي مافهم طلبي الموضوع بسيط بدي اسوي AttachElement للرشاش وسيارة شكرا
  2. مافي اي مساعدة شباب !؟
  3. السلام عليكم ورحمة الله وباركته اخواني عندي مشكلة في سكربت جديد قاعد ابرمج فيه والسكربت عبارة عن عداد تاكسي يحسب بالامتار المشكلة اني اريد ليبل او Label يتغير وهو ليبل السعر حيث لما يوصل عداد الامتار ل 1000 متر يتغير السعر ويصير 1 دينار يعني اليبل يتغير والمشكلة التانية اني ماعرفت اسويله لووب بحيث لما يركب التاكسي بس يطلع الGUI او الواجهة الرسومية الكود : GUIEditor = { button = {}, window = {}, label = {}, memo = {} } function setUp(startedResource) if(startedResource == getThisResource()) then oX,oY,oZ = getElementPosition(getLocalPlayer()) distanceTraveled = 0 GUIEditor.window[1] = guiCreateWindow(1034, 558, 322, 166, "عداد المركبة الناقلة", false) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.memo[1] = guiCreateMemo(10, 25, 302, 50, "مرحبا بكم على متن هذه المركبة المتنقلة هذه المركبة \nمجهزة بعداد للمسافة وللسعر فكل الف متر نصف دينار", false, GUIEditor.window[1]) GUIEditor.label[1] = guiCreateLabel(204, 81, 108, 20, "المسافة المقطوعة :", false, GUIEditor.window[1]) guiSetFont(GUIEditor.label[1], "default-bold-small") GUIEditor.label[2] = guiCreateLabel(204, 101, 98, 20, "سعر الرحلة :", false, GUIEditor.window[1]) guiSetFont(GUIEditor.label[2], "default-bold-small") GUIEditor.button[1] = guiCreateButton(10, 122, 86, 34, "إدفع", false, GUIEditor.window[1]) meterlable = guiCreateLabel(134, 81, 108, 20, "999999 متر", false, GUIEditor.window[1]) guiSetFont(meterlable, "default-bold-small") GUIEditor.label[4] = guiCreateLabel(129, 101, 108, 20, "999999 دينار", false, GUIEditor.window[1]) guiSetFont(GUIEditor.label[4], "default-bold-small") end end addEventHandler("onClientResourceStart",getRootElement(),setUp) function monitoring() if(isPlayerInVehicle(getLocalPlayer())) then x,y,z = getElementPosition(getLocalPlayer()) distanceTraveled = distanceTraveled + getDistanceBetweenPoints3D(x,y,z,oX,oY,oZ) guiSetText(meterlable," " .. math.floor(distanceTraveled) .. " متر") oX = x oY = y oZ = z end end addEventHandler("onClientRender",getRootElement(),monitoring) ارجو المساعدة وشكرااا
  4. hello my last topic was closed beacuse topic bumping so i decided to create anthor one because i really need help ihave a problem on Xwad mg Machine Gun script the problem is i can't mount the machine gun on a vehicle the code client side : inUse = false inUse_s = false inUse_s2 = false inUse_s3 = false w, h = guiGetScreenSize () function create_client(weapon,weapon2,weapon3) local x,y,z = getElementPosition (weapon) local weapon_c = createWeapon("minigun", x,y,z) setElementCollisionsEnabled( weapon_c, false ) setWeaponState ( weapon_c, "ready" ) setElementAlpha ( weapon_c, 255 ) setWeaponFiringRate ( weapon_c , 60 ) setElementParent( weapon_c, weapon ) setWeaponProperty( weapon_c, "damage", 0) setWeaponProperty ( weapon_c, "fire_rotation", 0, -27, -5.5 ) setWeaponProperty ( weapon_c, "weapon_range", 10000 ) setWeaponProperty ( weapon_c, "target_range", 10000 ) setWeaponClipAmmo( weapon_c, 250 ) setElementData ( weapon_c, "owner", player ) setElementData ( localPlayer, "gun", weapon_c ) attachElements ( weapon_c, weapon, 1.1, -0.12, 0.152, -6, 3, -2 ) local x,y,z = getElementPosition (weapon2) local weapon_c2 = createWeapon("minigun", x,y,z) setElementCollisionsEnabled( weapon_c2, false ) setWeaponState ( weapon_c2, "ready" ) setElementAlpha ( weapon_c2, 0 ) setWeaponFiringRate ( weapon_c2 , 60 ) setElementParent( weapon_c2, weapon2 ) setWeaponProperty( weapon_c2, "damage", 0) setWeaponProperty ( weapon_c2, "fire_rotation", 0, -27, -5.5 ) setWeaponProperty ( weapon_c2, "weapon_range", 10000 ) setWeaponProperty ( weapon_c2, "target_range", 10000 ) setWeaponClipAmmo( weapon_c2, 250 ) setElementData ( weapon_c2, "owner", player ) setElementData ( localPlayer, "gun2", weapon_c2 ) attachElements ( weapon_c2, weapon2, 1.1, -0.12, 0.152, -6, 3, -2 ) local x,y,z = getElementPosition (weapon3) local weapon_c3 = createWeapon("minigun", x,y,z) setElementCollisionsEnabled( weapon_c3, false ) setWeaponState ( weapon_c3, "ready" ) setElementAlpha ( weapon_c3, 0 ) setWeaponFiringRate ( weapon_c3 , 60 ) setElementParent( weapon_c3, weapon3 ) setWeaponProperty( weapon_c3, "damage", 0) setWeaponProperty ( weapon_c3, "fire_rotation", 0, -27, -5.5 ) setWeaponProperty ( weapon_c3, "weapon_range", 10000 ) setWeaponProperty ( weapon_c3, "target_range", 10000 ) setWeaponClipAmmo( weapon_c3, 250 ) setElementData ( weapon_c3, "owner", player ) setElementData ( localPlayer, "gun2", weapon_c3 ) attachElements ( weapon_c3, weapon3, 1.1, -0.12, 0.152, -6, 3, -2 ) end addEvent("createRealWeapon", true) addEventHandler("createRealWeapon",root, create_client) function enterMG() if inUse == true then setTimer ( exitMG, 100, 1) else if not isPedInVehicle(localPlayer) and inUse == false then local text = getElementData ( localPlayer, "text" ) if isElement(text) then inUse = true setElementAlpha ( localPlayer, 0 ) triggerServerEvent ( "attachPlayerToMG", localPlayer) addEventHandler('onClientRender', root, renderVehCross ) addEventHandler('onClientRender', root, updatePlayerWeapon ) toggleCockpitView() destroyElement(text) local text2 = guiCreateLabel ( 0.470, 0.32, 4, 2, "Press USE [G] to drop", true ) guiSetFont ( text2, "default-bold-small" ) setElementData (localPlayer, "text2", text2) end end end end bindKey ( "g", "down", enterMG) --1 function inUse_server() inUse_s = true end addEvent("inUse_server", true) addEventHandler("inUse_server",getRootElement(), inUse_server) function noUse_server() inUse_s = false end addEvent("noUse_server", true) addEventHandler("noUse_server",getRootElement(), noUse_server) --2 function inUse_server2() inUse_s2 = true end addEvent("inUse_server2", true) addEventHandler("inUse_server2",getRootElement(), inUse_server2) function noUse_server2() inUse_s2 = false end addEvent("noUse_server2", true) addEventHandler("noUse_server2",getRootElement(), noUse_server2) --3 function inUse_server3() inUse_server3 = true end addEvent("inUse_server3", true) addEventHandler("inUse_server3",getRootElement(), inUse_server3) function noUse_server3() noUse_server3 = false end addEvent("noUse_server3", true) addEventHandler("noUse_server3",getRootElement(), noUse_server3) function exitMG() inUse = false isEnabled = false setCameraTarget (localPlayer, localPlayer) removeEventHandler ("onClientPreRender", root, updateCamera) removeEventHandler ("onClientCursorMove", root, freecamMouse) removeEventHandler('onClientRender', root, updatePlayerWeapon ) removeEventHandler('onClientRender', root, renderVehCross ) triggerServerEvent("detachPlayerFromMG", localPlayer) setElementAlpha ( localPlayer, 255 ) local text2 = getElementData ( localPlayer, "text2" ) destroyElement(text2) local text = guiCreateLabel( 0.470, 0.32, 4, 2, "Press USE [G] to use", true) guiSetFont ( text, "default-bold-small" ) setElementData (localPlayer, "text", text) toggleControl ("fire", true) toggleCockpitView() end addEvent("getOutFromMacineGun", true) addEventHandler("getOutFromMacineGun",getRootElement(), exitMG) function onWasted () if inUse == true then inUse = false isEnabled = false setCameraTarget (localPlayer, localPlayer) removeEventHandler ( "onClientPreRender", root, updateCamera ) removeEventHandler ( "onClientCursorMove", root, freecamMouse ) removeEventHandler ( 'onClientRender', root, updatePlayerWeapon ) removeEventHandler ( 'onClientRender', root, renderVehCross ) triggerServerEvent ( "detachPlayerFromMG", localPlayer ) setElementAlpha ( localPlayer, 255 ) toggleControl ("fire", true) toggleCockpitView() local text = getElementData ( localPlayer, "text" ) local text2 = getElementData ( localPlayer, "text2" ) local img = getElementData ( localPlayer, "img" ) destroyElement(text) destroyElement(text2) destroyElement(img) end end addEventHandler ( "onClientPlayerWasted", getLocalPlayer(), onWasted ) function onDemage() if inUse == true then setPedAnimationProgress(localPlayer, "SilenceCrouchfire", 0.7) triggerServerEvent ( "demage_anim", localPlayer) end end addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), onDemage ) function renderVehCross () if inUse == true then dxDrawImage (w/2-34, h/2-38,68,68,"files/crosshair.png",0,0,0) setCameraFieldOfView("player",70) else removeEventHandler('onClientRender', root, renderVehCross ) end end function fireCustomVehWeapon () if inUse == true then local px,py,pz = getElementPosition (localPlayer) local x,y,z = getWorldFromScreenPosition ( w/2, h/2, 50 ) setElementData ( localPlayer, "attachedToWeapon_aim", {x,y,z} ) setElementData ( localPlayer, "attachedToWeapon_fire", true) setTimer ( updateWeaponTargetOnFire, 200, 1 ) triggerServerEvent("fire_server", localPlayer, localPlayer,px,py,pz) end end bindKey ("mouse1", "down", fireCustomVehWeapon) function updateWeaponTargetOnFire () if getKeyState ("mouse1") and inUse == true then local x,y,z = getWorldFromScreenPosition ( w/2, h/2, 75 ) setElementData ( localPlayer, "attachedToWeapon_aim", {x,y,z} ) setTimer ( updateWeaponTargetOnFire, 100, 1 ) else setElementData ( localPlayer, "attachedToWeapon_fire", false) end end function fire_client(player,px,py,pz) local sound_mg = getElementData ( localPlayer, "sound_mg" ) if not isElement(sound_mg) then local gun = getElementData ( localPlayer, "gun" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition (localPlayer) local sound_mg = playSound3D ( "files/mg.wav", px,py,pz, true ) setSoundMaxDistance ( sound_mg, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setElementData ( localPlayer, "sound_mg", sound_mg ) setTimer ( fireCustomWeapInTime, 50, 1, gun, player ) end local sound_mg = getElementData ( localPlayer, "sound_mg" ) if not isElement(sound_mg) then local gun = getElementData ( localPlayer, "gun2" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition ( gun ) local sound_mg = playSound3D ( "files/mg.wav", x,y,z, true ) setSoundMaxDistance ( sound_mg, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setTimer ( fireCustomWeapInTime, 50, 1, gun, player ) setElementData ( localPlayer, "sound_mg", sound_mg ) end end addEvent("fire_client", true) addEventHandler("fire_client",getRootElement(), fire_client) function fireCustomWeapInTime (gun, player) if isElement ( player ) and getElementData ( player, "attachedToWeapon_fire" ) then local aim = getElementData ( player, "attachedToWeapon_aim" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) timer = setTimer ( fireCustomWeapInTime, 100, 1, gun, player ) else local sound_mg = getElementData ( localPlayer, "sound_mg" ) local x,y,z = getElementPosition ( player ) setWeaponState ( gun, "ready" ) stopSound(sound_mg) end end function fire_client2(player,px,py,pz) local sound_mg2 = getElementData ( localPlayer, "sound_mg2" ) if not isElement(sound_mg2) then local gun = getElementData ( localPlayer, "gun2" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition (localPlayer) local sound_mg2 = playSound3D ( "files/mg.wav", px,py,pz, true ) setSoundMaxDistance ( sound_mg2, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setElementData ( localPlayer, "sound_mg2", sound_mg2 ) setTimer ( fireCustomWeapInTime2, 50, 1, gun, player ) end local sound_mg2 = getElementData ( localPlayer, "sound_mg2" ) if not isElement(sound_mg2) then local gun = getElementData ( localPlayer, "gun2" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition ( gun ) local sound_mg2 = playSound3D ( "files/mg.wav", x,y,z, true ) setSoundMaxDistance ( sound_mg2, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setTimer ( fireCustomWeapInTime2, 50, 1, gun, player ) setElementData ( localPlayer, "sound_mg2", sound_mg2 ) end end addEvent("fire_client2", true) addEventHandler("fire_client2",getRootElement(), fire_client2) function fireCustomWeapInTime2 (gun, player) if isElement ( player ) and getElementData ( player, "attachedToWeapon_fire" ) then local aim = getElementData ( player, "attachedToWeapon_aim" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) timer = setTimer ( fireCustomWeapInTime2, 100, 1, gun, player ) else local sound_mg2 = getElementData ( localPlayer, "sound_mg2" ) local x,y,z = getElementPosition ( player ) setWeaponState ( gun, "ready" ) stopSound(sound_mg2) end end function fire_client3(player,px,py,pz) local sound_mg3 = getElementData ( localPlayer, "sound_mg3" ) if not isElement(sound_mg3) then local gun = getElementData ( localPlayer, "gun3" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition (localPlayer) local sound_mg3 = playSound3D ( "files/mg.wav", px,py,pz, true ) setSoundMaxDistance ( sound_mg3, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setElementData ( localPlayer, "sound_mg3", sound_mg3 ) setTimer ( fireCustomWeapInTime3, 50, 1, gun, player ) end local sound_mg3 = getElementData ( localPlayer, "sound_mg3" ) if not isElement(sound_mg3) then local gun = getElementData ( localPlayer, "gun3" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition ( gun ) local sound_mg3 = playSound3D ( "files/mg.wav", x,y,z, true ) setSoundMaxDistance ( sound_mg3, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setTimer ( fireCustomWeapInTime3, 50, 1, gun, player ) setElementData ( localPlayer, "sound_mg3", sound_mg3 ) end end addEvent("fire_client3", true) addEventHandler("fire_client3",getRootElement(), fire_client2) function fireCustomWeapInTime3 (gun, player) if isElement ( player ) and getElementData ( player, "attachedToWeapon_fire" ) then local aim = getElementData ( player, "attachedToWeapon_aim" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) timer = setTimer ( fireCustomWeapInTime3, 100, 1, gun, player ) else local sound_mg3 = getElementData ( localPlayer, "sound_mg3" ) local x,y,z = getElementPosition ( player ) setWeaponState ( gun, "ready" ) stopSound(sound_mg3) end end function stop_client() if inUse == true then local x,y,z = getElementPosition (localPlayer) triggerServerEvent("ready_server", localPlayer, x,y,z) end end bindKey ("mouse1", "up", stop_client) function stop(x,y,z) local sound_lastshoot = playSound3D ( "files/mg_lastshoot.wav", x,y,z ) setSoundMaxDistance ( sound_lastshoot, 500 ) end addEvent("ready_client", true) addEventHandler("ready_client",getRootElement(), stop) function createCol(posX,posY) local col = createColCircle ( posX+1,posY, 0.9 ) addEventHandler ( "onClientColShapeHit", col, onHit ) addEventHandler ( "onClientColShapeLeave", col, onLeave ) end addEvent("createCol", true) addEventHandler("createCol",getRootElement(), createCol) function onHit( theElement ) if inUse_s == false then if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text2 = getElementData ( localPlayer, "text2" ) if not isElement(text2) then local text = guiCreateLabel( 0.470, 0.32, 4, 2, "Press USE [G] to use", true) local img = guiCreateStaticImage(0.57, 0.3, 0.09, 0.06, "files/mg42.png", true) guiSetFont ( text, "default-bold-small" ) setElementData (localPlayer, "text", text) setElementData (localPlayer, "img", img) end end end end function onLeave( theElement ) if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text = getElementData ( localPlayer, "text" ) local img = getElementData ( localPlayer, "img" ) destroyElement(text) destroyElement(img) end end function createCol2(posX,posY) local col2 = createColCircle ( posX+1,posY, 0.9 ) addEventHandler ( "onClientColShapeHit", col2, onHit2 ) addEventHandler ( "onClientColShapeLeave", col2, onLeave2 ) end addEvent("createCol2", true) addEventHandler("createCol2",getRootElement(), createCol2) function onHit2(theElement) if inUse_s2 == false then if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text2 = getElementData ( localPlayer, "text2" ) if not isElement(text2) then local text = guiCreateLabel( 0.470, 0.32, 4, 2, "Press USE [G] to use", true) local img = guiCreateStaticImage(0.57, 0.3, 0.09, 0.06, "files/mg42.png", true) guiSetFont ( text, "default-bold-small" ) setElementData (localPlayer, "text", text) setElementData (localPlayer, "img", img) end end end end function onLeave2(theElement) if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text = getElementData ( localPlayer, "text" ) local img = getElementData ( localPlayer, "img" ) destroyElement(text) destroyElement(img) end end function createCol3(posX,posY) local col3 = createColCircle ( posX+1,posY, 0.9 ) addEventHandler ( "onClientColShapeHit", col3, onHit3 ) addEventHandler ( "onClientColShapeLeave", col3, onLeave3 ) end addEvent("createCol3", true) addEventHandler("createCol3",getRootElement(), createCol3) function onHit3(theElement) if inUse_s3 == false then if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text2 = getElementData ( localPlayer, "text2" ) if not isElement(text2) then local text = guiCreateLabel( 0.470, 0.32, 4, 2, "Press USE [G] to use", true) local img = guiCreateStaticImage(0.57, 0.3, 0.09, 0.06, "files/mg42.png", true) guiSetFont ( text, "default-bold-small" ) setElementData (localPlayer, "text", text) setElementData (localPlayer, "img", img) end end end end function onLeave3(theElement) if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text = getElementData ( localPlayer, "text" ) local img = getElementData ( localPlayer, "img" ) destroyElement(text) destroyElement(img) end end function causeCustomWeaponDamage(hitElement) if hitElement then local owner = getElementData(source,"owner") if getElementType ( hitElement ) == "vehicle" then triggerServerEvent ( "causeVehicleDamageFromMG", localPlayer, hitElement ) end end end addEventHandler("onClientWeaponFire", getRootElement(), causeCustomWeaponDamage) function DamageToPlayersFromCustomWeapons(target) if target == localPlayer then setElementHealth ( target, getElementHealth(target) - 8 ) end end addEventHandler("onClientWeaponFire", root, DamageToPlayersFromCustomWeapons) function getPositionInfrontOfElement(x,y,rotation, meters) posX = x - math.sin(math.rad(rotation)) * meters posY = y + math.cos(math.rad(rotation)) * meters return posX, posY, posZ end function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end; return t; end 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 ) ) rotx = math.deg(rotx) rotz = -math.deg(rotz) return rotx, 180, rotz end function updatePlayerWeapon () if inUse == true then local x, y, z, lx, ly, lz = getCameraMatrix () local rot = findRotation ( x,y,lx,ly ) local rot2_x, rot_y, rot2_z = getCameraRotation() setElementRotation ( localPlayer, 0, 0, rot, "default", true ) triggerServerEvent ("rotatePlayerWeapon",localPlayer,rot,rot2_x) end end local root = getRootElement() local localPlayer = getLocalPlayer() local PI = math.pi local isEnabled = false 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 local forceFadeBack = false function toggleCockpitView() if (not isEnabled) then isEnabled = true addEventHandler ("onClientPreRender", root, updateCamera) addEventHandler ("onClientCursorMove",root, freecamMouse) else --reset view isEnabled = false setCameraTarget (localPlayer, localPlayer) removeEventHandler ("onClientPreRender", root, updateCamera) removeEventHandler ("onClientCursorMove", root, freecamMouse) end end function updateCamera () if (isEnabled) then 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) or forceFadeBack 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 = getPedBonePosition (localPlayer, 6) 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 not inVehicle then 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 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 local normalX = (camNormalizedAngleY * normalAngleZ - camNormalizedAngleZ * normalAngleY) local normalY = (camNormalizedAngleZ * normalAngleX - camNormalizedAngleX * normalAngleZ) local normalZ = (camNormalizedAngleX * normalAngleY - camNormalizedAngleY * normalAngleX) camTargetX = camPosX + freeModeAngleX * 100 camTargetY = camPosY + freeModeAngleY * 100 camTargetZ = camPosZ + freeModeAngleZ * 100 setCameraMatrix (camPosX, camPosY, camPosZ+0.2, camTargetX-140, camTargetY, camTargetZ, roll) end end function freecamMouse (cX,cY,aX,aY) if isCursorShowing() or isMTAWindowActive() then mouseFrameDelay = 5 return elseif mouseFrameDelay > 0 then mouseFrameDelay = mouseFrameDelay - 1 return end startTick = getTickCount() recentlyMoved = true if fadeBack then fadeBack = false executeCounter = 0 end 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 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 function fps() if inUse == true then toggleCockpitView() end end --bindKey ( "mouse3", "down", fps) function aim_in() if inUse == true then removeEventHandler('onClientRender', root, renderVehCross ) addEventHandler('onClientRender', root, renderVehCross2 ) else removeEventHandler('onClientRender', root, renderVehCross ) end end --bindKey ("mouse2", "down", aim_in) function aim_out() if inUse == true then removeEventHandler('onClientRender', root, renderVehCross2 ) addEventHandler('onClientRender', root, renderVehCross ) end end --bindKey ("mouse2", "up", aim_out) function renderVehCross2 () if inUse == true then dxDrawImage (w/2-28, h/2-32,58,58,"files/crosshair.png",0,0,0) setCameraFieldOfView("player",50) end end function replaceskin() txd = engineLoadTXD ( "files/m4.txd" ) engineImportTXD ( txd, 356) dff = engineLoadDFF ( "files/m4.dff", 356) engineReplaceModel ( dff, 356) end addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), replaceskin) addCommandHandler( "on", function () setDevelopmentMode ( true ) end ) server side : tion = isElementWithinColShape ( source, col_s ) local detection2 = isElementWithinColShape ( source, col_s2 ) local detection3 = isElementWithinColShape ( source, col_s3 ) if detection then local weap = getElementData ( mg, "weapon_base" ) local weap2 = getElementData ( mg, "weapon" ) local x,y,z = getElementRotation (weap) setElementRotation ( weap, 0,0,rot+97) if rot < 40 then --outputChatBox ( "< 40" ) --triggerClientEvent("right", root) end if rot > 140 then --outputChatBox ( "> 180" ) --triggerClientEvent("left", root) end local x,y,z,rx,ry,rz = getElementAttachedOffsets (weap2) if -rot2_x < 8 then setElementAttachedOffsets ( weap2, x, y, z, rx, -rot2_x+10, rz) end elseif detection2 then local weap = getElementData ( mg2, "weapon_base" ) local weap2 = getElementData ( mg2, "weapon" ) local x,y,z = getElementRotation (weap) setElementRotation ( weap, 0,0,rot+97) if rot < 40 then --outputChatBox ( "< 40" ) --triggerClientEvent("right", root) end if rot > 140 then --outputChatBox ( "> 180" ) --triggerClientEvent("left", root) end local x,y,z,rx,ry,rz = getElementAttachedOffsets (weap2) if -rot2_x < 8 then setElementAttachedOffsets ( weap2, x, y, z, rx, -rot2_x+10, rz) end elseif detection3 then local weap = getElementData ( mg3, "weapon_base" ) local weap2 = getElementData ( mg3, "weapon" ) local x,y,z = getElementRotation (weap) setElementRotation ( weap, 0,0,rot+97) if rot < 40 then --outputChatBox ( "< 40" ) --triggerClientEvent("right", root) end if rot > 140 then --outputChatBox ( "> 180" ) --triggerClientEvent("left", root) end local x,y,z,rx,ry,rz = getElementAttachedOffsets (weap2) if -rot2_x < 8 then setElementAttachedOffsets ( weap2, x, y, z, rx, -rot2_x+10, rz) end end end addEvent("rotatePlayerWeapon", true) addEventHandler("rotatePlayerWeapon",getRootElement(), rotate) function fire_server(player,px,py,pz) local detection = isElementWithinColShape ( source, col_s ) local detection2 = isElementWithinColShape ( source, col_s2 ) local detection3 = isElementWithinColShape ( source, col_s3 ) if detection then triggerClientEvent("fire_client", getRootElement(), player,px,py,pz) elseif detection2 then triggerClientEvent("fire_client2", getRootElement(), player,px,py,pz) elseif detection3 then triggerClientEvent("fire_client3", getRootElement(), player,px,py,pz) end end addEvent("fire_server", true) addEventHandler("fire_server",getRootElement(), fire_server) function ready_server(player,x,y,z) triggerClientEvent("ready_client", getRootElement(), player,x,y,z) end addEvent("ready_server", true) addEventHandler("ready_server",getRootElement(), ready_server) the script is createing a 2 or 3 machine gun's but i can't found the functoin of createing it to manipulte and mounted on a vehicle i want the machine gun to mount in the back of bobcat i think the code is flexible and my problem is esay to solve for those how has a exp in Lua thank alot
  5. no help for now !?
  6. Hello Guys this is me agin this time i have on Xwad MG Machine Gun Problem the problem is i can't mount the machine gun on a vehicle the code client side : inUse = false inUse_s = false inUse_s2 = false inUse_s3 = false w, h = guiGetScreenSize () function create_client(weapon,weapon2,weapon3) local x,y,z = getElementPosition (weapon) local weapon_c = createWeapon("minigun", x,y,z) setElementCollisionsEnabled( weapon_c, false ) setWeaponState ( weapon_c, "ready" ) setElementAlpha ( weapon_c, 255 ) setWeaponFiringRate ( weapon_c , 60 ) setElementParent( weapon_c, weapon ) setWeaponProperty( weapon_c, "damage", 0) setWeaponProperty ( weapon_c, "fire_rotation", 0, -27, -5.5 ) setWeaponProperty ( weapon_c, "weapon_range", 10000 ) setWeaponProperty ( weapon_c, "target_range", 10000 ) setWeaponClipAmmo( weapon_c, 250 ) setElementData ( weapon_c, "owner", player ) setElementData ( localPlayer, "gun", weapon_c ) attachElements ( weapon_c, weapon, 1.1, -0.12, 0.152, -6, 3, -2 ) local x,y,z = getElementPosition (weapon2) local weapon_c2 = createWeapon("minigun", x,y,z) setElementCollisionsEnabled( weapon_c2, false ) setWeaponState ( weapon_c2, "ready" ) setElementAlpha ( weapon_c2, 0 ) setWeaponFiringRate ( weapon_c2 , 60 ) setElementParent( weapon_c2, weapon2 ) setWeaponProperty( weapon_c2, "damage", 0) setWeaponProperty ( weapon_c2, "fire_rotation", 0, -27, -5.5 ) setWeaponProperty ( weapon_c2, "weapon_range", 10000 ) setWeaponProperty ( weapon_c2, "target_range", 10000 ) setWeaponClipAmmo( weapon_c2, 250 ) setElementData ( weapon_c2, "owner", player ) setElementData ( localPlayer, "gun2", weapon_c2 ) attachElements ( weapon_c2, weapon2, 1.1, -0.12, 0.152, -6, 3, -2 ) local x,y,z = getElementPosition (weapon3) local weapon_c3 = createWeapon("minigun", x,y,z) setElementCollisionsEnabled( weapon_c3, false ) setWeaponState ( weapon_c3, "ready" ) setElementAlpha ( weapon_c3, 0 ) setWeaponFiringRate ( weapon_c3 , 60 ) setElementParent( weapon_c3, weapon3 ) setWeaponProperty( weapon_c3, "damage", 0) setWeaponProperty ( weapon_c3, "fire_rotation", 0, -27, -5.5 ) setWeaponProperty ( weapon_c3, "weapon_range", 10000 ) setWeaponProperty ( weapon_c3, "target_range", 10000 ) setWeaponClipAmmo( weapon_c3, 250 ) setElementData ( weapon_c3, "owner", player ) setElementData ( localPlayer, "gun2", weapon_c3 ) attachElements ( weapon_c3, weapon3, 1.1, -0.12, 0.152, -6, 3, -2 ) end addEvent("createRealWeapon", true) addEventHandler("createRealWeapon",root, create_client) function enterMG() if inUse == true then setTimer ( exitMG, 100, 1) else if not isPedInVehicle(localPlayer) and inUse == false then local text = getElementData ( localPlayer, "text" ) if isElement(text) then inUse = true setElementAlpha ( localPlayer, 0 ) triggerServerEvent ( "attachPlayerToMG", localPlayer) addEventHandler('onClientRender', root, renderVehCross ) addEventHandler('onClientRender', root, updatePlayerWeapon ) toggleCockpitView() destroyElement(text) local text2 = guiCreateLabel ( 0.470, 0.32, 4, 2, "Press USE [G] to drop", true ) guiSetFont ( text2, "default-bold-small" ) setElementData (localPlayer, "text2", text2) end end end end bindKey ( "g", "down", enterMG) --1 function inUse_server() inUse_s = true end addEvent("inUse_server", true) addEventHandler("inUse_server",getRootElement(), inUse_server) function noUse_server() inUse_s = false end addEvent("noUse_server", true) addEventHandler("noUse_server",getRootElement(), noUse_server) --2 function inUse_server2() inUse_s2 = true end addEvent("inUse_server2", true) addEventHandler("inUse_server2",getRootElement(), inUse_server2) function noUse_server2() inUse_s2 = false end addEvent("noUse_server2", true) addEventHandler("noUse_server2",getRootElement(), noUse_server2) --3 function inUse_server3() inUse_server3 = true end addEvent("inUse_server3", true) addEventHandler("inUse_server3",getRootElement(), inUse_server3) function noUse_server3() noUse_server3 = false end addEvent("noUse_server3", true) addEventHandler("noUse_server3",getRootElement(), noUse_server3) function exitMG() inUse = false isEnabled = false setCameraTarget (localPlayer, localPlayer) removeEventHandler ("onClientPreRender", root, updateCamera) removeEventHandler ("onClientCursorMove", root, freecamMouse) removeEventHandler('onClientRender', root, updatePlayerWeapon ) removeEventHandler('onClientRender', root, renderVehCross ) triggerServerEvent("detachPlayerFromMG", localPlayer) setElementAlpha ( localPlayer, 255 ) local text2 = getElementData ( localPlayer, "text2" ) destroyElement(text2) local text = guiCreateLabel( 0.470, 0.32, 4, 2, "Press USE [G] to use", true) guiSetFont ( text, "default-bold-small" ) setElementData (localPlayer, "text", text) toggleControl ("fire", true) toggleCockpitView() end addEvent("getOutFromMacineGun", true) addEventHandler("getOutFromMacineGun",getRootElement(), exitMG) function onWasted () if inUse == true then inUse = false isEnabled = false setCameraTarget (localPlayer, localPlayer) removeEventHandler ( "onClientPreRender", root, updateCamera ) removeEventHandler ( "onClientCursorMove", root, freecamMouse ) removeEventHandler ( 'onClientRender', root, updatePlayerWeapon ) removeEventHandler ( 'onClientRender', root, renderVehCross ) triggerServerEvent ( "detachPlayerFromMG", localPlayer ) setElementAlpha ( localPlayer, 255 ) toggleControl ("fire", true) toggleCockpitView() local text = getElementData ( localPlayer, "text" ) local text2 = getElementData ( localPlayer, "text2" ) local img = getElementData ( localPlayer, "img" ) destroyElement(text) destroyElement(text2) destroyElement(img) end end addEventHandler ( "onClientPlayerWasted", getLocalPlayer(), onWasted ) function onDemage() if inUse == true then setPedAnimationProgress(localPlayer, "SilenceCrouchfire", 0.7) triggerServerEvent ( "demage_anim", localPlayer) end end addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), onDemage ) function renderVehCross () if inUse == true then dxDrawImage (w/2-34, h/2-38,68,68,"files/crosshair.png",0,0,0) setCameraFieldOfView("player",70) else removeEventHandler('onClientRender', root, renderVehCross ) end end function fireCustomVehWeapon () if inUse == true then local px,py,pz = getElementPosition (localPlayer) local x,y,z = getWorldFromScreenPosition ( w/2, h/2, 50 ) setElementData ( localPlayer, "attachedToWeapon_aim", {x,y,z} ) setElementData ( localPlayer, "attachedToWeapon_fire", true) setTimer ( updateWeaponTargetOnFire, 200, 1 ) triggerServerEvent("fire_server", localPlayer, localPlayer,px,py,pz) end end bindKey ("mouse1", "down", fireCustomVehWeapon) function updateWeaponTargetOnFire () if getKeyState ("mouse1") and inUse == true then local x,y,z = getWorldFromScreenPosition ( w/2, h/2, 75 ) setElementData ( localPlayer, "attachedToWeapon_aim", {x,y,z} ) setTimer ( updateWeaponTargetOnFire, 100, 1 ) else setElementData ( localPlayer, "attachedToWeapon_fire", false) end end function fire_client(player,px,py,pz) local sound_mg = getElementData ( localPlayer, "sound_mg" ) if not isElement(sound_mg) then local gun = getElementData ( localPlayer, "gun" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition (localPlayer) local sound_mg = playSound3D ( "files/mg.wav", px,py,pz, true ) setSoundMaxDistance ( sound_mg, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setElementData ( localPlayer, "sound_mg", sound_mg ) setTimer ( fireCustomWeapInTime, 50, 1, gun, player ) end local sound_mg = getElementData ( localPlayer, "sound_mg" ) if not isElement(sound_mg) then local gun = getElementData ( localPlayer, "gun2" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition ( gun ) local sound_mg = playSound3D ( "files/mg.wav", x,y,z, true ) setSoundMaxDistance ( sound_mg, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setTimer ( fireCustomWeapInTime, 50, 1, gun, player ) setElementData ( localPlayer, "sound_mg", sound_mg ) end end addEvent("fire_client", true) addEventHandler("fire_client",getRootElement(), fire_client) function fireCustomWeapInTime (gun, player) if isElement ( player ) and getElementData ( player, "attachedToWeapon_fire" ) then local aim = getElementData ( player, "attachedToWeapon_aim" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) timer = setTimer ( fireCustomWeapInTime, 100, 1, gun, player ) else local sound_mg = getElementData ( localPlayer, "sound_mg" ) local x,y,z = getElementPosition ( player ) setWeaponState ( gun, "ready" ) stopSound(sound_mg) end end function fire_client2(player,px,py,pz) local sound_mg2 = getElementData ( localPlayer, "sound_mg2" ) if not isElement(sound_mg2) then local gun = getElementData ( localPlayer, "gun2" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition (localPlayer) local sound_mg2 = playSound3D ( "files/mg.wav", px,py,pz, true ) setSoundMaxDistance ( sound_mg2, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setElementData ( localPlayer, "sound_mg2", sound_mg2 ) setTimer ( fireCustomWeapInTime2, 50, 1, gun, player ) end local sound_mg2 = getElementData ( localPlayer, "sound_mg2" ) if not isElement(sound_mg2) then local gun = getElementData ( localPlayer, "gun2" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition ( gun ) local sound_mg2 = playSound3D ( "files/mg.wav", x,y,z, true ) setSoundMaxDistance ( sound_mg2, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setTimer ( fireCustomWeapInTime2, 50, 1, gun, player ) setElementData ( localPlayer, "sound_mg2", sound_mg2 ) end end addEvent("fire_client2", true) addEventHandler("fire_client2",getRootElement(), fire_client2) function fireCustomWeapInTime2 (gun, player) if isElement ( player ) and getElementData ( player, "attachedToWeapon_fire" ) then local aim = getElementData ( player, "attachedToWeapon_aim" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) timer = setTimer ( fireCustomWeapInTime2, 100, 1, gun, player ) else local sound_mg2 = getElementData ( localPlayer, "sound_mg2" ) local x,y,z = getElementPosition ( player ) setWeaponState ( gun, "ready" ) stopSound(sound_mg2) end end function fire_client3(player,px,py,pz) local sound_mg3 = getElementData ( localPlayer, "sound_mg3" ) if not isElement(sound_mg3) then local gun = getElementData ( localPlayer, "gun3" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition (localPlayer) local sound_mg3 = playSound3D ( "files/mg.wav", px,py,pz, true ) setSoundMaxDistance ( sound_mg3, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setElementData ( localPlayer, "sound_mg3", sound_mg3 ) setTimer ( fireCustomWeapInTime3, 50, 1, gun, player ) end local sound_mg3 = getElementData ( localPlayer, "sound_mg3" ) if not isElement(sound_mg3) then local gun = getElementData ( localPlayer, "gun3" ) local aim = getElementData ( player, "attachedToWeapon_aim" ) local x,y,z = getElementPosition ( gun ) local sound_mg3 = playSound3D ( "files/mg.wav", x,y,z, true ) setSoundMaxDistance ( sound_mg3, 500 ) setWeaponState ( gun, "firing" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) setTimer ( fireCustomWeapInTime3, 50, 1, gun, player ) setElementData ( localPlayer, "sound_mg3", sound_mg3 ) end end addEvent("fire_client3", true) addEventHandler("fire_client3",getRootElement(), fire_client2) function fireCustomWeapInTime3 (gun, player) if isElement ( player ) and getElementData ( player, "attachedToWeapon_fire" ) then local aim = getElementData ( player, "attachedToWeapon_aim" ) setWeaponTarget(gun, aim[1],aim[2],aim[3]) timer = setTimer ( fireCustomWeapInTime3, 100, 1, gun, player ) else local sound_mg3 = getElementData ( localPlayer, "sound_mg3" ) local x,y,z = getElementPosition ( player ) setWeaponState ( gun, "ready" ) stopSound(sound_mg3) end end function stop_client() if inUse == true then local x,y,z = getElementPosition (localPlayer) triggerServerEvent("ready_server", localPlayer, x,y,z) end end bindKey ("mouse1", "up", stop_client) function stop(x,y,z) local sound_lastshoot = playSound3D ( "files/mg_lastshoot.wav", x,y,z ) setSoundMaxDistance ( sound_lastshoot, 500 ) end addEvent("ready_client", true) addEventHandler("ready_client",getRootElement(), stop) function createCol(posX,posY) local col = createColCircle ( posX+1,posY, 0.9 ) addEventHandler ( "onClientColShapeHit", col, onHit ) addEventHandler ( "onClientColShapeLeave", col, onLeave ) end addEvent("createCol", true) addEventHandler("createCol",getRootElement(), createCol) function onHit( theElement ) if inUse_s == false then if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text2 = getElementData ( localPlayer, "text2" ) if not isElement(text2) then local text = guiCreateLabel( 0.470, 0.32, 4, 2, "Press USE [G] to use", true) local img = guiCreateStaticImage(0.57, 0.3, 0.09, 0.06, "files/mg42.png", true) guiSetFont ( text, "default-bold-small" ) setElementData (localPlayer, "text", text) setElementData (localPlayer, "img", img) end end end end function onLeave( theElement ) if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text = getElementData ( localPlayer, "text" ) local img = getElementData ( localPlayer, "img" ) destroyElement(text) destroyElement(img) end end function createCol2(posX,posY) local col2 = createColCircle ( posX+1,posY, 0.9 ) addEventHandler ( "onClientColShapeHit", col2, onHit2 ) addEventHandler ( "onClientColShapeLeave", col2, onLeave2 ) end addEvent("createCol2", true) addEventHandler("createCol2",getRootElement(), createCol2) function onHit2(theElement) if inUse_s2 == false then if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text2 = getElementData ( localPlayer, "text2" ) if not isElement(text2) then local text = guiCreateLabel( 0.470, 0.32, 4, 2, "Press USE [G] to use", true) local img = guiCreateStaticImage(0.57, 0.3, 0.09, 0.06, "files/mg42.png", true) guiSetFont ( text, "default-bold-small" ) setElementData (localPlayer, "text", text) setElementData (localPlayer, "img", img) end end end end function onLeave2(theElement) if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text = getElementData ( localPlayer, "text" ) local img = getElementData ( localPlayer, "img" ) destroyElement(text) destroyElement(img) end end function createCol3(posX,posY) local col3 = createColCircle ( posX+1,posY, 0.9 ) addEventHandler ( "onClientColShapeHit", col3, onHit3 ) addEventHandler ( "onClientColShapeLeave", col3, onLeave3 ) end addEvent("createCol3", true) addEventHandler("createCol3",getRootElement(), createCol3) function onHit3(theElement) if inUse_s3 == false then if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text2 = getElementData ( localPlayer, "text2" ) if not isElement(text2) then local text = guiCreateLabel( 0.470, 0.32, 4, 2, "Press USE [G] to use", true) local img = guiCreateStaticImage(0.57, 0.3, 0.09, 0.06, "files/mg42.png", true) guiSetFont ( text, "default-bold-small" ) setElementData (localPlayer, "text", text) setElementData (localPlayer, "img", img) end end end end function onLeave3(theElement) if ( theElement == getLocalPlayer() ) and not isPedInVehicle(localPlayer) and inUse == false then local text = getElementData ( localPlayer, "text" ) local img = getElementData ( localPlayer, "img" ) destroyElement(text) destroyElement(img) end end function causeCustomWeaponDamage(hitElement) if hitElement then local owner = getElementData(source,"owner") if getElementType ( hitElement ) == "vehicle" then triggerServerEvent ( "causeVehicleDamageFromMG", localPlayer, hitElement ) end end end addEventHandler("onClientWeaponFire", getRootElement(), causeCustomWeaponDamage) function DamageToPlayersFromCustomWeapons(target) if target == localPlayer then setElementHealth ( target, getElementHealth(target) - 8 ) end end addEventHandler("onClientWeaponFire", root, DamageToPlayersFromCustomWeapons) function getPositionInfrontOfElement(x,y,rotation, meters) posX = x - math.sin(math.rad(rotation)) * meters posY = y + math.cos(math.rad(rotation)) * meters return posX, posY, posZ end function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end; return t; end 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 ) ) rotx = math.deg(rotx) rotz = -math.deg(rotz) return rotx, 180, rotz end function updatePlayerWeapon () if inUse == true then local x, y, z, lx, ly, lz = getCameraMatrix () local rot = findRotation ( x,y,lx,ly ) local rot2_x, rot_y, rot2_z = getCameraRotation() setElementRotation ( localPlayer, 0, 0, rot, "default", true ) triggerServerEvent ("rotatePlayerWeapon",localPlayer,rot,rot2_x) end end local root = getRootElement() local localPlayer = getLocalPlayer() local PI = math.pi local isEnabled = false 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 local forceFadeBack = false function toggleCockpitView() if (not isEnabled) then isEnabled = true addEventHandler ("onClientPreRender", root, updateCamera) addEventHandler ("onClientCursorMove",root, freecamMouse) else --reset view isEnabled = false setCameraTarget (localPlayer, localPlayer) removeEventHandler ("onClientPreRender", root, updateCamera) removeEventHandler ("onClientCursorMove", root, freecamMouse) end end function updateCamera () if (isEnabled) then 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) or forceFadeBack 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 = getPedBonePosition (localPlayer, 6) 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 not inVehicle then 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 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 local normalX = (camNormalizedAngleY * normalAngleZ - camNormalizedAngleZ * normalAngleY) local normalY = (camNormalizedAngleZ * normalAngleX - camNormalizedAngleX * normalAngleZ) local normalZ = (camNormalizedAngleX * normalAngleY - camNormalizedAngleY * normalAngleX) camTargetX = camPosX + freeModeAngleX * 100 camTargetY = camPosY + freeModeAngleY * 100 camTargetZ = camPosZ + freeModeAngleZ * 100 setCameraMatrix (camPosX, camPosY, camPosZ+0.2, camTargetX-140, camTargetY, camTargetZ, roll) end end function freecamMouse (cX,cY,aX,aY) if isCursorShowing() or isMTAWindowActive() then mouseFrameDelay = 5 return elseif mouseFrameDelay > 0 then mouseFrameDelay = mouseFrameDelay - 1 return end startTick = getTickCount() recentlyMoved = true if fadeBack then fadeBack = false executeCounter = 0 end 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 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 function fps() if inUse == true then toggleCockpitView() end end --bindKey ( "mouse3", "down", fps) function aim_in() if inUse == true then removeEventHandler('onClientRender', root, renderVehCross ) addEventHandler('onClientRender', root, renderVehCross2 ) else removeEventHandler('onClientRender', root, renderVehCross ) end end --bindKey ("mouse2", "down", aim_in) function aim_out() if inUse == true then removeEventHandler('onClientRender', root, renderVehCross2 ) addEventHandler('onClientRender', root, renderVehCross ) end end --bindKey ("mouse2", "up", aim_out) function renderVehCross2 () if inUse == true then dxDrawImage (w/2-28, h/2-32,58,58,"files/crosshair.png",0,0,0) setCameraFieldOfView("player",50) end end function replaceskin() txd = engineLoadTXD ( "files/m4.txd" ) engineImportTXD ( txd, 356) dff = engineLoadDFF ( "files/m4.dff", 356) engineReplaceModel ( dff, 356) end addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), replaceskin) addCommandHandler( "on", function () setDevelopmentMode ( true ) end ) Server Side: tion = isElementWithinColShape ( source, col_s ) local detection2 = isElementWithinColShape ( source, col_s2 ) local detection3 = isElementWithinColShape ( source, col_s3 ) if detection then local weap = getElementData ( mg, "weapon_base" ) local weap2 = getElementData ( mg, "weapon" ) local x,y,z = getElementRotation (weap) setElementRotation ( weap, 0,0,rot+97) if rot < 40 then --outputChatBox ( "< 40" ) --triggerClientEvent("right", root) end if rot > 140 then --outputChatBox ( "> 180" ) --triggerClientEvent("left", root) end local x,y,z,rx,ry,rz = getElementAttachedOffsets (weap2) if -rot2_x < 8 then setElementAttachedOffsets ( weap2, x, y, z, rx, -rot2_x+10, rz) end elseif detection2 then local weap = getElementData ( mg2, "weapon_base" ) local weap2 = getElementData ( mg2, "weapon" ) local x,y,z = getElementRotation (weap) setElementRotation ( weap, 0,0,rot+97) if rot < 40 then --outputChatBox ( "< 40" ) --triggerClientEvent("right", root) end if rot > 140 then --outputChatBox ( "> 180" ) --triggerClientEvent("left", root) end local x,y,z,rx,ry,rz = getElementAttachedOffsets (weap2) if -rot2_x < 8 then setElementAttachedOffsets ( weap2, x, y, z, rx, -rot2_x+10, rz) end elseif detection3 then local weap = getElementData ( mg3, "weapon_base" ) local weap2 = getElementData ( mg3, "weapon" ) local x,y,z = getElementRotation (weap) setElementRotation ( weap, 0,0,rot+97) if rot < 40 then --outputChatBox ( "< 40" ) --triggerClientEvent("right", root) end if rot > 140 then --outputChatBox ( "> 180" ) --triggerClientEvent("left", root) end local x,y,z,rx,ry,rz = getElementAttachedOffsets (weap2) if -rot2_x < 8 then setElementAttachedOffsets ( weap2, x, y, z, rx, -rot2_x+10, rz) end end end addEvent("rotatePlayerWeapon", true) addEventHandler("rotatePlayerWeapon",getRootElement(), rotate) function fire_server(player,px,py,pz) local detection = isElementWithinColShape ( source, col_s ) local detection2 = isElementWithinColShape ( source, col_s2 ) local detection3 = isElementWithinColShape ( source, col_s3 ) if detection then triggerClientEvent("fire_client", getRootElement(), player,px,py,pz) elseif detection2 then triggerClientEvent("fire_client2", getRootElement(), player,px,py,pz) elseif detection3 then triggerClientEvent("fire_client3", getRootElement(), player,px,py,pz) end end addEvent("fire_server", true) addEventHandler("fire_server",getRootElement(), fire_server) function ready_server(player,x,y,z) triggerClientEvent("ready_client", getRootElement(), player,x,y,z) end addEvent("ready_server", true) addEventHandler("ready_server",getRootElement(), ready_server) the script is createing a 2 or 3 machine gun's but i can't found the functoin of createing it to manipulte and mounted on a vehicle i want the machine gun to mount in the back of bobcat i think the code is flexible and my problem is esay to solve for those how has a exp in Lua thank alot
  7. cashu paypal او اي عملة معدنية مو مشكلة
  8. السلام عليكم ورحمة الله وباركته مبرمج Lua محترف خبرة 3 سنوات مستعد لبرمجة اي جيم مود او سكربتات بمقابل مادي الديسكورد حقي ||M.O.M||'Dev#4281 شكرا
  9. hello guys, i'm looking for an answer for my question is there an enb series for mta sa ?
  10. Hi Guys , i'm working on a new gamemode and i want to add a custom tank well i know how to fire a rocket like the Rhino in another vehicle but the problem is how to make it Aim like Rhino & move like rhino . ? what should i use any function to help me i well be grateful . ps. Rhino is the tank Thanks
  11. Hi Guys ,,, Well i have this code that add tint on vehicle but i have problem with it i want The shader apply only for one specified car not all models like When player comes to the shop and wants he's infernus to get tint i want the script to only change the infernus texture not all textures i hope you get the idea my code , local shader = dxCreateShader("tint.fx", 1, 0, true) -- Create a shader local vehicle = getPedOccupiedVehicle ( source ) engineApplyShaderToWorldTexture(shader, "plm_glass", vehicle) -- i want The shader only Applys on [ texture ] for Vehicle
  12. i'm completely lost man can you edit my code i well be grateful client : Thanks Man it works i appreciate your help