Page 1 of 1

Need help writing a lua gadget.

Posted: 02 May 2008, 16:34
by url_00
Alright, I have an idea for a mod, but I need to ask if this is possible first, and how to do the basics of it.

Ok, you know how the team platters widget draws a circle on the ground below a unit? Basically, I need a gadget that can draw circles, squares and triangles and such like the way that team platters works.

I looked at team platters, and I guessing that this code is where the circle is finnaly drawn:

Code: Select all

function widget:DrawWorldPreUnit()
  glLineWidth(3.0)

  glDepthTest(true)
  
  glPolygonOffset(-50, -2)

  local lastColorSet = nil
  for _,unitID in ipairs(spGetAllUnits()) do
    if (spIsUnitVisible(unitID)) then
      local teamID = spGetUnitTeam(unitID)
      if (teamID) then
        local udid = spGetUnitDefID(unitID)
        local radius = GetUnitDefRealRadius(udid)
        if (radius) then
          local colorSet  = GetTeamColorSet(teamID)
          if (trackSlope and (not UnitDefs[udid].canFly)) then
            local x, y, z = spGetUnitBasePosition(unitID)
            local gx, gy, gz = spGetGroundNormal(x, z)
            local degrot = math.acos(gy) * 180 / math.pi
            glColor(colorSet[1])
            glDrawListAtUnit(unitID, circlePolys, false,
                             radius, 1.0, radius,
                             degrot, gz, 0, -gx)
            glColor(colorSet[2])
            glDrawListAtUnit(unitID, circleLines, false,
                             radius, 1.0, radius,
                             degrot, gz, 0, -gx)
          else
            glColor(colorSet[1])
            glDrawListAtUnit(unitID, circlePolys, false,
                             radius, 1.0, radius)
            glColor(colorSet[2])
            glDrawListAtUnit(unitID, circleLines, false,
                             radius, 1.0, radius)
          end
        end
      end
    end
  end
Anyway, some help would be very nice.

PS. Can you hide the model of of a unit, but maintain its hit box?
PPS. Do you even need to have a model?
PPPS. I need a unit with out a model, just what ever the script draws.

Re: Need help writing a lua gadget.

Posted: 02 May 2008, 18:11
by KDR_11k
You can have empty models that are nothing but a hitbox, yes.

Re: Need help writing a lua gadget.

Posted: 06 May 2008, 22:02
by url_00
Not to pry, but I still need an answer to my other main question.

How do I draw shapes, like triangles and squares, on the ground, below the unit.

Re: Need help writing a lua gadget.

Posted: 07 May 2008, 05:43
by Tribulexrenamed
OpenGL. Beyond that I cannot help.

Re: Need help writing a lua gadget.

Posted: 07 May 2008, 06:00
by url_00
Tribulex wrote:OpenGL. Beyond that I cannot help.
:cry: :cry: :cry: :cry: :cry:

Re: Need help writing a lua gadget.

Posted: 07 May 2008, 14:38
by Tribulexrenamed
I am currently looking for good free online literature on OpenGL. Due to its expansive nature, being a graphics library, I was wondering if anyone could direct me to a good source? I would appreciate it.

Re: Need help writing a lua gadget.

Posted: 07 May 2008, 16:32
by Pxtl
The code you've got there draws the circles, yes, but it doesn't build the circle shape itself - so if you wanted to do triangles or squares or whatever, you'd use nearly the exact same code.

The "CirclePolys" and "CircleLines" objects in that Lua are the objects that actually contain the definitions for the circle shape. Look at the code that generates those things.