Hi,
i have a unit who builds things selected in the gui. I now want to select a building for placement. In such a way that the ghosted building becomes the mouse cursor.
How do i do that?
Spring.SetCommandActive seemed to be the candidate for that at first, but then i realized its just for taking commands into action from the queue.
Thanks for the help
How to set a building-unit into placement mode
Moderator: Moderators
Re: How to set a building-unit into placement mode
I assume you're talking about SetActiveCommand. How are you using it?SetCommandActive
This shouldn't work:
Code: Select all
Spring.SetActiveCommand(-UnitDefNames.peewee.id)
Code: Select all
local cmdIndex = Spring.GetCmdDescIndex(-UnitDefNames.peewee.id)
Spring.SetActiveCommand(cmdIndex)
Code: Select all
Spring.SetActiveCommand("buildunit_peewee")
Re: How to set a building-unit into placement mode
Code: Select all
function BuildHandler(button)
local alt, ctrl, meta, shift = Spring.GetModKeyState()
local _, _, lmb, mmb, rmb, outsideSpring = Spring.GetMouseState()
local opt = {}
if alt then push(opt,"alt") end
if ctrl then push(opt,"ctrl") end
if meta then push(opt,"meta") end
if shift then push(opt,"shift") end
if button==1 then
builderDefID= Spring.GetUnitDefID(facs[openedMenu+1].unitID)
if builderDefID and UnitDefs[builderDefID].isFactory then
Spring.GiveOrderToUnit(facs[openedMenu+1].unitID, -(facs[openedMenu+1].buildList[pressedBOpt+1]),{},opt)
else --select building and select build
Spring.SelectUnitArray({[1]=facs[openedMenu+1].unitID})
--TODO Find a solution here
--Spring.SetActiveCommand(-(facs[openedMenu+1].buildList[pressedBOpt+1]))
-- Spring.GiveOrderToUnit(facs[openedMenu+1].unitID, -facs[openedMenu+1].buildList[pressedBOpt+1], {}, opt)
end
Spring.PlaySoundFile(sound_queue_add, 0.95)
elseif button==3 then
push(opt,"right")
Spring.GiveOrderToUnit(facs[openedMenu+1].unitID, -(facs[openedMenu+1].buildList[pressedBOpt+1]),{},opt)
Spring.PlaySoundFile(sound_queue_rem, 0.97)
end
end
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: How to set a building-unit into placement mode
Perhaps the ActionCommand function in https://springrts.com/wiki/Chili:Example_3 answers your question?
-
- Moderator
- Posts: 2464
- Joined: 12 Oct 2007, 09:24
Re: How to set a building-unit into placement mode
This is how the ZK menu deals with button clicks (or key presses for hotkeys). https://github.com/ZeroK-RTS/Zero-K/blo ... #L555-L590
It handles factory queues and terraform. What you want should be this cut down version:
The cmdID is just -UnitDefID.
It handles factory queues and terraform. What you want should be this cut down version:
Code: Select all
local function ClickFunc(mouse, cmdID)
local left, right = mouse == 1, mouse == 3
local alt, ctrl, meta, shift = Spring.GetModKeyState()
local index = Spring.GetCmdDescIndex(cmdID)
if index then
Spring.SetActiveCommand(index, mouse or 1, left, right, alt, ctrl, meta, shift)
end
end
Re: How to set a building-unit into placement mode
Thanks - you all where right - it is spring.SetActivCommand- i was just using it wrong