Need help writing a lua gadget.

Need help writing a lua gadget.

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
url_00
Posts: 163
Joined: 15 Apr 2007, 22:44

Need help writing a lua gadget.

Post 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.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Need help writing a lua gadget.

Post by KDR_11k »

You can have empty models that are nothing but a hitbox, yes.
User avatar
url_00
Posts: 163
Joined: 15 Apr 2007, 22:44

Re: Need help writing a lua gadget.

Post 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.
User avatar
Tribulexrenamed
Posts: 775
Joined: 22 Apr 2008, 19:06

Re: Need help writing a lua gadget.

Post by Tribulexrenamed »

OpenGL. Beyond that I cannot help.
User avatar
url_00
Posts: 163
Joined: 15 Apr 2007, 22:44

Re: Need help writing a lua gadget.

Post by url_00 »

Tribulex wrote:OpenGL. Beyond that I cannot help.
:cry: :cry: :cry: :cry: :cry:
User avatar
Tribulexrenamed
Posts: 775
Joined: 22 Apr 2008, 19:06

Re: Need help writing a lua gadget.

Post 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.
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Need help writing a lua gadget.

Post 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.
Post Reply

Return to “Lua Scripts”