Jump to content

HustraDev

Members
  • Posts

    139
  • Joined

  • Last visited

Details

  • Gang
    Hustra

Recent Profile Visitors

1,346 profile views

HustraDev's Achievements

Poot-butt

Poot-butt (14/54)

6

Reputation

  1. Hello, as the title say's i'm having a problem opening MTA SA client when i open it all gui shakes and disappears by that i mean like this screenshot ScreenShot that it thanks alot.
  2. Hello Guys, i'm working on this new script its a Mounted machine gun and i faced some problems, so first problem is in the `getOut` function supposed to make the player free by that i mean (detach the player from the minigun and the turret object `a minigun` and back to normal) and the second problem is, in drawin a crosshair for the weapon as you can see in the line [75] of the code it supposed to `drawImage`. but it does not < maybe i'm mistaken in writing the `drawImage` function under those lines of `cursorX` statement, if so please enlighten me and last but not least i want the `Weapon` to appear so i probably remove the `SetElementAlpha` to zero and replace the Weapon Model with a realistic weapon (i.e MG42) so, is this can be accomplish ? replacing the actual minigun weapon with another one? i tried to use function m42() txd = engineLoadTXD("m4.txd", 31) engineImportTXD(txd, 31) dff = engineLoadDFF("m4.dff", 31) engineReplaceModel(dff, 31) end --i guess the Weapon Model is 356 i tried with it but it didn't change the wepaon but its the same and if could replace the weapon how can i avoid the firing Rotation problems. because i think the weapon firing Rotation is already buggy. i really need this to work, beacuse i want to prove to myself that i'm capable of learning. code:- [ client side] local current w, h = guiGetScreenSize () addEvent("aim", true) addEventHandler("aim", resourceRoot, function(vehicle, object) current = { vehicle=vehicle, object=object} addEventHandler("onClientRender", root, aim) setElementAlpha(localPlayer, 0) addEventHandler("onClientResourceStop", resourceRoot, function () setElementAlpha(localPlayer, 255) setPedAnimation(localPlayer) end) addEventHandler("onClientPreRender", root, function () --[[ Creating the direction vector ]] local cameraX, cameraY, cameraZ, lx, ly, lz = getCameraMatrix() local directionVector = (Vector3(lx, ly, lz) - Vector3( cameraX, cameraY, cameraZ)) directionVector:normalize ( ) directionVector = directionVector * 300 local screenX, screenY = guiGetScreenSize() local startPositionX, startPositionY, startPositionZ = x, y, z local turrentX, turretY, turretZ = getElementPosition(localPlayer) -- must be the turret position turretZ = turretZ - 0.2 -- < just for test purposes -- draw turret dxDrawLine3D(turrentX, turretY, turretZ, turrentX, turretY, turretZ - 0.5, tocolor(0,0,0)) dxDrawLine3D(turrentX, turretY, turretZ - 0.5, turrentX + 0.5, turretY, turretZ - 1, tocolor(0,0,0)) dxDrawLine3D(turrentX, turretY, turretZ - 0.5, turrentX - 0.5, turretY, turretZ - 1, tocolor(0,0,0)) dxDrawLine3D(turrentX, turretY, turretZ - 0.5, turrentX, turretY - 0.5, turretZ - 1, tocolor(0,0,0)) dxDrawLine3D(turrentX, turretY, turretZ - 0.5, turrentX, turretY + 0.5, turretZ - 1, tocolor(0,0,0)) -- detect any hits local hit, hitX, hitY, hitZ, elementHit = processLineOfSight ( turrentX, turretY, turretZ, cameraX + directionVector.x, cameraY + directionVector.y, cameraZ + directionVector.z, true, -- checkBuildings true, -- checkVehicles true, -- checkPlayers true, -- checkObjects false, -- checkDummies false, -- seeThroughStuff false, -- shootThroughStuff localPlayer -- element ignoredElement ) if checkPassiveTimer("attachedToWeapon_aim", true, 300) then setElementData ( localPlayer, "attachedToWeapon_aim", {hitX,hitY,hitZ} ) end if not hit then hitX, hitY, hitZ = cameraX + directionVector.x, cameraY + directionVector.y, cameraZ + directionVector.z end dxDrawText(hit and "COLLISION!" or "NO COLLISION!", 300, 300) -- draw the line + cursor dxDrawLine3D(turrentX, turretY, turretZ, hitX, hitY, hitZ) local cursorX, cursorY = getScreenFromWorldPosition (hitX, hitY, hitZ) if cursorX then dxDrawImage (w/2-28, h/2-32,58,58,"files/crosshair.png",0,0,0) dxDrawCircle (screenX / 2, screenY / 2, 10) end end) end) function aim() local camRot = getPedCameraRotation(localPlayer) setElementAttachedOffsets(current.object, 0, -1.5, -0.25, 0, 0, -camRot+90) setElementRotation(localPlayer,0, 0, -camRot) local x,y,z = getWorldFromScreenPosition ( w/2, h/2, 50 ) setElementData ( localPlayer, "attachedToWeapon_aim", {x,y,z} ) local aim = getElementData ( localPlayer, "attachedToWeapon_aim" ) setWeaponTarget(Weapon, aim[1],aim[2],aim[3]) -- renderVehCross2() end function CreateRealWeapon(object) Weapon = createWeapon("minigun",0,0,0) setWeaponFiringRate(Weapon,70) setElementAlpha(Weapon,0) attachElements(Weapon,localPlayer,0.042,0.1,0.5,0.4,26,94) outputChatBox("Real Weapon Created At X:" .. x .. "Y:" .. y .. "Z:" .. z) end addEvent( "createWeapon", true ) addEventHandler( "createWeapon", localPlayer, CreateRealWeapon ) function renderVehCross2 () setCameraFieldOfView("player",70) end function ClientfireWeapon() if isElement(Weapon) then setPedAnimation(localPlayer,'Attractors','Stepsit_loop') setWeaponProperty(Weapon, "fire_rotation", 0, -30, 0) setWeaponState ( Weapon, "firing" ) end end addEvent("FireWeapon", true) addEventHandler("FireWeapon",getRootElement(), ClientfireWeapon) bindKey ("mouse1", "down", ClientfireWeapon) function ClientReadyWeapon() setWeaponState(Weapon, "ready") --- stops the weapon when the key is up end bindKey ("mouse1", "up", ClientReadyWeapon) function GetOut() destroyElement(Weapon) triggerServerEvent("remove",root) setElementAlpha(localPlayer, 255) setPedAnimation(localPlayer) removeEventHandler("onClientRender",root,aim) local x,y,z = getElementPosition(localPlayer) setElementPosition(localPlayer,x,y+4,z) end bindKey ("O", "down", GetOut) [server side] :- addCommandHandler("createTactical", function(player) x,y,z = getElementPosition(player) createVehicle(getVehicleModelFromName("Bobcat"), x, y+3, z+3) end) addCommandHandler("aim", function(player) local vehicle = getPedOccupiedVehicle(player) if not vehicle then return outputChatBox("Use in vehicle...", player) end removePedFromVehicle(player) object = createObject(2985, 0, 0, 0) local x,y,z = getElementRotation(object) triggerClientEvent("createWeapon",player,object) setElementCollisionsEnabled(object, false) attachElements(object, vehicle, 0, -1.5, -0.25) attachElements(player, object, -0.4, 0, 0.8) triggerClientEvent(player, "aim", resourceRoot, vehicle, object) end) addEvent("remove", true) addEventHandler("remove",root,function(player) detachElements(object,player) end) function TriggerFire() local x,y,z = getElementPosition(localPlayer) triggerClientEvent("FireWeapon",getRootElement()) end Thanks.
  3. i'm grateful for you help mate, see what i have done:- function aim() local camRot = getPedCameraRotation(localPlayer) setElementAttachedOffsets(current.object, 0, -1.5, -0.25, 0, 0, -camRot+90) setElementRotation(localPlayer,0, 0, -camRot) setElementAlpha(localPlayer, 0) addEventHandler("onClientResourceStop", resourceRoot, function () setElementAlpha(localPlayer, 255) end) addEventHandler("onClientPreRender", root, function () --[[ Creating the direction vector ]] local cameraX, cameraY, cameraZ, lx, ly, lz = getCameraMatrix() local directionVector = (Vector3(lx, ly, lz) - Vector3( cameraX, cameraY, cameraZ)) directionVector:normalize ( ) directionVector = directionVector * 300 local screenX, screenY = guiGetScreenSize() local startPositionX, startPositionY, startPositionZ = x, y, z local turrentX, turretY, turretZ = getElementPosition(localPlayer) -- must be the turret position turretZ = turretZ + 0.5 -- < just for test purposes -- draw turret dxDrawLine3D(turrentX, turretY, turretZ, turrentX, turretY, turretZ - 0.5, tocolor(0,0,0)) dxDrawLine3D(turrentX, turretY, turretZ - 0.5, turrentX + 0.5, turretY, turretZ - 1, tocolor(0,0,0)) dxDrawLine3D(turrentX, turretY, turretZ - 0.5, turrentX - 0.5, turretY, turretZ - 1, tocolor(0,0,0)) dxDrawLine3D(turrentX, turretY, turretZ - 0.5, turrentX, turretY - 0.5, turretZ - 1, tocolor(0,0,0)) dxDrawLine3D(turrentX, turretY, turretZ - 0.5, turrentX, turretY + 0.5, turretZ - 1, tocolor(0,0,0)) -- detect any hits local hit, hitX, hitY, hitZ, elementHit = processLineOfSight ( turrentX, turretY, turretZ, cameraX + directionVector.x, cameraY + directionVector.y, cameraZ + directionVector.z, true, -- checkBuildings true, -- checkVehicles true, -- checkPlayers true, -- checkObjects false, -- checkDummies false, -- seeThroughStuff false, -- ignoreSomeObjectsForCamera false, -- shootThroughStuff localPlayer -- element ignoredElement ) setElementData ( localPlayer, "attachedToWeapon_aim", {hitX,hitY,hitZ} ) if not hit then hitX, hitY, hitZ = cameraX + directionVector.x, cameraY + directionVector.y, cameraZ + directionVector.z end dxDrawText(hit and "COLLISION!" or "NO COLLISION!", 300, 300) -- draw the line + cursor dxDrawLine3D(turrentX, turretY, turretZ, hitX, hitY, hitZ) local cursorX, cursorY = getScreenFromWorldPosition (hitX, hitY, hitZ) if cursorX then dxDrawCircle ( cursorX, cursorY, 10) dxDrawCircle (screenX / 2, screenY / 2, 10) end end) renderVehCross2() end
  4. update :- i guess i get the idea of the crosshair and how it works, but there is two problems first is the weapon is "killing the Player when aiming down" the second one is the weapon movement, what i'm missing here? function ClientfireWeapon() local x,y,z = getWorldFromScreenPosition ( w/2, h/2, 50 ) setElementData ( localPlayer, "attachedToWeapon_aim", {x,y,z} ) local aim = getElementData ( localPlayer, "attachedToWeapon_aim" ) setWeaponTarget(Weapon, aim[1],aim[2],aim[3]) setWeaponState ( Weapon, "firing" ) end addEvent("FireWeapon", true) addEventHandler("FireWeapon",getRootElement(), ClientfireWeapon) bindKey ("mouse1", "down", ClientfireWeapon)
  5. thanks for your reply, what about the crosshair ?
  6. Hello, i created a weapon "minigun" using Create Weapon and i'm trying to make it fire like a weapon the Player have by that i mean ( it fires when mouse is clicked and stops when is not), i know that ( fireWeapon is the function that i should use ) so i tried to do it but i failed. also i have another question ( i'm willing to make a crosshair for the weapon and i have no idea how to make the weapon fires to the crosshair point) so if there is any examples or functions to give that will be great what i have tried :- Client Side:- function CreateRealWeapon(object) local Weapon = createWeapon("minigun",0,0,0) attachElements(Weapon,localPlayer,0.042,0.09,0.5,0,26,94) outputChatBox("Real Weapon Created At X:" .. x .. "Y:" .. y .. "Z:" .. z) end addEvent( "createWeapon", true ) addEventHandler( "createWeapon", localPlayer, CreateRealWeapon ) function ClientfireWeapon() setWeaponState ( Weapon, "firing" ) end addEvent("FireWeapon", true) addEventHandler("FireWeapon",getRootElement(), ClientfireWeapon) bindKey ("mouse1", "down", ClientfireWeapon) function ClientReadyWeapon() setWeaponState(Weapon, "Ready") --- stops the weapon when the key is up end bindKey ("mouse1", "up", ClientReadyWeapon) ServerSide:- function TriggerFire() local x,y,z = getElementPosition(localPlayer) triggerClientEvent("FireWeapon",getRootElement()) end
  7. Hello Community, i'm working on a tactical vehicle script , Basiclly i'm attaching a (machine gun) to the back of the (bobcat) vehicle, so that the player can hop in and used to be honest, i'm not sure that i have the entire idea on how to code it because ( i don't know how to make an aiming system ) i want to draw a crosshair on the screen and i want the player to be able to rotate the weapon. so my question is how can i make an ( aiming system ) for this.
  8. Yes, @Zango i want the player to control it, so its clear that first i need to create a weapon in the back of for example (bobcat) and then wrap the player to the weapon and attach the player to the weapon ex(minigun). this well be easy to do but how about ( aiming ) how i can make a crosshair that moves with the players cam and fires on the players command .. also firing to the crooshair world position
  9. hello guys, as the title says i'm looking for a tactical vehicle with working mounted machine gun like this ( GTA V ) tactical vehicle :- Picture so as you see from the picture that is what i'm looking for , ( if there is no script like that ) how could i code a one which functions is used to make fully working weapon .. attached to the back of a pickup vehicle like bobcat. Thanks.
  10. السلام عليكم ورحمة الله وباركته اخواني لدي مشكلة في مود رشاش المود جاهز حملته من الموقع بس الفكرة اني ابي اعدل عليه واخلي الرشاش تابت في خلف ال 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 للرشاش وسيارة شكرا
  11. مافي اي مساعدة شباب !؟
  12. السلام عليكم ورحمة الله وباركته اخواني عندي مشكلة في سكربت جديد قاعد ابرمج فيه والسكربت عبارة عن عداد تاكسي يحسب بالامتار المشكلة اني اريد ليبل او 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) ارجو المساعدة وشكرااا
  13. 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
×
×
  • Create New...