Range Widget, Alpha 2

Range Widget, Alpha 2

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

Moderator: Moderators

User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Range Widget, Alpha 2

Post by Argh »

This shows the weapon range for a Unit, if it's Selected and is on your Team.

It uses CustomParams, so you can use different colors for different Units, or multiple weapons on a Unit, to show people what's what really clearly.

Will not show enemy ranges, ever, since that would be a cheat.

Can currently be set up for up to three weapons, adding more is trivial.

Code: Select all

function widget:GetInfo()
  return {
    name      = "Range Widget",
    desc      = "Shows your units' weapon ranges, when selected.",
    author    = "Argh",
    date      = "January 21, 2009",
    license   = "Public Domain, or the least-restrictive rights of your country of residence",
    layer     = 0,
    enabled   = true -- loaded by default?
  }
end

local RangeList = {}
local unitIDList
local id
local unitID
local Team = Spring.GetLocalTeamID()

local GetUnitDefID = Spring.GetUnitDefID
local glColor = gl.Color
local glDrawGroundCircle = gl.DrawGroundCircle
local glLineWidth = gl.LineWidth
local GetUnitPosition = Spring.GetUnitPosition
local GetUnitTeam = Spring.GetUnitTeam
local GetSelectedUnits = Spring.GetSelectedUnits

function widget:Initialize()
	for ud,_ in pairs(UnitDefs) do
		if UnitDefs[ud].customParams.show_range_one == 'yes' then
			table.insert(RangeList,ud,{range_one = tonumber(UnitDefs[ud].customParams.weapon_range_one), colorR_one = tonumber(UnitDefs[ud].customParams.color_r_one), 

colorG_one = tonumber(UnitDefs[ud].customParams.color_g_one), colorB_one = tonumber(UnitDefs[ud].customParams.color_b_one)})
		end
		if UnitDefs[ud].customParams.show_range_two == 'yes' then
			table.insert(RangeList,ud,{range_two = tonumber(UnitDefs[ud].customParams.weapon_range_two), colorR_two = tonumber(UnitDefs[ud].customParams.color_r_two), 

colorG_two = tonumber(UnitDefs[ud].customParams.color_g_two), colorB_two = tonumber(UnitDefs[ud].customParams.color_b_two)})
		end
		if UnitDefs[ud].customParams.show_range_three == 'yes' then
			table.insert(RangeList,ud,{range_three = tonumber(UnitDefs[ud].customParams.weapon_range_three), colorR_three = tonumber(UnitDefs[ud].customParams.color_r_three), 

colorG_three = tonumber(UnitDefs[ud].customParams.color_g_three), colorB_three = tonumber(UnitDefs[ud].customParams.color_b_three)})
		end
	end
end

function widget:DrawWorldPreUnit()
	unitIDList = GetSelectedUnits()
	if unitIDList[1] ~= nil then
		for _,unitID in ipairs(unitIDList) do
			if Team == GetUnitTeam(unitID) then
				id = GetUnitDefID(unitID)
				if RangeList[id] then					
					x,y,z = GetUnitPosition(unitID)
					glLineWidth(2.5)
					if RangeList[id].range_one ~= nil then
						glColor(RangeList[id].colorR_one,RangeList[id].colorG_one,RangeList[id].colorB_one,0.35)
						glDrawGroundCircle(x,y,z,RangeList[id].range_one,128)
					end
					if RangeList[id].range_two ~= nil then
						glColor(RangeList[id].colorR_two,RangeList[id].colorG_two,RangeList[id].colorB_two,0.35)
						glDrawGroundCircle(x,y,z,RangeList[id].range_two,128)
					end
					if RangeList[id].range_three ~= nil then
						glColor(RangeList[id].colorR_three,RangeList[id].colorG_three,RangeList[id].colorB_three,0.35)
						glDrawGroundCircle(x,y,z,RangeList[id].range_three,128)
					end
				end
			end
		end	
	end
end
Last edited by Argh on 21 Jan 2009, 14:16, edited 1 time in total.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Range Widget, Alpha 1

Post by Forboding Angel »

Could I get a screenshot of what it should look like?

I tried it and it isn't working for me. Attached is the file I'm using. Am I doin it rong?
unit_ranges.lua
(3.08 KiB) Downloaded 116 times
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Range Widget, Alpha 2

Post by Argh »

That part's fine, but you need to add customParams to the Units you want to display the ranges in the Unit FBI, like this example:

[customParams]
{
//Range Stuff
show_range_one=yes;
color_r_one=1.0;
color_g_one=1.0;
color_b_one=0.5;
}

This shows a range band that's light yellow for this unit, at a range of 950. You can customize it per Unit and per weapon this way.

Or, if you'd rather automate that part, you can just have it look up the UnitDef.weapons[number of weapon].weaponDef to get the weaponDef... then WeaponDefs[weaponDef].range to get the range, if you'd prefer. In fact, I think I'll remove that customParam, it'll save drudgery in 99% of the use cases.

Here... now you don't have to worry about putting in a customParam for range, which will save on maintenance hassles if you're playing around with ranges, etc.

I'm leaving the rest as a requirement, though- if you just want random colors assigned at Initialize, that's easy enough to do, just do a math.random(0,1.0) instead of the customParam.

Code: Select all

function widget:GetInfo()
  return {
    name      = "Range Widget",
    desc      = "Shows your units' weapon ranges, when selected.",
    author    = "Argh",
    date      = "January 21, 2009",
    license   = "Public Domain, or the least-restrictive rights of your country of residence",
    layer     = 0,
    enabled   = true -- loaded by default?
  }
end

local RangeList = {}
local unitIDList
local id
local unitID
local Team = Spring.GetLocalTeamID()

local GetUnitDefID = Spring.GetUnitDefID
local glColor = gl.Color
local glDrawGroundCircle = gl.DrawGroundCircle
local glLineWidth = gl.LineWidth
local GetUnitPosition = Spring.GetUnitPosition
local GetUnitTeam = Spring.GetUnitTeam
local GetSelectedUnits = Spring.GetSelectedUnits

function widget:Initialize()
	for ud,_ in pairs(UnitDefs) do
		if UnitDefs[ud].customParams.show_range_one == 'yes' then
			local weaponD = UnitDefs[ud].weapons[1].weaponDef
			--Spring.Echo("weaponDef "..weaponD.." found")
			local Range = WeaponDefs[weaponD].range
			table.insert(RangeList,ud,{range_one = Range, colorR_one = 

tonumber(UnitDefs[ud].customParams.color_r_one), colorG_one = tonumber(UnitDefs[ud].customParams.color_g_one), colorB_one = 

tonumber(UnitDefs[ud].customParams.color_b_one)})
		end
		if UnitDefs[ud].customParams.show_range_two == 'yes' then
			local weaponD = UnitDefs[ud].weapons[2].weaponDef
			local Range = WeaponDefs[weaponD].range
			table.insert(RangeList,ud,{range_two = Range, colorR_two = 

tonumber(UnitDefs[ud].customParams.color_r_two), colorG_two = tonumber(UnitDefs[ud].customParams.color_g_two), colorB_two 

= tonumber(UnitDefs[ud].customParams.color_b_two)})
		end
		if UnitDefs[ud].customParams.show_range_three == 'yes' then
			local weaponD = UnitDefs[ud].weapons[3].weaponDef
			local Range = WeaponDefs[weaponD].range
			table.insert(RangeList,ud,{range_three = Range, colorR_three = 

tonumber(UnitDefs[ud].customParams.color_r_three), colorG_three = tonumber(UnitDefs[ud].customParams.color_g_three), 

colorB_three = tonumber(UnitDefs[ud].customParams.color_b_three)})
		end
	end
end

function widget:DrawWorldPreUnit()
	unitIDList = GetSelectedUnits()
	if unitIDList[1] ~= nil then
		for _,unitID in ipairs(unitIDList) do
			if Team == GetUnitTeam(unitID) then
				id = GetUnitDefID(unitID)
				if RangeList[id] then					
					x,y,z = GetUnitPosition(unitID)
					glLineWidth(2.5)
					if RangeList[id].range_one ~= nil then
						

glColor(RangeList[id].colorR_one,RangeList[id].colorG_one,RangeList[id].colorB_one,0.35)
						glDrawGroundCircle(x,y,z,RangeList[id].range_one,128)
					end
					if RangeList[id].range_two ~= nil then
						

glColor(RangeList[id].colorR_two,RangeList[id].colorG_two,RangeList[id].colorB_two,0.35)
						glDrawGroundCircle(x,y,z,RangeList[id].range_two,128)
					end
					if RangeList[id].range_three ~= nil then
						

glColor(RangeList[id].colorR_three,RangeList[id].colorG_three,RangeList[id].colorB_three,0.35)
						glDrawGroundCircle(x,y,z,RangeList[id].range_three,128)
					end
				end
			end
		end	
	end
end
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Range Widget, Alpha 2

Post by lurker »

Argh wrote:Will not show enemy ranges, ever, since that would be a cheat.
Okay, not going to say anything mean until you explain. You can see the max range of an enemy just by mousing over. How is seeing the ranges a cheat?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Range Widget, Alpha 2

Post by Argh »

Because you have to mouse-over, which requires micro-time and requires that the Unit is actually in LosState.

Anything past that is a cheat, imo. Being able to fly a Unit over enemy defenses and see their exact ranges displayed, so that you know where to put your counters... is a cheat, pure and simple. Dunno why this isn't totally obvious, tbh. I suspect it's because the hardcore players just don't tell you coders how useful having that kind of information is, frankly.

It's like the old "headshot models" in CS- it didn't make your aim any better, but it told you WHERE to aim, very clearly. Which is why replacement models were banned from most serious servers. Giving players information that the game designer decided not to give them... is cheating, there's no other way to define it. It's not "helpful", it's giving people stuff they weren't supposed to have in the first place. Weapon ranges are a very important mystery- it's almost as important, tactically, as knowing what your enemy's economic output would be strategically...
Last edited by Argh on 21 Jan 2009, 14:38, edited 1 time in total.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Range Widget, Alpha 2

Post by lurker »

But it's just memorization. Cheating, to me, is something more like taking advantage of static unitIDs to know things you shouldn't from radar, a nasty exploit that should be fixed in the engine.

Edit: Important mystery? When an experienced player can look at a defensive line and just know where the ranges are?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Range Widget, Alpha 2

Post by Argh »

No, it's not, dammit. One is having to spend time with a mouse over an object, zoom out, check vs. terrain, etc.- it takes a few seconds, minimum. The other is automated gimme. Totally different.

Dunno why you can't see the obvious here, man. Hardcore players gain so much from stuff like this, because of the micro-time they're saving.
Last edited by Argh on 21 Jan 2009, 14:42, edited 1 time in total.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Range Widget, Alpha 2

Post by lurker »

An experienced player doesn't have to mouse over. They know the range by heart. They can use the range of the counter they are placing as a guideline, putting it just enough in range of the opponent for quickest damage from out of reach.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Range Widget, Alpha 2

Post by Argh »

No. They have a guess. A good guess, based on a lot of experience (assuming that the game design is very stable, and that stuff doesn't change). But they do not KNOW, and will make mistakes. Those small mistakes are what makes a hardcore game, man. Somebody's off by a few pixels. Happens all the time in hardcore StarCraft games.

Knowing is a lot different than an educated guess. I don't care about people who play well memorizing stuff... and this tool makes that easier. But I really do care about people being spoon-fed information that they should have to learn the hard way. It ruins a game, when you know too much about your opponents' capabilities.
Last edited by Argh on 21 Jan 2009, 14:49, edited 1 time in total.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Range Widget, Alpha 2

Post by KDR_11k »

Argh wrote:Because you have to mouse-over, which requires micro-time and requires that the Unit is actually in LosState.
You can pause the game, look and unpause. The other guys will hate that but hey, not your problem, right?
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Range Widget, Alpha 2

Post by lurker »

Even with displayed ranges it's easy to screw up. Just which part of the unit has to be where on the range ring or how may pixels past it? Especially when units retaliating can shoot slightly past their normal ranges at times, as can units shooting at radar blips. You can play it safe with or without a widget's help, because you know where the limit is and go well beyond it. If you want to toe the line, with or without the widget, you will often fail.

Edit: Why should it be hard to learn ranges?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Range Widget, Alpha 2

Post by Argh »

Even with displayed ranges it's easy to screw up. Just which part of the unit has to be where on the range ring or how may pixels past it? Especially when units retaliating can shoot slightly past their normal ranges at times, as can units shooting at radar blips. You can play it safe with or without a widget's help, because you know where the limit is and go well beyond it. If you want to toe the line, with or without the widget, you will often fail.
My point is that while you may still be making mistakes... you're making a lot fewer. Information is power, people. Be very, very wary about giving players any information about their opponent in a RTS.

At any rate, I'm done arguing, if you don't get it, too bad.
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: Range Widget, Alpha 2

Post by very_bad_soldier »

Argh wrote:No, it's not, dammit. One is having to spend time with a mouse over an object, zoom out, check vs. terrain, etc.- it takes a few seconds, minimum. The other is automated gimme. Totally different.
By that definition this widget is cheating too?
User avatar
Evil4Zerggin
Posts: 557
Joined: 16 May 2007, 06:34

Re: Range Widget, Alpha 2

Post by Evil4Zerggin »

Argh wrote:I suspect it's because the hardcore players just don't tell you coders how useful having that kind of information is, frankly.
Of course we know how useful it is. Why the hell do you think we program them?

As for showing enemy ranges: Maybe in your game it is cheating. But I think most of us take issue with the blanket statement that is is cheating, period.

If you want a "precision competition machine" (as someone put it) like Starcraft, I would suggest banning user LuaUI entirely, or pushing for a mod tag for it if it doesn't exist already.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Range Widget, Alpha 2

Post by Argh »

By that definition this widget is cheating too?
No, because it's controlled via customParams, which are all game-side. That's a pretty important distinction here- the game designer is making use of a Widget's capabilities, the Widget assumes nothing.
BeefofAges
Posts: 31
Joined: 21 Sep 2008, 20:07

Re: Range Widget, Alpha 2

Post by BeefofAges »

Are you seriously trying to claim that eliminating repetitive micro is cheating? Hearing this coming from a widget author is pretty silly. If you think about it, showing enemy range rings will actually make the game easier for newbies to learn. Newbies don't have ranges memorized, while good players do. Shouldn't we encourage an easier learning curve?
el_matarife
Posts: 933
Joined: 27 Feb 2006, 02:04

Re: Range Widget, Alpha 2

Post by el_matarife »

BeefofAges wrote:If you think about it, showing enemy range rings will actually make the game easier for newbies to learn. Newbies don't have ranges memorized, while good players do. Shouldn't we encourage an easier learning curve?
Obviously not if you want to force everyone into your play style, silly. How else are you supposed to be the best player at your own mod forever?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Range Widget, Alpha 2

Post by Argh »

I already said that I would allow P.U.R.E. to be played however people feel like it. I certainly wouldn't play with people who wanted to use 3rd-party Widgets, myself, but I have no fundamental objections about people who would like to do so, so long as all players are aware that they're not all playing the same game.

The problem is, most people aren't really all that cognizant of what a huge difference it makes, if one guy has some really... helpful... Widgets, and the other guy doesn't. The way I'm doing stuff... when players choose to play with third-party stuff, they'll know they're opening themselves to possible cheating- that's a fair choice, I think. The way it works right now is neither fair nor honest, imo.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Range Widget, Alpha 2

Post by Forboding Angel »

Argh, would it be particularly hard to make it show enemy units? I'm thinking right along the lines of beefofages here. Ppl don't play evo often and the game is really confusing for newbies and this would help out a TON if enemy unit ranges were shown.
el_matarife
Posts: 933
Joined: 27 Feb 2006, 02:04

Re: Range Widget, Alpha 2

Post by el_matarife »

Argh wrote: The problem is, most people aren't really all that cognizant of what a huge difference it makes, if one guy has some really... helpful... Widgets, and the other guy doesn't. The way I'm doing stuff... when players choose to play with third-party stuff, they'll know they're opening themselves to possible cheating- that's a fair choice, I think. The way it works right now is neither fair nor honest, imo.
If your concern is fairness, why not just ship with the widgets or point people to the really helpful ones? I mean, there's a remote possibility people could be writing private widgets and not passing them around the community, but the vast majority of "overly helpful" widgets are fully public? It isn't a rational response to ban all widgets because you are concerned your player base may not be fully informed in terms of widget options, or too lazy to get said widgets for themselves.
Post Reply

Return to “Lua Scripts”