Sorry about the bump but:
Here is the current progress, i will update it whenever I feel like doing so.
client
--[[
This resource has been created by qaisjp
Find more epic resources at [url=http://www.code.google.com/p/mta-freeroamplus]http://www.code.google.com/p/mta-freeroamplus[/url]
Please give me credit!
]]
local function iif(a,b,c) if a then return b else return c end return nil end
local me, ufo = getLocalPlayer(), getElementByID("ufo")
local data = {}
local sW, sH = guiGetScreenSize()
local mapSize = iif((sH - 100)>=600, 600, sH - 100)
local mapX = (sW / 2) - (mapSize / 2)
local mapY = (sH / 2) - (mapSize / 2)
function tse(st,...)
local args = {...}
triggerServerEvent(st, root, unpack(args))
end
function createEvent(str, hand, func)
addEvent(str, true)
addEventHandler(str, hand, func)
end
--[[
addEventHandler("onClientGUIClick", button_fun, toggleFunWindow, false) opens the fun stuff. we will have a gridlist attch to btn
addEventHandler("onClientGUIClick", button_map, mapUfoInit, false) warp to map
triggerServerEvent("ufo:dirHeight", root,tonumber(theHeight))
addEventHandler("onClientGUIClick", button_quickmap_go,
function()
pointX = tonumber( guiGetText(edit_coord) )
pointY = tonumber( guiGetText(edit_coord_2))
speed = guiGetText(edit_speed)
superSpeed = speed * 1000
z = "nothing"
if speed and pointX then
tse("ufo:moveEvent", tonumber(pointX), tonumber(pointY), z, true, tonumber(superSpeed))
end
end
, false)
bla bla notes here bla bla bla bla
height_up, function() triggerServerEvent("ufoHeight", root, 3) end, false)
height_down, function() triggerServerEvent("ufoHeight", root, -3) end, false)
movement_stop, function() triggerServerEvent("ufoStop", root) end, false)
LS, function() triggerServerEvent("ufo:move2Loc", root, 835.6, -2086, 500) end, false)
SF, function() triggerServerEvent("ufo:move2Loc", root, -1357.7, 532.4, 500) end, false)
LV, function() triggerServerEvent("ufo:move2Loc", root, 2415, 507, 500) end, false)
nw, function() triggerServerEvent("ufo:moveEvent", root, -160, 160, 0) end, false)
n, function() triggerServerEvent("ufo:moveEvent", root, 0, 160, 0) end, false)
ne, function() triggerServerEvent("ufo:moveEvent", root, 160, 160, 0) end, false)
e, function() triggerServerEvent("ufo:moveEvent", root, 160, 0, 0) end, false)
se, function() triggerServerEvent("ufo:moveEvent", root, 160, -160, 0) end, false)
s, function() triggerServerEvent("ufo:moveEvent", root, 0, -160, 0) end, false)
sw, function() triggerServerEvent("ufo:moveEvent", root, -160, -160, 0) end, false)
w, function() triggerServerEvent("ufo:moveEvent", root, -160, 0, 0) end, false)
rot_45nw, function() triggerServerEvent("ufo:rotateUfo", root, 0, 0, 45) end, false)
rot_45ne, function() triggerServerEvent("ufo:rotateUfo", root, 0, 0, -45) end, false)
rot_90ne, function() triggerServerEvent("ufo:rotateUfo", root, 0, 0, -90) end, false)
rot_90nw, function() triggerServerEvent("ufo:rotateUfo", root, 0, 0, 90) end, false)]]
local guiContainer = {}
function getControl(child)
return guiContainer[child]
end
function mouseToggle()
showCursor(not isCursorShowing())
end
function showMenu()
if data.enabled then return end
toggleControl("enter_exit", false)
bindKey("f", "down", mouseToggle)
showCursor(true)
local additions = {"stopedit", "showextras", "extragrid", "mapaccess", "pref"}
for i,v in ipairs(additions) do
local gui = getControl(v)
guiSetVisible(gui, true)
end
data.enabled = true
end
addCommandHandler("ufo", showMenu)
function hideMenu()
data.enabled = false
local additions = {"stopedit", "showextras", "extragrid", "mapaccess", "pref"}
for i,v in ipairs(additions) do
local gui = getControl(v)
guiSetVisible(gui, false)
end
showCursor(false)
toggleControl("enter_exit", true)
unbindKey("f", "down", mouseToggle)
end
-------------------
--///////////////--: Create the main screen objects
-------------------
-- Leave movement mode
guiContainer["stopedit"] = guiCreateButton(0.7825,0.0583,0.205,0.0617,"Stop Editing",true)
addEventHandler("onClientGUIClick", getControl("stopedit"), hideMenu)
-- Create the extras menu, to do is sliding the extras gridlist up and down to toggle showing, also moving the btns below it.
guiContainer["showextras"] = guiCreateButton(0.7825,0.135,0.205,0.0617,"Show Extras",true)
guiSetProperty(getControl("showextras"),"AlwaysOnTop","True")
guiContainer["extragrid"] = guiCreateGridList(0.7837,0.155,0.2025,0.37,true)
guiGridListSetSelectionMode(getControl("extragrid"),2)
guiSetProperty(getControl("extragrid"),"ZOrderChangeEnabled","False")
guiGridListAddColumn(getControl("extragrid"),"",0.1)
guiContainer["mapaccess"] = guiCreateButton(0.7825,0.54,0.205,0.0617,"Quick Map",true)
guiContainer["pref"] = guiCreateButton(0.7825,0.6133,0.205,0.0617,"Preferences",true)
for i = 1, 6 do
guiGridListAddRow(getControl("extragrid"))
end
-------------------
--///////////////--
-------------------
for i,v in pairs(guiContainer) do
guiSetVisible(v, false)
end
-------------------
--///////////////--
-------------------
-- This contains content from the freecam resource and has been editied by karlis, so thanks to him.
local zoom=10 --how far is camera target from elem
rotX, rotY = 0,0
local mouseFrameDelay = 0
local ratio = 3 --how many times distance from camera to player is smaller then distance from player to camera target
local offset = 0.4 --how much the camera goes to the right from the player (negative for the left)
local mouseSensetivity = 0.25 --ovbious much?
local width, height = guiGetScreenSize()
local PI = math.pi
local hit
--heavily modified freecam resource's core
function freecamFrame()
if not data.enabled then return end
do
local additions = {"stopedit", "showextras", "extragrid", "mapaccess", "pref"}
for i,v in ipairs(additions) do
local gui, show = getControl(v), isCursorShowing()
guiSetAlpha(gui, show and 1 or 0.9)
guiSetEnabled(gui, show)
end
end
local cameraAngleX = rotX
local cameraAngleY = rotY
local freeModeAngleZ = math.sin(cameraAngleY)
local freeModeAngleY = math.cos(cameraAngleY) * math.cos(cameraAngleX)
local freeModeAngleX = math.cos(cameraAngleY) * math.sin(cameraAngleX)
local camPosX, camPosY, camPosZ = getElementPosition(ufo)
-- calculate a target based on the current position and an offset based on the angle
local camTargetX = camPosX + freeModeAngleX * zoom
local camTargetY = camPosY + freeModeAngleY * zoom
local camTargetZ = camPosZ + freeModeAngleZ * zoom
local camPosX = camPosX - ( camTargetX - camPosX ) / ratio
local camPosY = camPosY - ( camTargetY - camPosY ) / ratio
local camPosZ = camPosZ - ( camTargetZ - camPosZ ) / ratio
if not isLineOfSightClear(camPosX,camPosY,camPosZ,camPosX,camPosY,camPosZ,true,true,true,true,false,true,false,me) then
_,camPosX,camPosY,camPosZ=processLineOfSight(camTempPosX,camTempPosY,camPosZ,camPosX,camPosY,camPosZ,true,true,true,true,false,true,false,false,localPlayer)
camPosX,camPosY,camPosZ=camPosX-(camTempPosX-camPosX)*0.1,camPosY-(camTempPosY-camPosY)*0.1,camPosZ-(camTempPosZ-camPosZ)*0.1
end
-- Set the new camera position and target
setCameraMatrix ( camPosX, camPosY, camPosZ, camTargetX, camTargetY, camTargetZ )
end
addEventHandler("onClientRender", root, freecamFrame)
function freecamMouse(_,_,aX,aY)
--ignore mouse movement if the cursor or MTA window is on
--and do not resume it until at least 5 frames after it is toggled off
--(prevents cursor mousemove data from reaching this handler)
if not data.enabled then return end
if isCursorShowing() or isMTAWindowActive() then
mouseFrameDelay = 5
return
elseif mouseFrameDelay > 0 then
mouseFrameDelay = mouseFrameDelay - 1
return
end
-- how far have we moved the mouse from the screen center?
aX = aX - width / 2
aY = aY - height / 2
rotX = rotX + aX * 0.01745 * mouseSensetivity
rotY = rotY - aY * 0.01745 * mouseSensetivity
if rotX > PI then
rotX = rotX - 2 * PI
elseif rotX < -PI then
rotX = rotX + 2 * PI
end
if rotY > PI then
rotY = rotY - 2 * PI
elseif rotY < -PI then
rotY = rotY + 2 * PI
end
-- 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
-- and strafeing will break entirely as the camera loses any concept of what is 'up'
if rotY < -PI / 3 then
rotY = -PI / 3
elseif rotY > PI / 3 then
rotY = PI / 3
end
-- work out an angle in radians based on the number of pixels the cursor has moved (ever)
end
addEventHandler("onClientCrsorMove", root, freecamMouse)
server
allowAll = false
local ufo = createObject ( 13607, -1326, -67, 55, 0, 0, 0 )
createBlipAttachedTo ( ufo, 37 )
setElementData(ufo, "vglueable", true, true)
setElementDoubleSided( ufo, true)
setElementID(ufo, "ufo")
addCommandHandler("gotoufo",
function(thePlayer)
if thePlayer then
ufoWarpPlayer(thePlayer)
end
end
)
addCommandHandler("ufoheight",
function(thePlayer, cmd, height)
ufoSetHeight(height)
end
)
-- Zap thingy
function zapMeUp()
local x,y,z = getElementPosition(ufo)
triggerClientEvent ( "ufo:ClientFireN", getRootElement(), x, y, z - 50 )
end
addEvent("zapUFO", true)
addEventHandler("zapUFO", getRootElement(), zapMeUp)
addEvent("ufo:warp_player_to_ufo", true)
function ufoWarpPlayer(pl)
local x,y,z = getElementPosition(ufo)
setElementPosition(pl, x, y, z + 0.5)
end
addEventHandler("ufo:warp_player_to_ufo", getRootElement(), ufoWarpPlayer)
function ufoSetHeight(height)
if tonumber(height) then
local x,y,z = getElementPosition(ufo)
setElementPosition(ufo, x, y, tonumber(height))
end
end
addEvent("ufo:dirHeight", true)
addEventHandler("ufo:dirHeight", getRootElement(), ufoSetHeight)
function stopMove()
stopObject(ufo)
end
addEvent("ufoStop", true)
addEventHandler("ufoStop", getRootElement(), stopMove)
-- ufo raise/lower/reset
function ufoHeight(theValue)
local x, y, z = getElementPosition(ufo)
if (theValue == 5.5) then
moveObject(ufo, 0, x, y, 5.5)
else
moveObject(ufo, 5000, x, y, z + theValue)
end
end
addEvent("ufoHeight", true)
addEventHandler("ufoHeight", getRootElement(), ufoHeight)
-- ufo warper
function ufoWarper(x, y, z)
moveObject(ufo, 0, x, y, z)
end
addEvent("ufo:move2Loc", true)
addEventHandler("ufo:move2Loc", getRootElement(), ufoWarper)
-- Directional movement controls
function ufoMove(, yD, zD, direct,speed)
local x,y,z = getElementPosition(ufo)
if not direct then
moveObject(ufo, 20000, x + , y + yD, z + zD)
elseif direct then
moveObject(ufo, speed, ,yD,z)
end
end
addEvent("ufo:moveEvent", true)
addEventHandler("ufo:moveEvent", getRootElement(), ufoMove)
-- Rotational movement controls
function rotateUfoFunc(rX, rY, rZ)
local x,y,z = getElementPosition(ufo)
moveObject(ufo, 5000, x, y, z, rX, rY, rZ)
end
addEvent("ufo:rotateUfo", true)
addEventHandler("ufo:rotateUfo", getRootElement(), rotateUfoFunc)
-- ****************************************
-- * Super weapons - Ion Nuke - By Ransom *
-- ****************************************
function NukeFinished ()
N_Active = false
end
addEvent("ufo:serverNukeFinished", true)
addEventHandler("ufo:serverNukeFinished", root, NukeFinished)
function KillNukedPlayer ()
killPed( source )
outputChatBox ( "#ff0000*UFO: #ffff00You got attacked by the UFO!", source, 105, 252, 55, true )
end
addEvent("ufo:serverKillNukedPlayer", true)
addEventHandler("ufo:serverKillNukedPlayer", root, KillNukedPlayer)
code is verry messy atm.but if you test it ingame, type /ufo and press f to toggle.
@Karlis, the camera fails.