Advertisement
Noneatme

Untitled

Jul 26th, 2012
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.67 KB | None | 0 0
  1. local gMe = getLocalPlayer()
  2. -- CLAYMORE SCRIPT [C] BY MULTI! YOU ARE NOT ALLOWED TO USE ANYTHING FROM HERE !!! --
  3.  
  4. addEvent("onClaymoreEnable", true)
  5. addEvent("onClientClaymoreGive", true)
  6. addEvent("onClientClaymoreDestroy", true)
  7.  
  8. local enabled = false
  9. local claymore = {}
  10. local cMarker = {}
  11.  
  12. addEventHandler("onClientClick", getRootElement(), function(mouse, state, sx, sy, x, y, z)
  13.     if(mouse == "right") then
  14.         showCursor(false)
  15.        
  16.     return end
  17.     if(mouse == "left") and (state == "down") then
  18.         if(enabled == false) then return end
  19.         if(x) then
  20.             enabled = false
  21.             local object = createObject(1252, x, y, z)
  22.            
  23.             local x1, y1 = getElementPosition(object)
  24.             local x2, y2 = getElementPosition(gMe)
  25.             local rot = math.atan2(y2 - y1, x2 - x1) * 180 / math.pi
  26.            
  27.             setElementRotation(object, 0, 0, rot+90)
  28.            
  29.             local pos = getGroundPosition(x, y, z)
  30.             local dis = getDistanceBetweenPoints3D(x, y, z, x, y, pos)
  31.             local rotx = false
  32.             if(dis > 0) then
  33.                
  34.             else
  35.                 rotx = true
  36.                 setElementRotation(object, 90, 0, rot+90)
  37.             end
  38.             -- POSITION CHANGE --
  39.             local px, py, pz = getElementPosition(object)
  40.             local rx, ry, rz = getElementRotation(object)
  41.            
  42.             rz = rz-180
  43.             local distance = 0.1
  44.             local nx, ny, nz
  45.            
  46.             if(rotx == false) then
  47.                 nx = px + math.cos(math.rad(rz + 90)) * distance
  48.                 ny = py + math.sin(math.rad(rz + 90)) * distance
  49.                 nz = pz
  50.             else
  51.                 nx = px
  52.                 ny = py
  53.                 nz = pz+0.1
  54.             end
  55.             setElementPosition(object, nx, ny, nz)
  56.             local px, py, pz = getElementPosition(object)
  57.             local rx, ry, rz = getElementRotation(object)
  58.             rz = rz-180
  59.             local distance = 70
  60.             local nx, ny, nz
  61.            
  62.             if(rotx == false) then
  63.                 nx = px + math.cos(math.rad(rz + 90)) * distance
  64.                 ny = py + math.sin(math.rad(rz + 90)) * distance
  65.                 nz = pz
  66.             else
  67.                 nx = px
  68.                 ny = py
  69.                 nz = pz+50
  70.             end
  71.            
  72.             local ob2 = createObject(1252, nx, ny, nz)
  73.  
  74.            
  75.             setElementData(object, "ob2", ob2)
  76.        
  77.             local x1, y1, z1 = getElementPosition(object)
  78.             local rotx1, roty1, rotz1 = getElementRotation(object)
  79.             local x2, y2, z2 = getElementPosition(ob2)
  80.            
  81.             destroyElement(object)
  82.             destroyElement(ob2)
  83.             triggerServerEvent("onClaymoreCreate", gMe, x1, y1, z1, rotx1, roty1, rotz1, x2, y2, z2)
  84.             showCursor(false)
  85.         end
  86.     end
  87. end)
  88.  
  89. addEventHandler("onClientRender", getRootElement(), function()
  90.     for _, object in pairs(claymore) do
  91.         local x, y, z = getElementPosition(object)
  92.         local x2, y2, z2 = getElementPosition(getElementData(object, "ob2"))
  93.         local hit, hitx, hity, hitz, hitElement = processLineOfSight(x, y, z, x2, y2, z2, true, true, true)
  94.         if(hitx) then
  95.             dxDrawLine3D(x, y, z, hitx, hity, hitz, tocolor(255, 0, 0, 200), 2)
  96.             if(hit == true) and(hitElement) then
  97.                 if(getElementType(hitElement) == "player") or (getElementType(hitElement) == "vehicle") then
  98.                     if(getElementData(object, "armed") == true) then
  99.                         local frak = getElementData(object, "fraktion")
  100.                         if(frak) then
  101.                             if(frak ~= getElementData(hitElement, "fraktion")) then
  102.                                 setElementData(object, "armed", "explodet")
  103.                                 triggerServerEvent("onClaymoreExplode", gMe, getElementData(object, "id"))
  104.                             else
  105.                                 setMarkerColor(getElementData(object, "attachedMarker"), 0, 200, 0)
  106.                             end
  107.                         end
  108.                     end
  109.                 end
  110.             else
  111.                 local r, g, b = getMarkerColor(getElementData(object, "attachedMarker"))
  112.                 if(g == 255) then
  113.                     setMarkerColor(getElementData(object, "attachedMarker"), 200, 0, 0)
  114.                 end
  115.             end
  116.         else
  117.             dxDrawLine3D(x, y, z, x2, y2, z2, tocolor(255, 0, 0, 200), 2)
  118.         end
  119.     end
  120. end)
  121.  
  122.  
  123. addEventHandler("onClientClaymoreGive", getRootElement(), function(id, object)
  124.     local x, y, z = getElementPosition(object)
  125.     cMarker[id] = createMarker(x, y, z, "corona", 0.8, 0, 255, 0, 150)
  126.     setElementData(object, "attachedMarker", cMarker[id], false)
  127.     attachElements(cMarker[id], object)
  128.     if(getElementData(cMarker[id], "armed") == true) then
  129.         setMarkerColor(cMarker[id], 255, 0, 0, 200)
  130.     else
  131.         setTimer(function()
  132.             if(isElement(cMarker[id])) then
  133.                 setMarkerColor(cMarker[id], 255, 0, 0, 150)
  134.                 local sound = playSound3D("sounds/armed.mp3", x, y, z, false)
  135.                 setSoundMaxDistance(sound, 50)
  136.                 setSoundVolume(sound, 1)
  137.             end
  138.         end, 3000, 1)
  139.     end
  140.     claymore[id] = object
  141. end)
  142.  
  143. addEventHandler("onClaymoreEnable", getRootElement(), function()
  144.     enabled = true
  145.     showCursor(true)
  146. end)
  147.  
  148. addEventHandler("onClientClaymoreDestroy", getRootElement(), function(id)
  149.     claymore[id] = nil
  150.     if(isElement(cMarker[id])) then destroyElement(cMarker[id]) end
  151. end)
  152.  
  153. addEventHandler("onClientResourceStart", getResourceRootElement(), function()
  154.     triggerServerEvent("onClaymoreGet", gMe)
  155. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement