Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function widget:GetInfo()
- return {
- name = "Follow And Shove (v1.1)",
- desc = "giving a guard order while holding the alt key causes the selected units to constantly path to the selected unit",
- author = "AutoWar",
- date = "2015",
- license = "GNU GPL, v2 or later",
- layer = 9999,
- enabled = true
- }
- end
- -----------------------------------------------------------------
- local spGetUnitNearestEnemy = Spring.GetUnitNearestEnemy
- local spGetAllUnits = Spring.GetAllUnits --( ) -> nil | unitTable = { [1] = number unitID, ... }
- local spMarkerAddPoint = Spring.MarkerAddPoint
- local spEcho = Spring.Echo
- local spInsertUnitCmdDesc = Spring.InsertUnitCmdDesc
- local spGetUnitAllyTeam = Spring.GetUnitAllyTeam
- local spValidUnitID = Spring.ValidUnitID
- local spGetUnitPosition = Spring.GetUnitPosition
- local spGetUnitDefID = Spring.GetUnitDefID
- local spGiveOrderToUnit = Spring.GiveOrderToUnit
- local spGetUnitStates = Spring.GetUnitStates
- local spGiveOrderToUnitArray= Spring.GiveOrderToUnitArray
- local spGetUnitIsDead = Spring.GetUnitIsDead
- local spValidUnitID = Spring.ValidUnitID
- local spGetTeamUnits = Spring.GetTeamUnits --( number teamID ) -> nil | unitTable = { [1] = number unitID, etc... }
- local spGetMyTeamID = Spring.GetMyTeamID
- local spGetMyAllyTeamID = Spring.GetMyAllyTeamID
- local spIsUnitIcon = Spring.IsUnitIcon
- local myAllyID = Spring.GetMyAllyTeamID()
- local myTeamID = Spring.GetMyTeamID()
- local CMD_ATTACK = CMD.ATTACK
- local CMD_MOVE = CMD.MOVE
- local CMD_UNIT_SET_TARGET = 34923
- local spGetAllyTeamList = Spring.GetAllyTeamList --( ) -> { [1] = number allyTeamID, etc... }
- local spGetTeamList = Spring.GetTeamList --( [number allyTeamID = -1] ) -> nil | { [1] = number teamID, etc... }
- local spGetUnitTeam = Spring.GetUnitTeam --( number unitID ) -> nil | number teamID
- local CMD_LOAD_UNITS = CMD.LOAD_UNITS -- expect 1 parameter in return (unitid) or 4 parameters in return (mappos+radius)
- local spGetUnitTransporter = Spring.GetUnitTransporter --( number unitID ) -> nil | number unitID
- local spGetUnitIsTransporting = Spring.GetUnitIsTransporting --( number unitID ) -> nil | { [1] = number unitID, etc... }
- local spGetUnitHealth = Spring.GetUnitHealth --( number unitID ) -> nil | number health, number maxHealth, number paralyzeDamage, number captureProgress, number buildProgress
- local spGetUnitIsStunned = Spring.GetUnitIsStunned --( number unitID ) -> nil | boolean stunned_or_inbuild, boolean stunned, boolean inbuild
- local spGetUnitRulesParam = Spring.GetUnitRulesParam --( number unitID, number index | string ruleName ) -> nil | number value | string value
- local CMD_OPT_SHIFT = CMD.OPT_SHIFT --If the unit is working down a shift queue, add it seemless into it
- local CMD_INSERT = CMD.INSERT
- local spGetCommandQueue = Spring.GetCommandQueue --( number unitID, number count = 0 ) -> nil | number commandQueueSize, ( number unitID [, number count = -1] ) -> nil | table commandQueueTable = {[1] = {("id"=number),("params"={ [1]=number, ...}),("options"={"coded"=number,"alt"=boolean,"ctrl"=boolean,"shift"=boolean,"right"=boolean,"internal"=boolean,"meta"=boolean}}), ...}
- local spGetSelectedUnits = Spring.GetSelectedUnits --( ) -> { [1] = unitID, ... }
- local spGetGroundHeight = Spring.GetGroundHeight --(x,z)
- local CMD_CAPTURE = CMD.CAPTURE --expect 1 parameter in return (unitid) or 4 parameters in return (mappos+radius)
- local spGetUnitRulesParam = Spring.GetUnitRulesParam --( number unitID, number index | string ruleName ) -> nil | number value | string value
- local CMD_GUARD = CMD.GUARD --expect 1 parameters in return (unitid)
- -----------------------------------------------------------------
- -----------------------------------------------------------------
- local function Distance(x1,z1,x2,z2)
- return math.sqrt((x1-x2)^2 + (z1-z2)^2)
- end
- local function GetUnitName(unitID)
- if spValidUnitID(unitID)==true and spGetUnitDefID(unitID) then
- return UnitDefs[spGetUnitDefID(unitID)].name
- end
- end
- -----------------------------------------------------------------
- local ActivelyFollowingUnitsTable = {}
- function widget:UnitCommand(unitID, unitDefID, unitTeam, cmdId, cmdOpts, cmdParams,cmdTag)
- --spEcho(cmdId,cmdOpts,cmdParams[1])
- if cmdId==CMD_GUARD and cmdOpts==CMD.OPT_ALT then
- --spEcho(cmdId,cmdOpts)
- local targetID = cmdParams[1] --the target unit to follow
- local followerID = unitID --the unit following the target
- ActivelyFollowingUnitsTable[followerID]=targetID
- end
- if cmdId==0 and cmdParams[1]==nil then --give a stop order
- ActivelyFollowingUnitsTable[unitID]=nil --remove selected followers from widget's control
- end
- end
- function widget:GameFrame(frameNum)
- if frameNum%15==0 then
- for followerID,targetID in pairs(ActivelyFollowingUnitsTable) do
- --spEcho(followerID, targetID, spValidUnitID(followerID), spValidUnitID(targetID))
- if spValidUnitID(followerID)==true and spValidUnitID(targetID)==true then
- local x,y,z = spGetUnitPosition(targetID)
- --spEcho(followerID, targetID)
- spGiveOrderToUnit(followerID, CMD_MOVE, {x,y,z}, {"alt"})
- end
- end
- end
- end
- --[[
- Follow And Shove Command
- hotkey plus guard command will set the guarded unit as the mappos data source for move orders every second.
- uses altkey+gaurd
- v1.1 changelog
- update speed increased to twice per second
- ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement