REQ: Wiget Auto D-gun?
Posted: 25 Oct 2008, 21:20
That way you don't have to click on the G-gun button everytime when attacking something. I don't know how to program though...
Open Source Realtime Strategy Game Engine
https://springrts.com/phpbb/
Then you know everything about movement prediction?Super Mario wrote:I don't know how to program though...
Then he would shoot down anything behind the enemy unit(of course an if function is possible) and wouldn't be more effective than a skilled player because of possible less hits for more units if you know what I mean.Super Mario wrote:I just want the COM to shoot D-guns automatically when attacking something.
Code: Select all
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:GetInfo()
return {
name = "Auto D-Gunner",
desc = "Gives a d-gun order on units in range.",
author = "quantum",
date = "Oct, 26, 2008",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true -- loaded by default?
}
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local commIDs = {}
local lastAttack = 0
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function widget:UnitCreated(unitID, unitDefID)
if (UnitDefs[unitDefID].isCommander) then
for _, weaponData in ipairs(UnitDefs[unitDefID].weapons) do
local wd = WeaponDefs[weaponData.weaponDef]
if (wd.name:lower():find"disintegrator") then
commIDs[unitID] = wd.range
end
end
end
end
function widget:UnitDestroyed(unitID)
commIDs[unitID] = nil
end
function widget:Initialize()
for _, unitID in ipairs(Spring.GetAllUnits()) do
widget:UnitCreated(unitID, Spring.GetUnitDefID(unitID))
end
end
function widget:Update(dt)
if (Spring.GetGameSeconds() - lastAttack < 0.2) then
return
end
for unitID, range in pairs(commIDs) do
if (not Spring.GetUnitIsDead(unitID)) then
local nearestEnemy = Spring.GetUnitNearestEnemy(unitID, range)
if (nearestEnemy) then
Spring.GiveOrderToUnit(unitID, CMD.DGUN, { nearestEnemy },{})
lastAttack = Spring.GetGameSeconds();
end
end
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Code: Select all
Spring.GiveOrderToUnit(unitID, CMD.DGUN, { nearestEnemy },{})
Trying to get that working, along with a target movement prediction algorithm.Noruas wrote:Well its good but bad at the same time, it forces the commander to move by itself, if i could just move it and let the widget worry about the aiming part itd be great.
Face it and A.I. could D-gun BETTER! :DOtherside wrote:LEARN2DGUN
1.Then program the widget to not use the D-Gun when your energy is low.AF wrote:Using such a widget can be troublesome because:
Next time someone plays you they know to spam fleas early game and trick your commander into auto d-gunning your factory crippling you.
- 1.DGun can be expensive energywise in certain situations
2.Your now open to a horrible exploit where lots of cheap units surround commander and commander dguns, destroying hugely expensive base
3.DGun shots only work effectively when the unit is sitting still, otherwise you need to use predictive aiming
That's not what I was talking aboutOtherside wrote:LEARN2DGUN
When a swarm of enemy units surround your commander, believe me you have to D-gun them, AS FAST AS YOU CAN and besides you still have to click even though you already press D. I can D-gun a lot faster in FPS mode (which its frustrating when attacking something with a D-gun BTW)Tribulex wrote:noob
Also dont click, press D