DarkByte Posted September 20, 2015 Share Posted September 20, 2015 Hi i tried to make a script and its not working. I wanna add laser at the tank. function laser ( creator) if getElementType(creator) == "vehicle" then if getElementModel(creator) == 432 then local x, y = getVehicleComponentPosition( creator, "misc_c" ) local x1, y1 = getVehicleComponentPosition( creator, "misc_a" ) dxDrawLine ( x, y, x1, y1, tocolor ( 255, 0, 0, 255 ) end end end end addEventHandler("onClientVehicleEnter", getRootElement(), laser) Link to comment
HUNGRY:3 Posted September 20, 2015 Share Posted September 20, 2015 yes ofc it will not work since you didn't add the event "onClientRender" because it's very important for dx functions so it should be like this local x, y local x1, y1 function laser () local theVeh = getPedOccupiedVehicle(localPlayer) if getElementModel(theVeh) == 432 then x, y = getVehicleComponentPosition( theVeh, "misc_c" ) x1, y1 = getVehicleComponentPosition( theVeh, "misc_a" ) addEventHandler("onClientRender",root,add) end end addEventHandler("onClientVehicleEnter", getRootElement(), laser) function add() dxDrawLine ( x, y, x1, y1, tocolor ( 255, 0, 0, 255 ) ) end and what the hell is creator Link to comment
DarkByte Posted September 20, 2015 Author Share Posted September 20, 2015 Not working. Link to comment
HUNGRY:3 Posted September 20, 2015 Share Posted September 20, 2015 (edited) your code doesn't make sense what's misc? Edited September 20, 2015 by Guest Link to comment
DarkByte Posted September 20, 2015 Author Share Posted September 20, 2015 NOt working Link to comment
DarkByte Posted September 20, 2015 Author Share Posted September 20, 2015 http://imgur.com/f7rfz6r To Look this this Link to comment
DarkByte Posted September 20, 2015 Author Share Posted September 20, 2015 Anyone help me? Link to comment
BluntZ Posted September 20, 2015 Share Posted September 20, 2015 Any error in debugscript ? Link to comment
JR10 Posted September 20, 2015 Share Posted September 20, 2015 You want it to look like the picture? And how does it look right now? Are you sure the components are correct? Link to comment
DarkByte Posted September 20, 2015 Author Share Posted September 20, 2015 YES, i want like in the picture. I tried to make it. But i cant. Can someone help me? Link to comment
Moderators IIYAMA Posted September 21, 2015 Moderators Share Posted September 21, 2015 Get the function extendLine from the stealth resource, to extend the line... Which you probably can find in the main client file from stealth. And don't forget that the z variable is required from getVehicleComponentPosition to make this work. Link to comment
DarkByte Posted September 21, 2015 Author Share Posted September 21, 2015 I found it. Can you help me futher. local laserWeapons = {} function drawLasers() for k,player in ipairs(getElementsByType"player") do local playerWeapon = getPedWeapon ( player ) if ( laserWeapons[playerWeapon] ) then local startX,startY,startZ,targetX,targetY,targetZ local boneX,boneY,boneZ = getPedBonePosition ( player, 25 ) startX,startY,startZ = getPedWeaponMuzzlePosition ( player ) if boneX and startX then if getPedControlState(player, "aim_weapon") then targetX, targetY, targetZ = getPedTargetEnd(player) else targetX,targetY,targetZ = extendLine ( boneX,boneY,boneZ,startX,startY,startZ - 0.1,500 ) end local bool,hitX,hitY,hitZ = processLineOfSight ( startX,startY,startZ,targetX,targetY,targetZ, true, true, true, true, true, false, false, true ) if not bool or not hitX then hitX,hitY,hitZ = targetX,targetY,targetZ end dxDrawLine3D ( startX,startY,startZ, hitX,hitY,hitZ, tocolor(255,0,0,50), 1, false, 1 ) end end end end Link to comment
Moderators IIYAMA Posted September 21, 2015 Moderators Share Posted September 21, 2015 In the code you posted there is only a reference to that function. You have to get the full function. function extendLine ( .... ... .. .. end Link to comment
DarkByte Posted September 21, 2015 Author Share Posted September 21, 2015 function extendLine ( x,y,z,x2,y2,z2,length ) local vx = x2 - x local vy = y2 - y local vz = z2 - z local ratio = length/(getDistanceBetweenPoints3D ( x,y,z,x2,y2,z2 )) vx = vx*ratio vy = vy*ratio vz = vz*ratio return (x + vx),(y + vy),(z + vz) end Link to comment
Moderators IIYAMA Posted September 21, 2015 Moderators Share Posted September 21, 2015 It is not really optimised based on when it renders. But it should be working. I added dxDrawLine3D instead of dxDrawLine because it is easier to use for 3D. But if you want to keep the line the same thickness, you will have to study this function: https://wiki.multitheftauto.com/wiki/Ge ... ldPosition in order to use dxDrawLine > 3D. function extendLine ( x,y,z,x2,y2,z2,length ) local vx = x2 - x local vy = y2 - y local vz = z2 - z local ratio = length/(getDistanceBetweenPoints3D ( x,y,z,x2,y2,z2 )) vx = vx*ratio vy = vy*ratio vz = vz*ratio return (x + vx),(y + vy),(z + vz) end local renderTankLine = function () local theVeh = getPedOccupiedVehicle(localPlayer) if theVeh and getElementModel(theVeh) == 432 then local x,y,z = getVehicleComponentPosition( theVeh, "misc_c" ) local x1,y1,z1 = getVehicleComponentPosition( theVeh, "misc_a" ) if x and x1 then local endX,endY,endZ = extendLine(x,y,z,x1,y1,z1,300) dxDrawLine3D (x,y,z,endX,endY,endZ,tocolor(255,0,0)) end end end addEventHandler("onClientRender",root,renderTankLine) Update 19:35 Link to comment
DarkByte Posted September 21, 2015 Author Share Posted September 21, 2015 Not working Link to comment
DarkByte Posted September 21, 2015 Author Share Posted September 21, 2015 http://imgur.com/tRQkshJ Link to comment
Moderators IIYAMA Posted September 21, 2015 Moderators Share Posted September 21, 2015 Did you copied the code after 19:35? I didn't add those red letters for nothing. Link to comment
DarkByte Posted September 21, 2015 Author Share Posted September 21, 2015 YEs still nothing Link to comment
Moderators IIYAMA Posted September 21, 2015 Moderators Share Posted September 21, 2015 Any errors or warnings? Because exactly those from that screenshot shouldn't be visible any more. Link to comment
DarkByte Posted September 21, 2015 Author Share Posted September 21, 2015 http://imgur.com/6S3SZky Link to comment
HUNGRY:3 Posted September 21, 2015 Share Posted September 21, 2015 function renderTankLine() local theVeh = getPedOccupiedVehicle(localPlayer) if theVeh and getElementModel(theVeh) == 432 then local x,y,z = getVehicleComponentPosition( theVeh, "misc_c" ) local x1,y1,z1 = getVehicleComponentPosition( theVeh, "misc_a" ) if x and x1 then local endX,endY,endZ = extendLine(x,y,z,x1,y1,z1,300) dxDrawLine3D (x,y,z,endX,endY,endZ,tocolor(255,0,0)) end end end addEventHandler("onClientRender",root,renderTankLine) Link to comment
Moderators IIYAMA Posted September 21, 2015 Moderators Share Posted September 21, 2015 That warning you see is not from me. @HUNGRY:3 what did you change? I don't see any differences. @-Lemonade- Try to make the line a little bit thicker, because it must be somewhere. Link to comment
HUNGRY:3 Posted September 21, 2015 Share Posted September 21, 2015 That warning you see is not from me.@HUNGRY:3 what did you change? I don't see any differences. @-Lemonade- Try to make the line a little bit thicker, because it must be somewhere. Line 1 you did local renderblalala = function() It's from you :- ) IIYAMA-SENPAI That's why it's give error addEventHandler expected function 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