Cmd Desc cycle both ways and assign states to keybind?

Cmd Desc cycle both ways and assign states to keybind?

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

Moderator: Moderators

Post Reply
User avatar
Zealot
Posts: 94
Joined: 03 Dec 2012, 13:53

Cmd Desc cycle both ways and assign states to keybind?

Post by Zealot »

Here is the gadget I am working on:

http://pastebin.com/BesqZgMC


Has anyone implement a way to cycle through a 3 state cmd desc button both forwards and backwards?


Also could some one point me in the right direction to assign each state of the cmd desc to a keybind?

I assume i should use the Lua callin "KeyPress()"

where in the gadget should I insert this?

Should I put it at the very bottom of the gadget code?

Gadget code with my first stab in the dark at coding keybinds to the comand:
http://pastebin.com/nTHRgnfV


The below code is what I added to attempt to make a keybind:

I would have to repeat this for each key i wanted to bind.
This is obviously needs work.
I don't know if there is a callin to give the id of what units the player has selected at a given time?

I have wrtten some pseudo code at the top to describe the steps i think need to be taken.

Code: Select all

   -------[[Keypress callin for reference:
KeyPress() --> "key, mods, isRepeat", where key = keymap, mods = SHIFT, etc.]]---

 ---------------how to write no mods? "false"?
 ------what does "isRepeat" do?

 --press the "y" letter on kb
--check if any units are selected by player
---are selected units on the units in the list of units that have the cmd --desc button.
--
--set the state of the button the state bound to that key

 function Gadget:KeyPress(y,false, false) 
    if unitselected then                      --what is the callin for this
          if STANCE[unitDefID] then  
  	     local cmdDescID =FindUnitCmdDesc(unitID,CMD_STANCE)
  			cmdDescID.cmdParams[1] = 1 
		end
	end  
  end
  
Thanks for help with this and thanks for all the help I have received so far.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Cmd Desc cycle both ways and assign states to keybind?

Post by CarRepairer »

Don't use keypress. Add "actions" by using widgethandler.addaction. You and the user can then bind keys to the action. You can make one action to go to the next state and one to go to the previous.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Cmd Desc cycle both ways and assign states to keybind?

Post by Google_Frog »

Here is a gadget which implements a 4 state toggle with forwards and backwards. http://code.google.com/p/zero-k/source/ ... r_dive.lua
User avatar
Zealot
Posts: 94
Joined: 03 Dec 2012, 13:53

Re: Cmd Desc cycle both ways and assign states to keybind?

Post by Zealot »

Thanks guys.

Ill get on to that later this week.

Spent all day today recoding unit voices with a voice actor.
Post Reply

Return to “Lua Scripts”