Hi all,
im tryin to create a widget to place patrol and reclaim commands to mousebutton 4 and 5.
ingame this error occurs---> Error in mousepress () ... ...() bad unitid in parameter giveordertounit
function widget:GetInfo()
return {
name = "Mouse Reclaim/Patrol",
desc = "Use mousebuttons 4 and 5 for Reclaim/Patrol",
author = "Flash",
version = "v1.0",
date = "Dez, 2010",
license = "GNU GPL, v3 or later",
layer = 200,
enabled = true,
}
end
local spGetMyPlayerID = Spring.GetMyPlayerID
local spGetPlayerControlledUnit = Spring.GetPlayerControlledUnit
local GetPlayerControlledUnit = spGetPlayerControlledUnit
local GetMyPlayerID = spGetMyPlayerID
local function GetUnitID()
local unitID = GetPlayerControlledUnit(GetMyPlayerID())
return unitID
end
function widget:MousePress(mx, my, button)
local alt,ctrl,meta,shift = Spring.GetModKeyState()
-- Spring.Echo("Button pressed: " .. button)
if (button == 4) then
Spring.GiveOrderToUnit(GetUnitID(), CMD.PATROL);
return true
elseif (button == 5) then
Spring.GiveOrderToUnit(GetUnitID(), CMD.RECLAIM);
return true
end
return false
end
can anyone help me?
unitid problems cmd.patrol
Moderator: Moderators
Re: unitid problems cmd.patrol
isn't GetPlayerControlledUnit for FPS'd units or something?
you could do GiveOrderToUnitArray() and use GetSelectedUnits()
you could do GiveOrderToUnitArray() and use GetSelectedUnits()
Re: unitid problems cmd.patrol
GetPlayerControlledUnit only returns a unitID if a player is direct-controlling it (c-button FPS mode).
Also CMD.RECLAIM is CmdType CMDTYPE.ICON_UNIT_FEATURE_OR_AREA and CMD.PATROL is CmdType CMD.ICON_MAP, so when issuing the orders, you need to pass some parameters...
(HINT: you'll probably want to use
Also CMD.RECLAIM is CmdType CMDTYPE.ICON_UNIT_FEATURE_OR_AREA and CMD.PATROL is CmdType CMD.ICON_MAP, so when issuing the orders, you need to pass some parameters...
(HINT: you'll probably want to use
Code: Select all
Spring.TraceScreenRay
( number mouseX, number mouseY [, boolean onlyCoords [, boolean useMinimap] ] )
-> nil |
string "unit", number unitID |
string "feature", number featureID |
string "ground", { [1] = number x, [2] = number y, [3] = number z }
Re: unitid problems cmd.patrol
you basically want the extra mousebuttons to work as "P" on the keyboard? ie click mouse 4, cursor changes to patrol.
because GiveOrderToUnit wants more parameters for ie a patrol command. (x y z - location)
you probally do not want GiveOrderToUnit but something like ChangeActiveCommand <- no what its actually named or if exits.
because GiveOrderToUnit wants more parameters for ie a patrol command. (x y z - location)
you probally do not want GiveOrderToUnit but something like ChangeActiveCommand <- no what its actually named or if exits.
Re: unitid problems cmd.patrol
good point, knorke
Spring.SetActiveCommand
( string action [, string actionExtra ] ) -> nil | boolean
( number cmdIndex [, number button = 1
[, boolean leftClick, boolean rightClick,
boolean alt, boolean ctrl, boolean meta, boolean shift]] ) -> nil | boolean
-- so maybe this?
Spring.SetActiveCommand(CMD.RECLAIM)
Spring.SetActiveCommand(CMD.PATROL)
Spring.SetActiveCommand
( string action [, string actionExtra ] ) -> nil | boolean
( number cmdIndex [, number button = 1
[, boolean leftClick, boolean rightClick,
boolean alt, boolean ctrl, boolean meta, boolean shift]] ) -> nil | boolean
-- so maybe this?
Spring.SetActiveCommand(CMD.RECLAIM)
Spring.SetActiveCommand(CMD.PATROL)
Re: unitid problems cmd.patrol
ok thx guys. ill try my best :)
ill give you feedback asap.
ill give you feedback asap.
Re: unitid problems cmd.patrol
Spring.SetActiveCommand("Patrol") works thx!
function widget:GetInfo()
return {
name = "Mouse Reclaim/Patrol",
desc = "Use mousebuttons 4 and 5 for Reclaim/Patrol",
author = "Flash",
version = "v1.0",
date = "Dez, 2010",
license = "GNU GPL, v3 or later",
layer = 200,
enabled = true,
}
end
function widget:MousePress(mx, my, button)
local alt,ctrl,meta,shift = Spring.GetModKeyState()
-- Spring.Echo("Button pressed: " .. button)
if (button == 4) then
Spring.SetActiveCommand("Patrol");
return true
elseif (button == 5) then
Spring.SetActiveCommand("Reclaim");
return true
end
return false
end
would it be possible for units who cant reclaim to set command "Attack" or sth? (i.e. bombers, berthas, nukes...)
function widget:GetInfo()
return {
name = "Mouse Reclaim/Patrol",
desc = "Use mousebuttons 4 and 5 for Reclaim/Patrol",
author = "Flash",
version = "v1.0",
date = "Dez, 2010",
license = "GNU GPL, v3 or later",
layer = 200,
enabled = true,
}
end
function widget:MousePress(mx, my, button)
local alt,ctrl,meta,shift = Spring.GetModKeyState()
-- Spring.Echo("Button pressed: " .. button)
if (button == 4) then
Spring.SetActiveCommand("Patrol");
return true
elseif (button == 5) then
Spring.SetActiveCommand("Reclaim");
return true
end
return false
end
would it be possible for units who cant reclaim to set command "Attack" or sth? (i.e. bombers, berthas, nukes...)
Re: unitid problems cmd.patrol
if SetActiveCommand only sets the command if the selected units are capable of doing the command, then you can just GetActiveCommand afterwards and see if it was successfully set.
if this works and it wasn't set, you can try the next command (so try reclaim, if reclaim isn't selected, then try attack)
of course, this will only work if spring cares about SetActiveCommand applying to your selected units.
if this works and it wasn't set, you can try the next command (so try reclaim, if reclaim isn't selected, then try attack)
of course, this will only work if spring cares about SetActiveCommand applying to your selected units.
Re: unitid problems cmd.patrol
Spring.SetActiveCommand("Reclaim");
local zahl1, zahl2, zahl3, aCommand = Spring.GetActiveCommand()
if(aCommand == "Reclaim") then
else
Spring.SetActiveCommand("Attack");
works. thx aegis
dl link: http://www.springfiles.com/show_file.php?id=2881
local zahl1, zahl2, zahl3, aCommand = Spring.GetActiveCommand()
if(aCommand == "Reclaim") then
else
Spring.SetActiveCommand("Attack");
works. thx aegis
dl link: http://www.springfiles.com/show_file.php?id=2881
Re: unitid problems cmd.patrol
Some tips; You can use the _ operator to discard return values you don't need:
And if you want to be even neater, the select keyword:

Code: Select all
local _, _, _, aCommand = Spring.GetActiveCommand()
Code: Select all
local aCommand = select(4, Spring.GetActiveCommand())
