Radar

View previous topic View next topic Go down

Radar

Post by Timothy Ashtön on Wed Feb 09, 2011 6:33 am

I was pm'd by SuperShade about adding radar to a chip. I had no idea on what the explaination is for the radar variables, but I searched and found Juz old Radar (And I also have the Radar Truck from Kedji's mod of it) and I'll post the code in a box, but It be really handy if there was a way to explain whats going on with the lua code.

ASLO; It is required that you have Juz Library ( require("Juz/index.lua") ) Or this will not work. I sujest a link from the tutorial to the library for easy access. =D

Spoiler:
Code:
require("Juz/index.lua")

draw = {}
   draw.set = {}
   draw.draw = {}
   draw.l = {}
   draw.pla = {}
col = {}
data = {}
   data.c = {}
   data.fr = {}
   data.screen = {}
   data.pla = {}
ui = {}
   ui.rot = {}
   ui.tra = {}
      ui.tra.c = {}
      ui.tra.d = {}
   ui.ran = {}
   ui.pla = {}
opt = {}

function OnInit() init() end
function OnReset() init() end
function init()
   initindex()
   
   _ZOOM(1)

   col.misc = line.rgb(255,0,0)
   col.lat = line.rgb(204,204,204)
   col.ran = line.rgb(255,127,0)
   col.n = line.rgb(255,255,255)
   col.pla = {}
   col.pla.main = line.rgb(255,255,255)
   col.uipla = line.rgb(255,255,0)

   data.fr.y = 1
   data.range = 500
   data.ey = 0
   data.c = {x=0,y=0}

   ui.mode = nil
   ui.rot.a0 = 0
   ui.tra.c = {x0=0,y0=0}
   ui.pla.c = nil

   opt.lattxt = {}
   opt.lattxt.t = 1
   opt.mouse = {}
   opt.mouse.t = 0
end

draw.set.lat = function()
   draw.l.lat = {}
   
   for i = math.ceil((-data.c.x-len2(data.fr.x,data.fr.y)*data.range)/1000)*1000,math.floor((-data.c.x+len2(data.fr.x,data.fr.y)*data.range)/1000)*1000,1000 do
      local tmp = (-i-data.c.x)/data.range
      table.insert(draw.l.lat,line.move(0,0,0,tmp,-len2(data.fr.x,data.fr.y),0))
      table.insert(draw.l.lat,line.line(0,0,0,tmp,len2(data.fr.x,data.fr.y),0,col.lat))
      if opt.lattxt.t == 0 then
         for j = math.ceil((-data.c.y-len2(data.fr.x,data.fr.y)*data.range)/1000)*1000,math.floor((-data.c.y+len2(data.fr.x,data.fr.y)*data.range)/1000)*1000,1000 do
            local tmp1 = (-j-data.c.y)/data.range
            line.insert(draw.l.lat,line.extract(line.text.set(20/data.range+tmp,-45/data.range+tmp1,0,"{"..(-i/1000)..","..(j/1000).."}",50/data.range,"left",col.lat)))
         end
      end
   end
   for i = math.ceil((-data.c.y-len2(data.fr.x,data.fr.y)*data.range)/1000)*1000,math.floor((-data.c.y+len2(data.fr.x,data.fr.y)*data.range)/1000)*1000,1000 do
      local tmp = (-i-data.c.y)/data.range
      table.insert(draw.l.lat,line.move(0,0,0,-len2(data.fr.x,data.fr.y),tmp,0))
      table.insert(draw.l.lat,line.line(0,0,0,len2(data.fr.x,data.fr.y),tmp,0,col.lat))
   end
   
   draw.l.lat = line.rotate(-data.ey,draw.l.lat)
end

draw.set.misc = function()
   draw.l.misc = {}
   
   table.insert(draw.l.misc,line.move(0,0,0,0,0.04,0))
   table.insert(draw.l.misc,line.line(0,0,0,-0.015,-0.015,0,col.misc))
   table.insert(draw.l.misc,line.line(0,0,0,0.015,-0.015,0,col.misc))
   table.insert(draw.l.misc,line.line(0,0,0,0,0.04,0,col.misc))
   
   local d = {}
   if abs(cycle(data.ey,-pi/2,pi/2)) < atan2(data.fr.x-0.05,data.fr.y-0.05) then
      d.x = sin(-data.ey)*((1-0.05)/cos(-data.ey))*sgn(cos(-data.ey))
      d.y = cos(-data.ey)*((1-0.05)/cos(-data.ey))*sgn(cos(-data.ey))
   else
      d.x = sin(-data.ey)*((data.fr.x-0.05)/sin(-data.ey))*sgn(sin(-data.ey))
      d.y = cos(-data.ey)*((data.fr.x-0.05)/sin(-data.ey))*sgn(sin(-data.ey))
   end
   d.x1 = d.x/((0.05+len2(d.x,d.y))/len2(d.x,d.y))
   d.y1 = d.y/((0.05+len2(d.x,d.y))/len2(d.x,d.y))
   d.x2 = d.x/((0.15+len2(d.x,d.y))/len2(d.x,d.y))
   d.y2 = d.y/((0.15+len2(d.x,d.y))/len2(d.x,d.y))
   line.insert(draw.l.misc,line.add(d.x,d.y,0,line.rotate(-data.ey,line.extract(line.text.set(0,0,0,"N",0.06,"centre",col.n)))))
   line.insert(draw.l.misc,{line.move(d.x1,d.y1,0,0,0,0),line.line(d.x2,d.y2,0,0,0,0,col.n)})
end

draw.set.ran = function()
   draw.l.ran = {}
   
   local tmp = ui.ran.d*0.4
   
   table.insert(draw.l.ran,line.move(-data.screen.side,tmp,0,0.165,0.01,0))
   table.insert(draw.l.ran,line.line(-data.screen.side,tmp,0,0.055,0.01,0,col.ran))
   table.insert(draw.l.ran,line.line(-data.screen.side,tmp,0,0.055,-0.01,0,col.ran))
   table.insert(draw.l.ran,line.line(-data.screen.side,tmp,0,0.165,-0.01,0,col.ran))
   table.insert(draw.l.ran,line.line(-data.screen.side,tmp,0,0.165,0.01,0,col.ran))
   
   table.insert(draw.l.ran,line.move(-data.screen.side,0,0,0.075,tmp+0.01,0))
   table.insert(draw.l.ran,line.line(-data.screen.side,0,0,0.075,0.41,0,col.ran))
   table.insert(draw.l.ran,line.line(-data.screen.side,0,0,0.145,0.41,0,col.ran))
   table.insert(draw.l.ran,line.line(-data.screen.side,0,0,0.145,tmp+0.01,0,col.ran))
   table.insert(draw.l.ran,line.move(-data.screen.side,0,0,0.11,tmp+0.01,0))
   table.insert(draw.l.ran,line.line(-data.screen.side,0,0,0.11,0.41,0,col.ran))
   
   table.insert(draw.l.ran,line.move(-data.screen.side,0,0,0.075,tmp-0.01,0))
   table.insert(draw.l.ran,line.line(-data.screen.side,0,0,0.075,-0.41,0,col.ran))
   table.insert(draw.l.ran,line.line(-data.screen.side,0,0,0.145,-0.41,0,col.ran))
   table.insert(draw.l.ran,line.line(-data.screen.side,0,0,0.145,tmp-0.01,0,col.ran))
   table.insert(draw.l.ran,line.move(-data.screen.side,0,0,0.11,tmp-0.01,0))
   table.insert(draw.l.ran,line.line(-data.screen.side,0,0,0.11,-0.41,0,col.ran))
   
   if opt.lattxt.t == 0 then
      line.insert(draw.l.ran,line.extract(line.text.set(-data.screen.side+0.075,-0.45,0,"RANGE: "..string.format("%.1f",(data.range/1000*2)^2*data.fr.x).."KM^2.",0.05,"left",col.ran)))
   end
end

draw.set.pla = function()
   draw.l.pla = {}

   for i = 0,_PLAYERS()-1 do
      data.pla[i] = noisec(i)
      data.pla[i].col = _PLAYERCOLOR(i)
      data.pla[i].name = _PLAYERNAME(i)
      data.pla[i].chips = _PLAYERCHIPS(i)
      data.pla[i].arms = _PLAYERARMS(i)
      data.pla[i].crushes = _PLAYERCRUSHES(i)
      data.pla[i].resets = _PLAYERRESETS(i)+_PLAYERINITS(i)
      data.pla[i].d = {}
      
      col.pla[i] = data.pla[i].col
   end
   
   for i = 0,_PLAYERS()-1 do
      data.pla[i].d.x0 = -(data.pla[i].x+data.c.x)/data.range
      data.pla[i].d.y0 = -(data.pla[i].z+data.c.y)/data.range
      
      data.pla[i].d.x = -sin(data.ey)*data.pla[i].d.y0+cos(data.ey)*data.pla[i].d.x0
      data.pla[i].d.y = sin(data.ey)*data.pla[i].d.x0+cos(data.ey)*data.pla[i].d.y0
   end
   
   for i = 0,_PLAYERS()-1 do
      if i ~= _PLAYERMYNUM() then
         table.insert(draw.l.pla,line.move(data.pla[i].d.x,data.pla[i].d.y,0,0.02,0.02,0))
         table.insert(draw.l.pla,line.line(data.pla[i].d.x,data.pla[i].d.y,0,-0.02,0.02,0,col.pla[i]))
         table.insert(draw.l.pla,line.line(data.pla[i].d.x,data.pla[i].d.y,0,-0.02,-0.02,0,col.pla[i]))
         table.insert(draw.l.pla,line.line(data.pla[i].d.x,data.pla[i].d.y,0,0.02,-0.02,0,col.pla[i]))
         table.insert(draw.l.pla,line.line(data.pla[i].d.x,data.pla[i].d.y,0,0.02,0.02,0,col.pla[i]))
         table.insert(draw.l.pla,line.move(data.pla[i].d.x,data.pla[i].d.y,0,0.01,0.01,0))
         table.insert(draw.l.pla,line.line(data.pla[i].d.x,data.pla[i].d.y,0,-0.01,-0.01,0,col.pla.main))
         table.insert(draw.l.pla,line.move(data.pla[i].d.x,data.pla[i].d.y,0,-0.01,0.01,0))
         table.insert(draw.l.pla,line.line(data.pla[i].d.x,data.pla[i].d.y,0,0.01,-0.01,0,col.pla.main))
      else
         table.insert(draw.l.pla,line.move(data.pla[i].d.x,data.pla[i].d.y,0,0.015,0.015,0))
         table.insert(draw.l.pla,line.line(data.pla[i].d.x,data.pla[i].d.y,0,-0.015,-0.015,0,col.pla.main))
         table.insert(draw.l.pla,line.move(data.pla[i].d.x,data.pla[i].d.y,0,-0.015,0.015,0))
         table.insert(draw.l.pla,line.line(data.pla[i].d.x,data.pla[i].d.y,0,0.015,-0.015,0,col.pla.main))
         table.insert(draw.l.pla,line.move(data.pla[i].d.x,data.pla[i].d.y,0,0,0.015,0))
         table.insert(draw.l.pla,line.line(data.pla[i].d.x,data.pla[i].d.y,0,0,-0.015,0,col.pla[i]))
         table.insert(draw.l.pla,line.move(data.pla[i].d.x,data.pla[i].d.y,0,-0.015,0,0))
         table.insert(draw.l.pla,line.line(data.pla[i].d.x,data.pla[i].d.y,0,0.015,0,0,col.pla[i]))
      end
   end
end

draw.draw = function(t)
   line[2].draw(t)
end

ui.pla.f = function(p)
   draw.l.uipla = {}

   table.insert(draw.l.uipla,line.move(data.screen.side,1,0,-0.6,0,0))
   table.insert(draw.l.uipla,line.line(data.screen.side,1,0,-0.6,-0.43,0,col.uipla))
   table.insert(draw.l.uipla,line.line(data.screen.side,1,0,0,-0.43,0,col.uipla))
   line.insert(draw.l.uipla,line.extract(line.text.set(data.screen.side-0.3,1-0.11,0,string.upper(data.pla[p].name),0.05,"centre",col.uipla)))
   line.insert(draw.l.uipla,line.extract(line.text.set(data.screen.side-0.55,1-0.18,0,"CHIPS:",0.04,"left",col.uipla)))
   line.insert(draw.l.uipla,line.extract(line.text.set(data.screen.side-0.05,1-0.18,0,string.format("%.0f",data.pla[p].chips),0.04,"right",col.uipla)))
   line.insert(draw.l.uipla,line.extract(line.text.set(data.screen.side-0.55,1-0.24,0,"ARMS:",0.04,"left",col.uipla)))
   line.insert(draw.l.uipla,line.extract(line.text.set(data.screen.side-0.05,1-0.24,0,string.format("%.0f",data.pla[p].arms),0.04,"right",col.uipla)))
   line.insert(draw.l.uipla,line.extract(line.text.set(data.screen.side-0.55,1-0.30,0,"DEATHS:",0.04,"left",col.uipla)))
   line.insert(draw.l.uipla,line.extract(line.text.set(data.screen.side-0.05,1-0.30,0,string.format("%.0f",data.pla[p].crushes),0.04,"right",col.uipla)))
   line.insert(draw.l.uipla,line.extract(line.text.set(data.screen.side-0.55,1-0.36,0,"RESETS:",0.04,"left",col.uipla)))
   line.insert(draw.l.uipla,line.extract(line.text.set(data.screen.side-0.05,1-0.36,0,string.format("%.0f",data.pla[p].resets),0.04,"right",col.uipla)))
end

function UI()
   if m.mu == 1 and ui.mode == "rot" then ui.mode = nil end
   if m.ru == 1 and ui.mode == "tra" then ui.mode = nil end
   if m.lu == 1 and ui.mode == "ran" then ui.mode = nil end
   if ui.mode == "pla" then
      if m.ld == 1 or m.md == 1 or m.rd == 1 then
         ui.mode,ui.pla.c = nil,nil
      end
   end
   
   if m.md == 1 and ui.mode == nil then
      ui.mode = "rot"
   end
   if m.rd == 1 and ui.mode == nil then
      ui.mode = "tra"
   end
   if m.ld == 1 and ui.mode == nil then
      if m.x < -data.screen.side+0.15 and m.x > -data.screen.side+0.07 then
         ui.mode = "ran"
      else
         for i = 0,_PLAYERS()-1 do
            if ui.mode == nil and m.x < data.pla[i].d.x+0.02 and m.x > data.pla[i].d.x-0.02 and m.y < data.pla[i].d.y+0.02 and m.y > data.pla[i].d.y-0.02 then
               ui.mode = "pla"
               ui.pla.c = i
            end
         end
      end
   end
   if ui.mode == "rot" then
      ui.rot.a = atan2(m.x,m.y)
      ui.rot.d = ui.rot.a-ui.rot.a0
      ui.rot.a0 = ui.rot.a
   else
      ui.rot.d = 0
      ui.rot.a = atan2(m.x,m.y)
      ui.rot.a0 = ui.rot.a
   end
   if ui.mode == "tra" then
      ui.tra.c.x = m.x
      ui.tra.c.y = m.y
      ui.tra.d.x = ui.tra.c.x-ui.tra.c.x0
      ui.tra.d.y = ui.tra.c.y-ui.tra.c.y0
      ui.tra.c.x0 = ui.tra.c.x
      ui.tra.c.y0 = ui.tra.c.y
   else
      ui.tra.d.x,ui.tra.d.y = 0,0
      ui.tra.c.x,ui.tra.c.y = m.x,m.y
      ui.tra.c.x0,ui.tra.c.y0 = ui.tra.c.x,ui.tra.c.y
   end
   if ui.mode == "ran" then
      ui.ran.d = limit(m.y,-0.4,0.4)/0.4
   else
      ui.ran.d = 0
   end
   if ui.mode == "pla" then
      ui.pla.f(ui.pla.c)
      draw.draw(draw.l.uipla)
   end
   
   data.ey = cycle(data.ey-ui.rot.d,-pi,pi)
   data.c.x = data.c.x-(cos(data.ey)*ui.tra.d.x+sin(data.ey)*ui.tra.d.y)*data.range
   data.c.y = data.c.y-(-sin(data.ey)*ui.tra.d.x+cos(data.ey)*ui.tra.d.y)*data.range
   data.range = math.max(data.range+(ui.ran.d*4000/(_FPS())),1)
end

function options()
   opt.lattxt.k = _KEYDOWN(7)
   opt.lattxt.t = mod(opt.lattxt.t+opt.lattxt.k,2)
   if opt.lattxt.t == 1 then opt.lattxt.txt = "Off" else opt.lattxt.txt = "On - Large CPU Drain" end
   
   opt.mouse.k = _KEYDOWN(8)
   opt.mouse.t = mod(opt.mouse.t+opt.mouse.k,2)
   if opt.mouse.t == 1 then opt.mouse.txt = "Off" else opt.mouse.txt = "On" end
end

function main()
   if opt.mouse.t == 0 then
      m = mouseout(m)
   else
      m = {}
      m.x,m.y = 0,0
      m.l,m.ld,m.lu = 0,0,0
      m.m,m.md,m.mu = 0,0,0
      m.r,m.rd,m.ru = 0,0,0
   end
   
   data.screen.side = _WIDTH()/_HEIGHT()
   data.fr.x = data.screen.side

   out(0,"'Radar', by Juz.")
   out(2,"[A] = Toggle Text (",opt.lattxt.txt,").  [S] = Toggle Mouse (",opt.mouse.txt,").")
   out(3,"[Mouse L] = Selector (Player Info or Range).  [Mouse M] = Rotate.  [Mouse R] = Translate.")
   
   options()
   
   UI()

   draw.set.lat()
   draw.set.misc()
   draw.set.ran()
   draw.set.pla()
   
   draw.draw(draw.l.lat)
   draw.draw(draw.l.misc)
   draw.draw(draw.l.ran)
   draw.draw(draw.l.pla)
end
avatar
Timothy Ashtön
Walker
Walker

Posts : 289
Join date : 2010-07-17
Age : 25
Location : Ontario

View user profile http://wildfrontierguidecomplete.blogspot.com/

Back to top Go down

Re: Radar

Post by supershade on Wed Feb 09, 2011 11:20 am

Wish i knew how to use but thx.
avatar
supershade
Hover
Hover

Posts : 107
Join date : 2011-02-07
Age : 22
Location : Norman,Oklahoma

View user profile

Back to top Go down

Re: Radar

Post by Timothy Ashtön on Wed Feb 09, 2011 6:42 pm

You can copy paste that into your Lua tab (Tab as in use RCD) but the only problem is once you've done that, all controls seem to stop working. ( I tested it on my car, Radar worked, but controls as in engine and turn didn't :\ )

So kinda requesting Juz (Since this was his Lua) to explain how to keep controls while having radar. Idk..
avatar
Timothy Ashtön
Walker
Walker

Posts : 289
Join date : 2010-07-17
Age : 25
Location : Ontario

View user profile http://wildfrontierguidecomplete.blogspot.com/

Back to top Go down

Re: Radar

Post by supershade on Wed Feb 09, 2011 6:44 pm

okay I do not know how to use lua script as in applying it to vehicles I am very new.
avatar
supershade
Hover
Hover

Posts : 107
Join date : 2011-02-07
Age : 22
Location : Norman,Oklahoma

View user profile

Back to top Go down

Re: Radar

Post by Timothy Ashtön on Wed Feb 09, 2011 8:59 pm

I'll post Juz Radar + Kedji mod, You'll see what the radar is, but you'll have control of the truck because controls are in Lua. Anyways check it out.
avatar
Timothy Ashtön
Walker
Walker

Posts : 289
Join date : 2010-07-17
Age : 25
Location : Ontario

View user profile http://wildfrontierguidecomplete.blogspot.com/

Back to top Go down

Re: Radar

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum