joedajoester Posted November 29, 2011 Share Posted November 29, 2011 Hi all, this script is in mta community i just edited it, i dont own it. I need it to have it so its not manual to create the lasers, the script does it automatically and after a few seconds they come back. i dont know how to do it lol please help me g_Mines = { } g_Plant = false g_Distance = 6000 g_Radius = 2 function plantCommand() showCursor ( true ) g_Plant = true end addCommandHandler("p", plantCommand) function onClientClick ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) if(g_Plant) then plantRequest( absoluteX, absoluteY) showCursor ( false ) g_Plant = false end end addEventHandler ( "onClientClick", getRootElement(), onClientClick ) function plantRequest(w, h) local tx, ty, tz = getWorldFromScreenPosition ( w, h, g_Distance ) local px, py, pz = getCameraMatrix() local hit, x, y, z, elementHit = processLineOfSight ( px, py, pz, tx, ty, tz, true, true, true, true, true, false, false, false, getLocalPlayer() ) if hit then triggerServerEvent ( "onCreateMine", getRootElement(), x, y, z ) end end function getTopPointRelativeOfElement(element,distance) local x, y, z = getElementPosition ( element ) local rx, ry, rz = getElementRotation ( element ) y = y - (distance * math.sin(math.rad(rx)) ) x = x + (distance * math.sin(math.rad(ry)) ) z = z + (distance * math.cos(math.rad(rx+ry)) ) return x,y,z end function onClientRender ( ) for k, v in ipairs(g_Mines) do processLaserMine ( k, v , g_Distance ) end end addEventHandler("onClientRender",getRootElement(), onClientRender) function processLaserMine(index, mine, distance) if ( isElement(mine) and getElementType (mine) == "object" ) then local x1, y1, z1 = getElementPosition ( mine ) local xp, yp, zp = getTopPointRelativeOfElement( mine, 0.1 ) local xt, yt, zt = getTopPointRelativeOfElement( mine, distance ) local hit, x2, y2, z2, elementHit = processLineOfSight ( xp, yp, zp, xt, yt, zt, true, true, true, true, true, false, false, false, mine ) if(elementHit) then explodeMine(index, mine, x1, y1, z1) end if(hit) then dxDrawLine3D ( x1, y1, z1, x2, y2, z2, tocolor ( 255, 0, 0, 0xAA ),1) else dxDrawLine3D ( x1, y1, z1, xt, yt, zt, tocolor ( 255, 0, 0, 0xAA ),1) end return true end return false end function onClientExplosion(x,y,z,type) -- explodeMine(0,nil,x,y,z) end addEventHandler("onClientExplosion",getRootElement(),onClientExplosion) function explodeMine(index, mine, x, y, z) if(isElement(mine)) then createExplosion ( 0, 0, 0, 3 ) createExplosion ( 11, 1, 4, 3 ) createExplosion ( 0, 0, 3, 3 ) table.remove(g_Mines,index) destroyElement(mine) end for k, v in ipairs(g_Mines) do local x2, y2, z2 = getElementPosition(v) if(getDistanceBetweenPoints3D ( x, y, z, x2, y2, z2 ) <= (g_Radius*2) ) then explodeMine(k, v, x2, y2, z2) end end end local checkSize = 0.1 function lowHitCheck(x,y,z,name) local t = checkSize if(name == "xu") then if isLineOfSightClear ( x+t, y, z, x+t/10, y, z ) and not isLineOfSightClear ( x+t, y+t, z, x-t, y-t, z ) and not isLineOfSightClear ( x+t, y-t, z, x-t, y+t, z ) and not isLineOfSightClear ( x+t, y, z+t, x-t, y, z-t ) and not isLineOfSightClear ( x+t, y, z-t, x-t, y, z+t ) then return true end elseif(name == "xd") then if isLineOfSightClear ( x-t, y, z, x-t/10, y, z ) and not isLineOfSightClear ( x-t, y+t, z, x+t, y-t, z ) and not isLineOfSightClear ( x-t, y-t, z, x+t, y+t, z ) and not isLineOfSightClear ( x-t, y, z+t, x+t, y, z-t ) and not isLineOfSightClear ( x-t, y, z-t, x+t, y, z+t ) then return true end elseif(name == "yu") then if isLineOfSightClear ( x, y+t, z, x, y+t/10, z ) and not isLineOfSightClear ( x+t, y+t, z, x-t, y-t, z ) and not isLineOfSightClear ( x-t, y+t, z, x+t, y-t, z ) and not isLineOfSightClear ( x, y+t, z+t, x, y-t, z-t ) and not isLineOfSightClear ( x, y+t, z-t, x, y-t, z+t ) then return true end elseif(name == "yd") then if isLineOfSightClear ( x, y-t, z, x, y-t/10, z ) and not isLineOfSightClear ( x+t, y-t, z, x-t, y+t, z ) and not isLineOfSightClear ( x-t, y-t, z, x+t, y+t, z ) and not isLineOfSightClear ( x, y-t, z+t, x, y+t, z-t ) and not isLineOfSightClear ( x, y-t, z-t, x, y+t, z+t ) then return true end elseif(name == "zu") then if isLineOfSightClear ( x, y, z+t, x, y, z+t/10 ) and not isLineOfSightClear ( x+t, y, z+t, x+t, y, z-t ) and not isLineOfSightClear ( x-t, y, z+t, x-t, y, z-t ) and not isLineOfSightClear ( x, y+t, z+t, x, y+t, z-t ) and not isLineOfSightClear ( x, y-t, z+t, x, y-t, z-t ) then return true end elseif(name == "zd") then if isLineOfSightClear ( x, y, z-t, x, y, z-t/10 ) and not isLineOfSightClear ( x+t, y, z-t, x+t, y, z+t ) and not isLineOfSightClear ( x-t, y, z-t, x-t, y, z+t ) and not isLineOfSightClear ( x, y+t, z-t, x, y+t, z+t ) and not isLineOfSightClear ( x, y-t, z-t, x, y-t, z+t ) then return true end end return false end function toang(value) if(value > 360.0) then while(value > 360.0) do value = value - 360.0 end elseif(value < 0.0) then while(value < 0.0) do value = value + 360.0 end end return value; end function lowHitGetNormal(x,y,z,name) local rx, ry, rz = 0, 0, 0 local t = checkSize if(name == "xu") then rx, ry, rz = 0, 90, 0 elseif(name == "xd") then rx, ry, rz = 0, 270, 0 elseif(name == "yu") then rx, ry, rz = 270, 0, 0 elseif(name == "yd") then rx, ry, rz = 90, 0, 0 elseif(name == "zu") then rx, ry, rz = 0, 0, 0 --hit, x1, y1, z1, elementHit = processLineOfSight ( x, y+t, z+t, x, y+t, z-t ) --rx = toang( math.deg( math.atan2(t,t-z1) ) ) --outputChatBox("ang=" .. rx ) elseif(name == "zd") then rx, ry, rz = 180, 0, 0 end return rx, ry, rz end function getPointNormal(x, y, z) local rx, ry, rz = 0, 0, 0 if lowHitCheck(x,y,z,"zu") then rx, ry, rz = lowHitGetNormal(x,y,z,"zu") elseif lowHitCheck(x,y,z,"zd") then rx, ry, rz = lowHitGetNormal(x,y,z,"zd") elseif lowHitCheck(x,y,z,"xu") then rx, ry, rz = lowHitGetNormal(x,y,z,"xu") elseif lowHitCheck(x,y,z,"xd") then rx, ry, rz = lowHitGetNormal(x,y,z,"xd") elseif lowHitCheck(x,y,z,"yu") then rx, ry, rz = lowHitGetNormal(x,y,z,"yu") elseif lowHitCheck(x,y,z,"yd") then rx, ry, rz = lowHitGetNormal(x,y,z,"yd") end return rx, ry, rz end function getNormalPlane3(x1,y1,z1,x2,y2,z2,x3,y3,z3) end function onCreateMine( x, y, z ) local rx,ry,rz = getPointNormal ( x, y, z ) local mine = createObject ( 1213, x, y, z ) if(getDistanceBetweenPoints3D ( x, y, z, getElementPosition(getLocalPlayer())) <= 10 ) then local sound = playSound3D ( "plant.wav", getElementPosition(mine) ) setSoundMaxDistance ( sound, 10 ) end setObjectStatic ( mine, true ) table.insert ( g_Mines, mine ) setElementRotation ( mine, rx, ry, rz ) end addEvent( "onCreateMine", true ) addEventHandler( "onCreateMine", getRootElement(), onCreateMine ) Link to comment
Castillo Posted November 30, 2011 Share Posted November 30, 2011 I don't understand what do you mean, could you explain yourself better? Link to comment
joedajoester Posted November 30, 2011 Author Share Posted November 30, 2011 Instead of ingame useing the script, can the script have it set automatically? So i dont have to manually do it every time Link to comment
joedajoester Posted November 30, 2011 Author Share Posted November 30, 2011 I need the script to start up with the lasers automatically created Link to comment
Castillo Posted November 30, 2011 Share Posted November 30, 2011 You mean already planted "mines"? Link to comment
joedajoester Posted November 30, 2011 Author Share Posted November 30, 2011 Ahh i need the script to start with mines allready made the way from the script and when someone walks in it it will do something like explosion somewhere or setposition somewhere else i need it so i can define where it will create the "mines" theyre called mines but they are kinda lasers try the script ull know wat i mean Link to comment
Castillo Posted November 30, 2011 Share Posted November 30, 2011 If you want to create mines automatically, then I suggest you to use map files for it, is really easy to manage them after that. Link to comment
joedajoester Posted November 30, 2011 Author Share Posted November 30, 2011 It uses dxdraw and I cant do that with Map. Can you make the script automatically startup with a few mines made like to guard an admin base and the script automatically has the mines in place Link to comment
Castillo Posted November 30, 2011 Share Posted November 30, 2011 If you haven't noticed the script uses a trigger to create the mine: triggerServerEvent ( "onCreateMine", getRootElement(), x, y, z ) You just have to create a map file with X, Y, Z as data and then a simple function to load them all and create the mines. 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