Advertisement
qaisjp

c_core : awesomeufo 2.4

Sep 24th, 2011
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.72 KB | None | 0 0
  1. --[[
  2.     This resource has been created by qaisjp
  3.     Find more epic resources at www.code.google.com/p/mta-freeroamplus
  4.     Please give me credit!
  5. ]]
  6.  
  7. local function iif(a,b,c) if a then return b else return c end return nil end
  8. local me, ufo, realufo = getLocalPlayer(), getElementByID("ufo"), getElementByID("realufo")
  9. local data = {mapShown=false}
  10.  
  11. local sW, sH = guiGetScreenSize()
  12. local mapSize = iif((sH - 100)>=600, 600, sH - 100)
  13. local mapX = (sW / 2) - (mapSize / 2)
  14. local mapY = (sH / 2) - (mapSize / 2)
  15.  
  16. function tse(st,...)
  17.     local args = {...}
  18.     triggerServerEvent(st, root, unpack(args))
  19. end
  20.  
  21. function createEvent(str, hand, func)
  22.     addEvent(str, true)
  23.     addEventHandler(str, hand, func)
  24. end
  25. --[[
  26.  
  27. addEventHandler("onClientGUIClick", button_fun, toggleFunWindow, false) opens the fun stuff. we will have a gridlist attch to btn
  28. addEventHandler("onClientGUIClick", button_map, mapUfoInit, false) warp to map
  29.  
  30. triggerServerEvent("ufo:dirHeight", root,tonumber(theHeight))
  31. addEventHandler("onClientGUIClick", button_quickmap_go,
  32. function()
  33.     pointX = tonumber( guiGetText(edit_coord) )
  34.     pointY = tonumber( guiGetText(edit_coord_2))
  35.     speed = guiGetText(edit_speed)
  36.     superSpeed = speed * 1000
  37.     z = "nothing"
  38.     if speed and pointX then
  39.         tse("ufo:moveEvent", tonumber(pointX), tonumber(pointY), z, true, tonumber(superSpeed))
  40.     end
  41. end
  42. , false)
  43.       bla bla notes here bla bla bla bla
  44.  
  45. height_up, function() triggerServerEvent("ufoHeight", root, 3) end, false)
  46. height_down, function() triggerServerEvent("ufoHeight", root, -3) end, false)
  47. movement_stop, function() triggerServerEvent("ufoStop", root) end, false)
  48. LS, function() triggerServerEvent("ufo:move2Loc", root, 835.6, -2086, 500) end, false)
  49. SF, function() triggerServerEvent("ufo:move2Loc", root, -1357.7, 532.4, 500) end, false)
  50. LV, function() triggerServerEvent("ufo:move2Loc", root, 2415, 507, 500) end, false)
  51. nw, function() triggerServerEvent("ufo:moveEvent", root, -160, 160, 0) end, false)
  52. n, function() triggerServerEvent("ufo:moveEvent", root, 0, 160, 0) end, false)
  53. ne, function() triggerServerEvent("ufo:moveEvent", root, 160, 160, 0) end, false)
  54. e, function() triggerServerEvent("ufo:moveEvent", root, 160, 0, 0) end, false)
  55. se, function() triggerServerEvent("ufo:moveEvent", root, 160, -160, 0) end, false)
  56. s, function() triggerServerEvent("ufo:moveEvent", root, 0, -160, 0) end, false)
  57. sw, function() triggerServerEvent("ufo:moveEvent", root, -160, -160, 0) end, false)
  58. w, function() triggerServerEvent("ufo:moveEvent", root, -160, 0, 0) end, false)
  59. rot_45nw, function() triggerServerEvent("ufo:rotateUfo", root, 0, 0, 45) end, false)
  60. rot_45ne, function() triggerServerEvent("ufo:rotateUfo", root, 0, 0, -45) end, false)
  61. rot_90ne, function() triggerServerEvent("ufo:rotateUfo", root, 0, 0, -90) end, false)
  62. rot_90nw, function() triggerServerEvent("ufo:rotateUfo", root, 0, 0, 90) end, false)]]
  63.  
  64. local guiContainer  = {}
  65.  
  66. local extraOptions = {scrolling=true}
  67.  
  68. function getControl(child)
  69.     return guiContainer[child]
  70. end
  71.  
  72. function mouseToggle()
  73.     showCursor(not isCursorShowing())
  74. end
  75.  
  76. function bool2col(bool)
  77.     if bool then
  78.         return 0,255,0
  79.     end
  80.     return 255,0,0
  81. end
  82.    
  83. -------------------
  84. --///////////////--
  85. -------------------
  86. local function handleScroll(type)
  87.     if not extraOptions.scrolling then return end
  88.     type = type:gsub("mouse_wheel_", "")
  89.     if (not getKeyState("lshift") and not getKeyState("lalt")) then -- if both keys pressed or none
  90.         type = type=="up" and 1 or -1
  91.     elseif getKeyState("lshift") and not getKeyState("lalt") then
  92.         type = type=="up" and 1.5 or -1.5
  93.     elseif getKeyState("lalt") and not getKeyState("lshift") then
  94.         type = type=="up" and 0.5 or -0.5
  95.     end
  96.     local x,y,z = getElementPosition(ufo)
  97.     setElementPosition(ufo, x,y,z+type)
  98. end
  99. local function doSlidingExtras(btn,st)
  100.     if btn ~= "left" and st ~= "down" then return end
  101.     st = getElementData(source, "shown")
  102.     guiSetText(source, ((st and "Show") or "Hide").." Extras")
  103.     if st then
  104.         -- do the sliding off
  105.         guiSetVisible(getControl("extragrid"), false)
  106.         ---
  107.         guiSetPosition(getControl("mapaccess"), 0.7825, 0.21, true)
  108.         guiSetPosition(getControl("pref"), 0.7825, 0.285, true)
  109.     else
  110.         -- do the sliding in
  111.         guiSetVisible(getControl("extragrid"), true)
  112.         --
  113.         guiSetPosition(getControl("mapaccess"), 0.7825, 0.54, true)
  114.         guiSetPosition(getControl("pref"), 0.7825, 0.6133, true)
  115.     end
  116.     setElementData(source, "shown", not st)
  117. end
  118.  
  119. function extrasSelection()
  120.     local row = guiGridListGetSelectedItem(getControl("extragrid"))
  121.     if row==-1 then return end
  122.     local text = guiGridListGetItemText(getControl("extragrid"), row, 1)
  123.     if text == "Scroll Movement" then
  124.         extraOptions.scrolling = not extraOptions.scrolling
  125.         guiGridListSetItemColor(getControl("extragrid"), 2, 1, bool2col(extraOptions.scrolling))
  126.     elseif text == "Nuke!" then
  127.         tse("zapUFO")
  128.     end
  129. end
  130.  
  131. function installExtras()
  132.     --[[local features = {"World Collide", "Scroll Movement", "Nuke!", "Classic Controller", "Height", "Coordinates", "Follow"}
  133.     for i,v in ipairs(features) do
  134.         guiGridListSetItemText(getControl("extragrid"), i, 1, v, false, false)
  135.     end]]-- More optimised, but i should build this with performance not in mind and jst get the stff working. then optimise
  136.    
  137.     --[[ Colour codes:
  138.      -RED/GREEN = Boolean.
  139.      -CYAN = Action.
  140.      -YELLOW = Window.
  141.     --]]
  142.    
  143.     guiGridListSetItemText(getControl("extragrid"), 1, 1, "World Collide", false, false)
  144.     guiGridListSetItemColor(getControl("extragrid"), 1, 1, bool2col(false))
  145.    
  146.     guiGridListSetItemText(getControl("extragrid"), 2, 1, "Scroll Movement", false, false)
  147.     guiGridListSetItemColor(getControl("extragrid"), 2, 1, bool2col(true))
  148.    
  149.     guiGridListSetItemText(getControl("extragrid"), 3, 1, "Nuke!", false, false)
  150.     guiGridListSetItemColor(getControl("extragrid"), 3, 1, 0,255,255)
  151.    
  152.     guiGridListSetItemText(getControl("extragrid"), 4, 1, "Classic Controller", false, false)
  153.     guiGridListSetItemColor(getControl("extragrid"), 4, 1, 255,255,0)
  154.    
  155.     guiGridListSetItemText(getControl("extragrid"), 5, 1, "Height", false, false)
  156.     guiGridListSetItemColor(getControl("extragrid"), 5, 1, 255,255,0)
  157.    
  158.     guiGridListSetItemText(getControl("extragrid"), 6, 1, "Coordinates", false, false)
  159.     guiGridListSetItemColor(getControl("extragrid"), 6, 1, 255,255,0)
  160.    
  161.     guiGridListSetItemText(getControl("extragrid"), 7, 1, "Follow", false, false)
  162.     guiGridListSetItemColor(getControl("extragrid"), 7, 1, 255,255,0)
  163.    
  164.     addEventHandler("onClientGUIClick", getControl("showextras"), doSlidingExtras)
  165.     addEventHandler("onClientGUIDoubleClick", getControl("extragrid"), extrasSelection)
  166.    
  167. end
  168. function initUfoWnd(btn,st)
  169.     if btn~="left" and st~="down" then return end
  170.     if data.mapShown == false then
  171.         addEventHandler("onClientRender", root, drawUfoMap)
  172.         data.mapShown = true
  173.         setTimer(
  174.             function()
  175.                 addEventHandler("onClientClick", root, ufoSpawn)
  176.             end
  177.         , 1000, 1)
  178.     else
  179.         removeEventHandler("onClientRender", root, drawUfoMap)
  180.         removeEventHandler("onClientClick", root, ufoSpawn)
  181.         data.mapShown = false
  182.     end
  183. end
  184. -------------------
  185. --///////////////--
  186. -------------------
  187. function showMenu()
  188.     if data.enabled then return end
  189.     toggleControl("enter_exit", false)
  190.     bindKey("f", "down", mouseToggle)
  191.     bindKey("mouse_wheel_up", "both", handleScroll)
  192.     bindKey("mouse_wheel_down", "both", handleScroll)
  193.     showCursor(true)
  194.     local additions = {"stopedit", "showextras", "extragrid", "mapaccess", "pref"}
  195.     for i,v in ipairs(additions) do
  196.         local gui = getControl(v)
  197.         guiSetVisible(gui, true)
  198.     end
  199.     data.enabled = true
  200. end
  201.  
  202. addCommandHandler("ufo", showMenu)
  203.  
  204. function hideMenu()
  205.     data.enabled = false
  206.     local additions = {"stopedit", "showextras", "extragrid", "mapaccess", "pref"}
  207.     for i,v in ipairs(additions) do
  208.         local gui = getControl(v)
  209.         guiSetVisible(gui, false)
  210.     end
  211.     showCursor(false)
  212.     toggleControl("enter_exit", true)
  213.     unbindKey("f", "down", mouseToggle)
  214.     unbindKey("mouse_wheel_up", "both", handleScroll)
  215.     unbindKey("mouse_wheel_down", "both", handleScroll)
  216.     setCameraTarget(me)
  217. end
  218. -------------------
  219. --///////////////--: Create the main screen objects
  220. -------------------
  221.  
  222. -- Leave movement mode
  223. guiContainer["stopedit"] = guiCreateButton(0.7825,0.0583,0.205,0.0617,"Stop Editing",true)
  224. addEventHandler("onClientGUIClick", getControl("stopedit"), hideMenu)
  225.  
  226. -- Create the extras menu, to do is sliding the extras gridlist up and down to toggle showing, also moving the btns below it.
  227. guiContainer["showextras"] = guiCreateButton(0.7825,0.135,0.205,0.0617,"Hide Extras",true)
  228. guiSetProperty(getControl("showextras"),"AlwaysOnTop","True")
  229. setElementData(getControl("showextras"), "shown", true)
  230.  
  231. guiContainer["extragrid"] = guiCreateGridList(0.7825,0.155,0.205,0.37,true)
  232. guiGridListSetSelectionMode(getControl("extragrid"),2)
  233. guiSetProperty(getControl("extragrid"),"ZOrderChangeEnabled","False")
  234. guiGridListAddColumn(getControl("extragrid"),"",1)
  235. guiSetVisible(getControl("extragrid"), false)
  236.  
  237. setTimer(installExtras, 75, 1) -- This installs the "extras" gridlist+button for interactive use.
  238. --
  239.  
  240. guiContainer["mapaccess"] = guiCreateButton(0.7825,0.54,0.205,0.0617,"Quick Map",true)
  241. addEventHandler("onClientGUIClick", getControl("mapaccess"), initUfoWnd)
  242.  
  243. guiContainer["pref"] = guiCreateButton(0.7825,0.6133,0.205,0.0617,"Preferences",true)
  244.  
  245. for i = 0, 7 do
  246.     guiGridListAddRow(getControl("extragrid"))
  247. end
  248.  
  249. -------------------
  250. --///////////////--
  251. -------------------
  252.  
  253. for i,v in pairs(guiContainer) do
  254.     guiSetVisible(v, false)
  255. end
  256.  
  257. -------------------
  258. --///////////////--
  259. -------------------
  260. --[[do -- This contains content from the freecam resource and has been editied by karlis, so thanks to him.
  261.      TO DO LIST:
  262.         When moving forward, the ufo will move forward. Only forward is supported (W)
  263.         Cursor look-at direction changes the rotation of the ufo.
  264.         So when moving the ufo will always move forward, but in the camera lookat direction
  265.    
  266.        
  267.     local zoom=100 --how far is camera target from elem
  268.     local rotX, rotY = 0,0
  269.     local ratio = 3 --how many times distance from camera to player is smaller then distance from player to camera target
  270.     local width, height = guiGetScreenSize()
  271.     local hit
  272.      
  273.     --heavily modified freecam resource's core
  274.     function freecamFrame()
  275.         local cameraAngleX = rotX
  276.         local cameraAngleY = rotY
  277.         local freeModeAngleZ = math.sin(cameraAngleY)
  278.         local freeModeAngleY = math.cos(cameraAngleY) * math.cos(cameraAngleX)
  279.         local freeModeAngleX = math.cos(cameraAngleY) * math.sin(cameraAngleX)
  280.         local camPosX, camPosY, camPosZ = getElementPosition(ufo)
  281.         -- calculate a target based on the current position and an offset based on the angle
  282.         local camTargetX = camPosX + freeModeAngleX * zoom
  283.         local camTargetY = camPosY + freeModeAngleY * zoom
  284.         local camTargetZ = camPosZ + freeModeAngleZ * zoom
  285.         local camPosX = camPosX - ( camTargetX - camPosX ) / ratio
  286.         local camPosY = camPosY - ( camTargetY - camPosY ) / ratio
  287.         local camPosZ = camPosZ - ( camTargetZ - camPosZ ) / ratio
  288.         if not isLineOfSightClear(camPosX,camPosY,camPosZ,camPosX,camPosY,camPosZ,true,true,true,true,false,true,false,me) then
  289.             _,camPosX,camPosY,camPosZ=processLineOfSight(camTempPosX,camTempPosY,camPosZ,camPosX,camPosY,camPosZ,true,true,true,true,false,true,false,false,localPlayer)
  290.             camPosX,camPosY,camPosZ=camPosX-(camTempPosX-camPosX)*0.1,camPosY-(camTempPosY-camPosY)*0.1,camPosZ-(camTempPosZ-camPosZ)*0.1
  291.         end
  292.         -- Set the new camera position and target
  293.         setCameraMatrix ( camPosX, camPosY, camPosZ, camTargetX, camTargetY, camTargetZ )
  294.     end
  295. end]]
  296.  
  297. -- state variables
  298. local speed = 0
  299. local strafespeed = 0
  300. local rotX, rotY = 0,0
  301. local velocityX, velocityY, velocityZ
  302.  
  303. -- configurable parameters
  304. local options = {
  305.     invertMouseLook = false,
  306.     normalMaxSpeed = 1,
  307.     slowMaxSpeed = 0.2,
  308.     fastMaxSpeed = 9,
  309.     smoothMovement = true,
  310.     acceleration = 0.3,
  311.     decceleration = 0.15,
  312.     mouseSensitivity = 0.3,
  313.     maxYAngle = 188,
  314.     key_fastMove = "lshift",
  315.     key_slowMove = "lalt",
  316.     key_forward = "w",
  317.     zoom = 100,
  318.     ratio = 3, --how many times distance from camera to player is smaller then distance from player to camera target
  319. }
  320.  
  321. local mouseFrameDelay = 0
  322. local getKeyState = getKeyState
  323. do
  324.     local mta_getKeyState = getKeyState
  325.     function getKeyState(key)
  326.         if isMTAWindowActive() or isCursorShowing()then
  327.             return false
  328.         else
  329.             return mta_getKeyState(key)
  330.         end
  331.     end
  332. end
  333.  
  334. -- PRIVATE
  335.  
  336. local function freecamFrame ()
  337.     if not data.enabled then return end
  338.        
  339.         if getKeyState(options.key_fastMove) then
  340.             options.mouseSensitivity = 0.7
  341.         elseif getKeyState(options.key_slowMove) then
  342.             options.mouseSensitivity = 0.1
  343.         else
  344.             options.mouseSensitivity = 0.3
  345.         end
  346.        
  347.         do
  348.             local additions = {"stopedit", "showextras", "extragrid", "mapaccess", "pref"}
  349.             for i,v in ipairs(additions) do
  350.                 local gui, show = getControl(v), isCursorShowing()
  351.                 guiSetAlpha(gui, show and 1 or 0.9)
  352.                 guiSetEnabled(gui, show)
  353.             end
  354.         end
  355.        
  356.         setElementPosition(getPedOccupiedVehicle(me) or me, getElementPosition(ufo))
  357.        
  358.     -- work out an angle in radians based on the number of pixels the cursor has moved (ever)
  359.     local cameraAngleX = rotX
  360.     local cameraAngleY = rotY
  361.  
  362.     local freeModeAngleZ = math.sin(cameraAngleY)
  363.     local freeModeAngleY = math.cos(cameraAngleY) * math.cos(cameraAngleX)
  364.     local freeModeAngleX = math.cos(cameraAngleY) * math.sin(cameraAngleX)
  365.     local camPosX, camPosY, camPosZ = getElementPosition(realufo)--getCameraMatrix()
  366.     camPosZ = camPosZ-8 -- This is to not interfere with the offsets of the attach.
  367.  
  368.     -- calculate a target based on the current position and an offset based on the angle
  369.     local camTargetX = camPosX + freeModeAngleX * options.zoom
  370.     local camTargetY = camPosY + freeModeAngleY * options.zoom
  371.     local camTargetZ = camPosZ + freeModeAngleZ * options.zoom
  372.  
  373.     -- Calculate what the maximum speed that the camera should be able to move at.
  374.     local mspeed = options.normalMaxSpeed
  375.     if getKeyState(options.key_fastMove) then
  376.         mspeed = options.fastMaxSpeed
  377.     elseif getKeyState(options.key_slowMove) then
  378.         mspeed = options.slowMaxSpeed
  379.     end
  380.    
  381.     if options.smoothMovement then
  382.         local acceleration = options.acceleration
  383.         local decceleration = options.decceleration
  384.    
  385.         -- Check to see if the forwards/backwards keys are pressed
  386.         local speedKeyPressed = false
  387.         if getKeyState ( options.key_forward ) then
  388.             speed = speed + acceleration
  389.             speedKeyPressed = true
  390.         end
  391.  
  392.         -- Check to see if the strafe keys are pressed
  393.         -- If no forwards/backwards keys were pressed, then gradually slow down the movement towards 0
  394.         if speedKeyPressed ~= true then
  395.             if speed > 0 then
  396.                 speed = speed - decceleration
  397.             elseif speed < 0 then
  398.                 speed = speed + decceleration
  399.             end
  400.         end
  401.  
  402.         -- Check the ranges of values - set the speed to 0 if its very close to 0 (stops jittering), and limit to the maximum speed
  403.         if speed > -decceleration and speed < decceleration then
  404.             speed = 0
  405.         elseif speed > mspeed then
  406.             speed = mspeed
  407.         elseif speed < -mspeed then
  408.             speed = -mspeed
  409.         end
  410.      
  411.         if strafespeed > -(acceleration / 2) and strafespeed < (acceleration / 2) then
  412.             strafespeed = 0
  413.         elseif strafespeed > mspeed then
  414.             strafespeed = mspeed
  415.         elseif strafespeed < -mspeed then
  416.             strafespeed = -mspeed
  417.         end
  418.     else
  419.         speed = 0
  420.         strafespeed = 0
  421.         if getKeyState ( options.key_forward ) then speed = mspeed end
  422.     end
  423.  
  424.     -- Work out the distance between the target and the camera (should be 100 units)
  425.     local camAngleX = camPosX - camTargetX
  426.     local camAngleY = camPosY - camTargetY
  427.     local camAngleZ = 0 -- we ignore this otherwise our vertical angle affects how fast you can strafe
  428.  
  429.     -- Calulcate the length of the vector
  430.     local angleLength = math.sqrt(camAngleX*camAngleX+camAngleY*camAngleY+camAngleZ*camAngleZ)
  431.  
  432.     -- Normalize the vector, ignoring the Z axis, as the camera is stuck to the XY plane (it can't roll)
  433.     local camNormalizedAngleX = camAngleX / angleLength
  434.     local camNormalizedAngleY = camAngleY / angleLength
  435.     local camNormalizedAngleZ = 0
  436.  
  437.     -- We use this as our rotation vector
  438.     local normalAngleX = 0
  439.     local normalAngleY = 0
  440.     local normalAngleZ = 1
  441.  
  442.     -- Perform a cross product with the rotation vector and the normalzied angle
  443.     local normalX = (camNormalizedAngleY * normalAngleZ - camNormalizedAngleZ * normalAngleY)
  444.     local normalY = (camNormalizedAngleZ * normalAngleX - camNormalizedAngleX * normalAngleZ)
  445.     local normalZ = (camNormalizedAngleX * normalAngleY - camNormalizedAngleY * normalAngleX)
  446.  
  447.     -- Update the camera position based on the forwards/backwards speed
  448.     camPosX = camPosX + freeModeAngleX * speed
  449.     camPosY = camPosY + freeModeAngleY * speed
  450.  
  451.     -- Update the camera position based on the strafe speed
  452.     camPosX = camPosX + normalX * strafespeed
  453.     camPosY = camPosY + normalY * strafespeed
  454.    
  455.     --local cameraPosX = camPosX - ( camTargetX - camPosX ) / ratio
  456.     --local cameraPosY = camPosY - ( camTargetY - camPosY ) / ratio
  457.     local cameraPosZ = (camPosZ+8) - ( camTargetZ - (camPosZ+8) ) / options.ratio
  458.    
  459.     --Store the velocity
  460.     velocityX = (freeModeAngleX * speed) + (normalX * strafespeed)
  461.     velocityY = (freeModeAngleY * speed) + (normalY * strafespeed)
  462.     velocityZ = (freeModeAngleZ * speed) + (normalZ * strafespeed)
  463.  
  464.     -- Update the target based on the new camera position (again, otherwise the camera kind of sways as the target is out by a frame)
  465.     camTargetX = camPosX + freeModeAngleX * 100
  466.     camTargetY = camPosY + freeModeAngleY * 100
  467.     camTargetZ = camPosZ + freeModeAngleZ * 100
  468.  
  469.     -- Set the new camera position and target
  470.     local _,_,ufoZ = getElementPosition(ufo)
  471.     setCameraMatrix ( camPosX, camPosY, cameraPosZ, camTargetX, camTargetY, camTargetZ )
  472.     setElementPosition(ufo, camPosX, camPosY, ufoZ)
  473.     setElementRotation(ufo, 0,0, math.deg(-rotX))
  474. end
  475.  
  476. local function freecamMouse (cX,cY,aX,aY)
  477.     --ignore mouse movement if the cursor or MTA window is on
  478.     --and do not resume it until at least 5 frames after it is toggled off
  479.     --(prevents cursor mousemove data from reaching this handler)
  480.     if not data.enabled then return end
  481.     if isCursorShowing() or isMTAWindowActive() then
  482.         mouseFrameDelay = 5
  483.         return
  484.     elseif mouseFrameDelay > 0 then
  485.         mouseFrameDelay = mouseFrameDelay - 1
  486.         return
  487.     end
  488.    
  489.     -- how far have we moved the mouse from the screen center?
  490.     local width, height = guiGetScreenSize()
  491.     aX = aX - width / 2
  492.     aY = aY - height / 2
  493.    
  494.     --invert the mouse look if specified
  495.     if options.invertMouseLook then
  496.         aY = -aY
  497.     end
  498.    
  499.     rotX = rotX + aX * options.mouseSensitivity * 0.01745
  500.     rotY = rotY - aY * options.mouseSensitivity * 0.01745
  501.    
  502.     local PI = math.pi
  503.     if rotX > PI then
  504.         rotX = rotX - 2 * PI
  505.     elseif rotX < -PI then
  506.         rotX = rotX + 2 * PI
  507.     end
  508.    
  509.     if rotY > PI then
  510.         rotY = rotY - 2 * PI
  511.     elseif rotY < -PI then
  512.         rotY = rotY + 2 * PI
  513.     end
  514.     -- limit the camera to stop it going too far up or down - PI/2 is the limit, but we can't let it quite reach that or it will lock up
  515.     -- and strafeing will break entirely as the camera loses any concept of what is 'up'
  516.     if rotY < -PI / 2.05 then
  517.        rotY = -PI / 2.05
  518.     elseif rotY > PI / 2.05 then
  519.         rotY = PI / 2.05
  520.     end
  521. end
  522. addEventHandler("onClientRender", root, freecamFrame)
  523. addEventHandler("onClientCursorMove", root, freecamMouse)
  524.  
  525. -------------------
  526. ----- UFO MAP -----
  527. -------------------
  528. function drawUfoMap()
  529.     data.mapShown = true
  530.     dxDrawRectangle((sW / 2) - ((mapSize / 2) + 4), (sH / 2) - ((mapSize / 2) + 4), (mapSize + 8), (mapSize + 8), tocolor(0, 0, 0, 128), false)
  531.  
  532.     -- Draw the map.
  533.     dxDrawImage(mapX, mapY, mapSize, mapSize, "map.jpg", 0, 0, 0, tocolor(255, 255, 255, 255), true)
  534.  
  535.     dxDrawText("Click on a location", 2, 12, sW, dxGetFontHeight(1, "bankgothic"), tocolor(0, 0, 0, 128), 1, "bankgothic", "center", "top", false, false, true)
  536.     dxDrawText("Click on a location", 0, 10, sW - 2, dxGetFontHeight(1, "bankgothic"), tocolor(255, 255, 255, 255), 1, "bankgothic", "center", "top", false, false, true)
  537.  
  538.     local px, py, wx, wy, wz = getCursorPosition()
  539.        
  540.     px = math.floor(px * sW)
  541.     py = math.floor(py * sH)
  542.        
  543.     if (px >= mapX and py >= mapY and px <= (mapX + mapSize) and py <= (mapY + mapSize)) then
  544.         px = px - mapX
  545.         py = py - mapY
  546.        
  547.         px = (6000 / mapSize) * px
  548.         py = (6000 / mapSize) * py
  549.         px = px - 3000
  550.         py = 3000 - py
  551.        
  552.         local zoneName = getZoneName(px, py, 0, false)
  553.         dxDrawText(zoneName, 2, sH - 40, sW, dxGetFontHeight(1, "bankgothic"), tocolor(0, 0, 0, 128), 1, "bankgothic", "center", "top", false, false, true)
  554.         dxDrawText(zoneName, 0, sH - 42, sW - 2, dxGetFontHeight(1, "bankgothic"), tocolor(255, 255, 255, 255), 1, "bankgothic", "center", "top", false, false, true)
  555.     end
  556. end
  557.  
  558. function ufoSpawn(button, state, px, py)
  559.     if data.mapShown then
  560.         removeEventHandler("onClientRender", root, drawUfoMap)
  561.         removeEventHandler("onClientClick", root, ufoSpawn)
  562.         data.mapShown = false
  563.  
  564.         if (px >= mapX and py >= mapY and px <= (mapX + mapSize) and py <= (mapY + mapSize)) then
  565.             px = px - mapX
  566.             py = py - mapY
  567.            
  568.             px = (6000 / mapSize) * px
  569.             py = (6000 / mapSize) * py
  570.             px = px - 3000
  571.             py = 3000 - py
  572.  
  573.             --guiSetText(edit_coord, tostring(px))
  574.             --guiSetText(edit_coord_2, tostring(py))
  575.             outputChatBox("x: "..px.." y: "..py)
  576.         end
  577.     end
  578. end
  579.  
  580. --///////////////////////////////////////--
  581. --// Super weapons - Nuke - By Ransom ///--
  582. --///////////////////////////////////////--
  583. local N_loops = 0
  584. local N_cloudRotationAngle = 0  
  585. local NFlashDelay = 0
  586. local stopNFlash = false  
  587.  
  588. function FireN ( x, y, z )
  589.     NBeaconX = x --these are for the render function
  590.     NBeaconY = y
  591.     NBeaconZ = z
  592.     N_Cloud = NBeaconZ 
  593.     setTimer ( function() setTimer ( NExplosion, 170, 35 ) end, 2700, 1 ) -- wait 2700 seconds then 35 loops @ 170ms
  594.     setTimer ( NShot, 500, 1 ) 
  595. end
  596. createEvent("ufo:ClientFireN", root, FireN)
  597.  
  598. function NShot ()
  599.     NukeObjectA = createObject ( 16340, NBeaconX, NBeaconY, NBeaconZ - 0.5 )
  600.     NukeObjectB = createObject ( 3865, NBeaconX + 0.072265, NBeaconY + 0.013731, NBeaconZ + 196.153122 )
  601.     NukeObjectC = createObject ( 1243, NBeaconX + 0.060547, NBeaconY - 0.017578, NBeaconZ + 189.075554 )
  602.     setElementRotation ( NukeObjectA, math.deg(3.150001), math.deg(0), math.deg(0.245437) )
  603.     setElementRotation ( NukeObjectB, math.deg(-1.575), math.deg(0), math.deg(1.938950) )
  604.     setElementRotation ( NukeObjectC, math.deg(0), math.deg(0), math.deg(-1.767145) )
  605.     shotpath = NBeaconZ - 200
  606.     moveObject ( NukeObjectA, 5000, NBeaconX, NBeaconY, shotpath, 0, 0, 259.9 )
  607.     moveObject ( NukeObjectB, 5000, NBeaconX + 0.072265, NBeaconY + 0.013731, shotpath - 3.846878, 0, 0, 259.9 )
  608.     moveObject ( NukeObjectC, 5000, NBeaconX + 0.060547, NBeaconY - 0.017578, shotpath - 10.924446, 0, 0, 259.9 )
  609. end
  610.  
  611. function NExplosion ()
  612.     N_loops = N_loops + 1  
  613.     r = math.random(1.5, 4.5)
  614.     angleup = math.random(0, 35999)/100
  615.     explosionXCoord = r*math.cos(angleup) + NBeaconX
  616.     ExplosionYCoord = r*math.sin(angleup) + NBeaconY   
  617.     if N_loops == 1 then
  618.         N_Cloud = NBeaconZ
  619.         createExplosion ( explosionXCoord, ExplosionYCoord, N_Cloud, 7 )
  620.         killXPosRadius = NBeaconX + 35
  621.         killXNegRadius = NBeaconX - 35
  622.         killYPosRadius = NBeaconY + 35
  623.         killYNegRadius = NBeaconY - 35 --+/- 35 x/y
  624.         killZPosRadius = NBeaconZ + 28-- +28
  625.         killZNegRadius = NBeaconZ - 28-- -28
  626.         local x, y, z = getElementPosition ( me )
  627.         if ( x < killXPosRadius ) and ( x > killXNegRadius ) and ( y < killYPosRadius ) and ( y > killYNegRadius ) and
  628.         ( z < killZPosRadius ) and ( z > killZNegRadius ) then
  629.             triggerServerEvent ( "ufo:serverKillNukedPlayer", me )
  630.         end
  631.     elseif N_loops == 2 then
  632.         N_Cloud = NBeaconZ + 4
  633.         createExplosion ( explosionXCoord, ExplosionYCoord, N_Cloud, 7 )
  634.         destroyElement ( NukeObjectA ) --Exploded, get rid of objects
  635.         destroyElement ( NukeObjectB )
  636.         destroyElement ( NukeObjectC )
  637.     elseif N_loops > 20 then
  638.         N_cloudRotationAngle = N_cloudRotationAngle + 22.5
  639.         if N_explosionLimiter == false then
  640.             N_cloudRadius = 7
  641.             explosionXCoord = N_cloudRadius*math.cos(N_cloudRotationAngle) + NBeaconX --recalculate
  642.             ExplosionYCoord = N_cloudRadius*math.sin(N_cloudRotationAngle) + NBeaconY --recalculate
  643.             createExplosion ( explosionXCoord, ExplosionYCoord, N_Cloud, 7 )
  644.             N_explosionLimiter = true
  645.         elseif N_explosionLimiter == true then
  646.             N_explosionLimiter = false
  647.         end
  648.         N_cloudRadius2 = 16
  649.         explosionXCoord2 = N_cloudRadius2*math.cos(N_cloudRotationAngle) + NBeaconX
  650.         ExplosionYCoord2 = N_cloudRadius2*math.sin(N_cloudRotationAngle) + NBeaconY
  651.         createExplosion ( explosionXCoord2, ExplosionYCoord2, N_Cloud, 7 )
  652.     else
  653.         N_Cloud = N_Cloud + 4
  654.         createExplosion ( explosionXCoord, ExplosionYCoord, N_Cloud, 7 )
  655.     end
  656.    
  657.     if N_loops == 1 then
  658.         NExplosionFlash = createMarker ( NBeaconX, NBeaconY, NBeaconZ, "corona", 0, 255, 255, 255, 255 )
  659.         N_FlashSize = 1
  660.         addEventHandler ( "onClientRender", root, NFlash )
  661.     elseif N_loops == 35 then
  662.         stopNFlash = true      
  663.     end
  664. end
  665.  
  666. function NFlash() --Corona "flare". Grows after cp marker B grows a little
  667.     if ( stopNFlash == false ) then
  668.             if N_FlashSize > 60 then --beginning flash must grow fast, then delayed
  669.                 if NFlashDelay == 2 then
  670.                     N_FlashSize = N_FlashSize + 1
  671.                     NFlashDelay = 0
  672.                 else   
  673.                     NFlashDelay = NFlashDelay + 1                                  
  674.                 end  
  675.             else
  676.                 N_FlashSize = N_FlashSize + 1          
  677.             end                      
  678.     else
  679.         N_FlashSize = N_FlashSize - 1
  680.     end
  681.     setMarkerSize ( NExplosionFlash, N_FlashSize )                 
  682.     if N_FlashSize == 0 then
  683.         removeEventHandler ( "onClientRender", root, NFlash )
  684.         destroyElement ( NExplosionFlash )
  685.         N_loops = 0 --reset stuff
  686.         N_cloudRotationAngle = 0 --reset stuff
  687.         stopNFlash = false --reset stuff
  688.         NFlashDelay = 0 --reset stuff
  689.         tse("ufo:serverNukeFinished")
  690.     end
  691. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement