Xwad Posted June 29, 2016 Share Posted June 29, 2016 I downloaded this custom rocket script: https://community.multitheftauto.com/in ... ls&id=3742 my problem is that the rocket projectile is not shooting to the direction where the locals player camera look at. my code starts at line 58. client gLPlayer = getLocalPlayer() addEvent("onClientPlayerFireRocket", false) function fireRocketByRotation(startX, startY, startZ, rotX, rotZ, velocity) local nrotX = -rotX local nrotZ = -(rotZ + 180) local velZ = velocity * math.sin(math.rad(rotX)) local a = velocity * math.cos(math.rad(rotX)) local velX = a * math.sin(math.rad(-rotZ)) local velY = a * math.cos(math.rad(-rotZ)) createProjectile(gLPlayer, 19, startX, startY, startZ, 1.0, nil, nrotX, 0, nrotZ, velX / 50, velY / 50, velZ / 50) triggerEvent("onClientPlayerFireRocket", gLPlayer) end function fireRocketByTargetPosition(startX, startY, startZ, targetX, targetY, targetZ, velocity) local rotZ = getRotationZ(startX, startY, targetX, targetY) local rotX = getRotationX(startX, startY, startZ, targetX, targetY, targetZ) fireRocketByRotation(startX, startY, startZ, rotX, rotZ, velocity) end function getRotationZ(startX, startY, endX, endY) -- Dommed-Space-Marine local height = endX - startX local line = endY - startY local t = -math.deg(math.atan2(height, line)) if t < 0 then t = t + 360 end return t end function getRotationX(startX, startY, startZ, endX, endY, endZ) -- Dommed-Space-Marine local line = ((endX - startX) ^ 2 + (endY - startY) ^ 2) ^ 0.5 local height = endZ - startZ local t = math.deg(math.atan2(height, line)) --[[ if t < 0 then t = t + 360 end --]] return t end function rocket() local x,y,z = getElementPosition(localPlayer) <--- THIS IS WORKING local rx,_,rz = getPedCameraRotation(localPlayer) <--- THIS IS NOT WORKING fireRocketByRotation(x,y,z,rx,rz 50) <--- THIS IS NOT WORKING end end bindKey("mouse1", "down", rocket) Link to comment
Dimos7 Posted June 29, 2016 Share Posted June 29, 2016 gLPlayer = getLocalPlayer() addEvent("onClientPlayerFireRocket", false) function fireRocketByRotation(startX, startY, startZ, rotX, rotZ, velocity) local nrotX = -rotX local nrotZ = -(rotZ + 180) local velZ = velocity * math.sin(math.rad(rotX)) local a = velocity * math.cos(math.rad(rotX)) local velX = a * math.sin(math.rad(-rotZ)) local velY = a * math.cos(math.rad(-rotZ)) createProjectile(gLPlayer, 19, startX, startY, startZ, 1.0, nil, nrotX, 0, nrotZ, velX / 50, velY / 50, velZ / 50) triggerEvent("onClientPlayerFireRocket", gLPlayer) end function fireRocketByTargetPosition(startX, startY, startZ, targetX, targetY, targetZ, velocity) local rotZ = getRotationZ(startX, startY, targetX, targetY) local rotX = getRotationX(startX, startY, startZ, targetX, targetY, targetZ) fireRocketByRotation(startX, startY, startZ, rotX, rotZ, velocity) end function getRotationZ(startX, startY, endX, endY) -- Dommed-Space-Marine local height = endX - startX local line = endY - startY local t = -math.deg(math.atan2(height, line)) if t < 0 then t = t + 360 end return t end function getRotationX(startX, startY, startZ, endX, endY, endZ) -- Dommed-Space-Marine local line = ((endX - startX) ^ 2 + (endY - startY) ^ 2) ^ 0.5 local height = endZ - startZ local t = math.deg(math.atan2(height, line)) --[[ if t < 0 then t = t + 360 end --]] return t end function rocket() local x,y,z = getElementPosition(gLPlayer) local rx,ry, rz = getPedCameraRotation(gLPlayer) fireRocketByRotation(x,y,z,rx,ry,rz 50) end end bindKey("mouse1", "down", rocket) Link to comment
DarkByte Posted June 29, 2016 Share Posted June 29, 2016 You forgot one comma, here try this. gLPlayer = getLocalPlayer() addEvent("onClientPlayerFireRocket", false) function fireRocketByRotation(startX, startY, startZ, rotX, rotZ, velocity) local nrotX = -rotX local nrotZ = -(rotZ + 180) local velZ = velocity * math.sin(math.rad(rotX)) local a = velocity * math.cos(math.rad(rotX)) local velX = a * math.sin(math.rad(-rotZ)) local velY = a * math.cos(math.rad(-rotZ)) createProjectile(gLPlayer, 19, startX, startY, startZ, 1.0, nil, nrotX, 0, nrotZ, velX / 50, velY / 50, velZ / 50) triggerEvent("onClientPlayerFireRocket", gLPlayer) end function fireRocketByTargetPosition(startX, startY, startZ, targetX, targetY, targetZ, velocity) local rotZ = getRotationZ(startX, startY, targetX, targetY) local rotX = getRotationX(startX, startY, startZ, targetX, targetY, targetZ) fireRocketByRotation(startX, startY, startZ, rotX, rotZ, velocity) end function getRotationZ(startX, startY, endX, endY) -- Dommed-Space-Marine local height = endX - startX local line = endY - startY local t = -math.deg(math.atan2(height, line)) if t < 0 then t = t + 360 end return t end function getRotationX(startX, startY, startZ, endX, endY, endZ) -- Dommed-Space-Marine local line = ((endX - startX) ^ 2 + (endY - startY) ^ 2) ^ 0.5 local height = endZ - startZ local t = math.deg(math.atan2(height, line)) --[[ if t < 0 then t = t + 360 end --]] return t end function rocket() local x,y,z = getElementPosition(gLPlayer) local rx,ry, rz = getPedCameraRotation(gLPlayer) fireRocketByRotation(x,y,z,rx,ry,rz, 50) end end bindKey("mouse1", "down", rocket) Link to comment
ozulus Posted June 29, 2016 Share Posted June 29, 2016 function rocket() local x,y,z = getElementPosition(gLPlayer) local rx, _, rz = getPedCameraRotation(gLPlayer) fireRocketByRotation(x, y, z, rx, rz, 50) end bindKey("mouse1", "down", rocket) Link to comment
Captain Cody Posted June 29, 2016 Share Posted June 29, 2016 All it takes is one missing comma or what not to mess it all up. Link to comment
Dimos7 Posted June 30, 2016 Share Posted June 30, 2016 gLPlayer = getLocalPlayer() addEvent("onClientPlayerFireRocket", false) function fireRocketByRotation(startX, startY, startZ, rotX, rotZ, velocity) local nrotX = -rotX local nrotZ = -(rotZ + 180) local velZ = velocity * math.sin(math.rad(rotX)) local a = velocity * math.cos(math.rad(rotX)) local velX = a * math.sin(math.rad(-rotZ)) local velY = a * math.cos(math.rad(-rotZ)) createProjectile(gLPlayer, 19, startX, startY, startZ, 1.0, nil, nrotX, 0, nrotZ, velX / 50, velY / 50, velZ / 50) triggerEvent("onClientPlayerFireRocket", gLPlayer) end function fireRocketByTargetPosition(startX, startY, startZ, targetX, targetY, targetZ, velocity) local rotZ = getRotationZ(startX, startY, targetX, targetY) local rotX = getRotationX(startX, startY, startZ, targetX, targetY, targetZ) fireRocketByRotation(startX, startY, startZ, rotX, rotZ, velocity) end function getRotationZ(startX, startY, endX, endY) -- Dommed-Space-Marine local height = endX - startX local line = endY - startY local t = -math.deg(math.atan2(height, line)) if t < 0 then t = t + 360 end return t end function getRotationX(startX, startY, startZ, endX, endY, endZ) -- Dommed-Space-Marine local line = ((endX - startX) ^ 2 + (endY - startY) ^ 2) ^ 0.5 local height = endZ - startZ local t = math.deg(math.atan2(height, line)) --[[ if t < 0 then t = t + 360 end --]] return t end function rocket() local x,y,z = getElementPosition(gLPlayer) local rx, _, rz = getPedCameraRotation(gLPlayer) fireRocketByRotation(x,y,z,rx,rz, 50) end bindKey("mouse1", "down", rocket) Link to comment
Xwad Posted June 30, 2016 Author Share Posted June 30, 2016 ERROR: Attempt to perform arithmetic on local 'rotZ' (a nil value) Link to comment
Xwad Posted July 25, 2016 Author Share Posted July 25, 2016 pls help me fix this bug: i cant shoot with the rocket up, and down: function mp5_projectile(weapon,ammo,ammoInClip,hitX,hitY,hitZ,hitElement) local PedWeapon = getPedWeapon(localPlayer) local id = getElementModel ( source ) if id == 20 or id == 100 then if (PedWeapon == 29) then local x,y,z = getElementPosition(getLocalPlayer()) local forward_velocity = 1.5 -- do any changes you want here, it adjusts the forward velocity local height_velocity = 0 -- and here, it adjusts the velocity along Z axis local _, _, r = getElementRotation(getLocalPlayer()) pro = createProjectile(getLocalPlayer(),19,x,y,z,200, nil, 0, 0, 0, math.sin(math.rad(-r))*forward_velocity, math.cos(math.rad(-r))*forward_velocity, height_velocity) end end end addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(), mp5_projectile) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now