Unit script have a menu button to switch between weapons
Moderator: Moderators
- Forboding Angel
 - Evolution RTS Developer
 - Posts: 14673
 - Joined: 17 Nov 2005, 02:43
 
Unit script have a menu button to switch between weapons
I want to make my gunships be able to switch between missiles and torpedos.
I'm sure this is possible, and maybe even easy, but I imagine that adding the command to the menu isn't.
I also imagine that lus is needed to do it, and that's fine, but I need some hand holding in this area.
I can haz halp?
			
			
									
						
										
						I'm sure this is possible, and maybe even easy, but I imagine that adding the command to the menu isn't.
I also imagine that lus is needed to do it, and that's fine, but I need some hand holding in this area.
I can haz halp?
Re: Unit script have a menu button to switch between weapons
http://www.youtube.com/watch?v=3MHkgwA8t-g
A video tutorial.. also zk-repo man.. they got everything. All the code. Sure there somewhere among all the thousands of gadgets, there is just what you need.
			
			
									
						
										
						A video tutorial.. also zk-repo man.. they got everything. All the code. Sure there somewhere among all the thousands of gadgets, there is just what you need.
- Forboding Angel
 - Evolution RTS Developer
 - Posts: 14673
 - Joined: 17 Nov 2005, 02:43
 
Re: Unit script have a menu button to switch between weapons
That was not helpful picasso.
			
			
									
						
										
						Re: Unit script have a menu button to switch between weapons
Take a look at artillery units in S44. They have 2 weapons (HE and smoke shells), toggleable via UI button. And they use COB scripts.
Any howitzer unit would do, for example gbr25pdr_stationary.
Gadget responsible for the trick: unit_smokeshells.lua
Relevant part is gadget:AllowCommand, it uses Spring.CallCOBScript to tell the unit script it should disable one weapon and enable the other.
			
			
									
						
										
						Any howitzer unit would do, for example gbr25pdr_stationary.
Gadget responsible for the trick: unit_smokeshells.lua
Relevant part is gadget:AllowCommand, it uses Spring.CallCOBScript to tell the unit script it should disable one weapon and enable the other.
Re: Unit script have a menu button to switch between weapons
Ok. Two paths, you enable one and block the other firing OR you morph the unit. I prefer the former over the latter.Forboding Angel wrote:I want to make my gunships be able to switch between missiles and torpedos.
Kampfer in gundam had it for years forb. Switching between anti-structure and anti-unit. Even though the code was ugly, I really always thought that unit was pretty cool! between this and the thrusters kicking in over water.Forboding Angel wrote:I'm sure this is possible, and maybe even easy, but I imagine that adding the command to the menu isn't.
Nah, possible in bos. I would *RATHER* you did LUS but you don't have to.Forboding Angel wrote:I also imagine that lus is needed to do it, and that's fine, but I need some hand holding in this area.
Re: Unit script have a menu button to switch between weapons
Don't use the morph path: that makes other units lose the target on the unit and possibly other problems.
			
			
									
						
										
						Re: Unit script have a menu button to switch between weapons
F is for former and first, L is for latter and latersmoth wrote:Ok. Two paths, you enable one and block the other firing OR you morph the unit. I prefer the former over the latter.Forboding Angel wrote:I want to make my gunships be able to switch between missiles and torpedos.
- Forboding Angel
 - Evolution RTS Developer
 - Posts: 14673
 - Joined: 17 Nov 2005, 02:43
 
Re: Unit script have a menu button to switch between weapons
Well, NixTux has been helping me implement a cob button switcher gadget that xta uses, but it's fairly inconsistent, and I think that is due to bos. Seems like a lot of issues come down to "because bos".
If I were to try to lus path, I would first need some way to convert this bos over to lus first ( http://pastebin.com/vw4effnt ). I can't do it from scratch.
That's the problem with lus, everyone is using this modular crap which may be great if you're already ass deep in it, but no one has just plain copy pasteable scripts that you could edit to your needs like bos scripts are.
Smoth, i rememebr you saying a long time ago, just wait till lus is common and you'll be able to have tons of examples to work with. Well that never happened, because the moment lus got popular, you flozi, and various others started working on these modular scripts that are great if you're starting from scratch, or are perfectly happy to rescript all of your units.
For the rest of us, we simply sit out in the cold. You can't really learn lus scripting from anything, because there are no complete examples out there.
If you care to prove me wrong, show me a lus example of a unit with a weapon, that does not rely on any includes. They might exist, but if they do, I've never seen them.
			
			
									
						
										
						If I were to try to lus path, I would first need some way to convert this bos over to lus first ( http://pastebin.com/vw4effnt ). I can't do it from scratch.
That's the problem with lus, everyone is using this modular crap which may be great if you're already ass deep in it, but no one has just plain copy pasteable scripts that you could edit to your needs like bos scripts are.
Smoth, i rememebr you saying a long time ago, just wait till lus is common and you'll be able to have tons of examples to work with. Well that never happened, because the moment lus got popular, you flozi, and various others started working on these modular scripts that are great if you're starting from scratch, or are perfectly happy to rescript all of your units.
For the rest of us, we simply sit out in the cold. You can't really learn lus scripting from anything, because there are no complete examples out there.
If you care to prove me wrong, show me a lus example of a unit with a weapon, that does not rely on any includes. They might exist, but if they do, I've never seen them.
Re: Unit script have a menu button to switch between weapons
Forb even my BOS scripts had includes.
I just put out a simple armcom for behe..
			
			
									
						
										
						I just put out a simple armcom for behe..
- Forboding Angel
 - Evolution RTS Developer
 - Posts: 14673
 - Joined: 17 Nov 2005, 02:43
 
Re: Unit script have a menu button to switch between weapons
I'm not talking about sfx and efx types, or smokeunit.smoth wrote:Forb even my BOS scripts had includes.
I just put out a simple armcom for behe..
Re: Unit script have a menu button to switch between weapons
As far as being left in the cold...
We have not withheld any knowledge flozi has several skeletons on one page in the wiki. And again the skeletons have nothing to do with modular anything!
The armcom behe has in bar is an improved version of my rx79 script from gundam which was a direct BOS conversion to Lua.
My general script is pretty readable as far as the places things go.
I do nothing fancy like meta tables yet.
I think your lack of confidence with Lua is the only thing holding you back. You only *think* it is harder than it is, you, can, do, this!
			
			
									
						
										
						We have not withheld any knowledge flozi has several skeletons on one page in the wiki. And again the skeletons have nothing to do with modular anything!
The armcom behe has in bar is an improved version of my rx79 script from gundam which was a direct BOS conversion to Lua.
My general script is pretty readable as far as the places things go.
I do nothing fancy like meta tables yet.
I think your lack of confidence with Lua is the only thing holding you back. You only *think* it is harder than it is, you, can, do, this!
- Forboding Angel
 - Evolution RTS Developer
 - Posts: 14673
 - Joined: 17 Nov 2005, 02:43
 
Re: Unit script have a menu button to switch between weapons
SinbadEV, learning lua is not the issue. Learning Spring's API is the hard part. Please don't interrupt.
			
			
									
						
										
						Re: Unit script have a menu button to switch between weapons
tutorials, examples and documentation about Lus:
http://springrts.com/wiki/Animation-LuaScripting
rescript 15 LOC bos to lus: $1 * -> http://zero-k.info/Forum/Thread/867 ? *²
*based on http://springrts.com/phpbb/viewtopic.ph ... 55#p549893
*²-ofc lines of code of the original bos script. empty lines or comments not counted obv.
-if i dont want to, i wont. so in this order: 1) link to a unitdef+script on svn 2) lus gets posted 3) ??? 4) profit
-lus without modular crap/includes
-batteries sold seperately.
			
			
									
						
										
						http://springrts.com/wiki/Animation-LuaScripting
rescript 15 LOC bos to lus: $1 * -> http://zero-k.info/Forum/Thread/867 ? *²
*based on http://springrts.com/phpbb/viewtopic.ph ... 55#p549893
*²-ofc lines of code of the original bos script. empty lines or comments not counted obv.
-if i dont want to, i wont. so in this order: 1) link to a unitdef+script on svn 2) lus gets posted 3) ??? 4) profit
-lus without modular crap/includes
-batteries sold seperately.
- Forboding Angel
 - Evolution RTS Developer
 - Posts: 14673
 - Joined: 17 Nov 2005, 02:43
 
Re: Unit script have a menu button to switch between weapons
Yet no one can point to a full script.
You know... if someone said, "Hey guys, I am learning bos and I need an example of a tank with just a turret and a single weapon, could someone hook me up?"
I would say, "Hey! No problem! Here you go and GL! https://code.google.com/p/evolutionrts/ ... ttank3.bos "
Yet here, I get links to bits and pieces of semi-relevant information. That is a perfect example of what I've been talking about. With lus, you can't just get a script of something that you can study and cannibalize. That enters "wtf" territory.
This is semi-useful: http://tvo.github.io/spring/2010/04/19/lus-stumpy.html
Still no full script though. Ffs. At least it looks like most of the important pieces are there. Enough to patch something together.
			
			
									
						
										
						I don't really understand what this means?
You know... if someone said, "Hey guys, I am learning bos and I need an example of a tank with just a turret and a single weapon, could someone hook me up?"
I would say, "Hey! No problem! Here you go and GL! https://code.google.com/p/evolutionrts/ ... ttank3.bos "
Yet here, I get links to bits and pieces of semi-relevant information. That is a perfect example of what I've been talking about. With lus, you can't just get a script of something that you can study and cannibalize. That enters "wtf" territory.
This is semi-useful: http://tvo.github.io/spring/2010/04/19/lus-stumpy.html
Still no full script though. Ffs. At least it looks like most of the important pieces are there. Enough to patch something together.
Re: Unit script have a menu button to switch between weapons
what important pieces are gone?
			
			
									
						
										
						Re: Unit script have a menu button to switch between weapons
Why only semi-useful?This is semi-useful: http://tvo.github.io/spring/2010/04/19/lus-stumpy.html
Still no full script though. Ffs.
You asked for "example of a tank with just a turret and a single weapon", it is excactly that. It is complete code too.
Read that tutorial. Then check the links again and you will notice they are not "semi-relevant" at all - it is all you need.
For small donation to spring server I rescript bos to lus.I don't really understand what this means?
- Forboding Angel
 - Evolution RTS Developer
 - Posts: 14673
 - Joined: 17 Nov 2005, 02:43
 
Re: Unit script have a menu button to switch between weapons
Because nowhere in this tutorial is the entire unit script posted. It's all in segments. So if I want to view it in it's entirety, I have to join it all together, which is a pain in the ass.knorke wrote:Why only semi-useful?This is semi-useful: http://tvo.github.io/spring/2010/04/19/lus-stumpy.html
Still no full script though. Ffs.
It is complete code too.
Oh. Well, that's nice of you. I might take you up on that for some of the more complicated scripts, but tbh, I'd rather figure it out for myself. All I want is a complete simple unit script that has all the necessary bits in it. Apparently that is far too much to ask, so apparently I'll have to do it myself.knorke wrote:For small donation to spring server I rescript bos to lus.I don't really understand what this means?
Let me point out that the lua language is not my problem. Learning lua isn't the issue, it's learning how all this crap hooks in with spring and learning springs magic tables, etc etc etc that is the hard part, as well as how some of the logic works out. Lua itself isn't particularly difficult, metatables being the exception. I read up on the extensively and I still don't even...
I know what they do, I understand how they work, blah blah blah. It's just that particular part is very complicated. I am told, however, that usage of metatables in spring is quite rare if non-existent though, so not to worry about it.
Lua's syntax is wonky as hell, but whatever, it's not that complicated. Once you start working with spring... That is where things get complicated.
I'll throw something together based upon tobi's examples.
If someone could translate this into lua I would be grateful though:
Code: Select all
setSFXoccupy(setSFXoccupy_argument) {
	terraintype = setSFXoccupy_argument;
	if(terraintype == 2) {
		move base to y-axis [-0.5] speed [50];
		show lilypad;
	} else {
		move base to y-axis [0] speed [50];
		hide lilypad;
	}
	if(terraintype == 4) {
		move base to y-axis [0] speed [50];
		hide lilypad;
	} else {
		move base to y-axis [-0.85] speed [50];
		show lilypad;
	}
}
Re: Unit script have a menu button to switch between weapons
There are tons of things that comprise a "complete" script. You are asking for a very specific thing but have yet to set down requirements.Forboding Angel wrote:All I want is a complete simple unit script that has all the necessary bits in it.
Forboding Angel wrote: Apparently that is far too much to ask, so apparently I'll have to do it myself.
oh my god have a full script! I am not pastebining because I don't want to hear that later the thing disappeared when the site decided to purge old entries.
Code: Select all
-------------------------------------------------------
-- License:	Public Domain
-- Author:	Steve (Smoth) Smith
-- Date:	4/19/2014
-------------------------------------------------------
-- Piece names
	head		= piece 'torso'
	base		= piece 'torso'
	l_arm		= piece 'luparm'
	l_forearm	= piece 'biggun'
	r_arm		= piece 'ruparm'
	r_forearm	= piece 'rloarm'
	lflare		= piece 'lflare'
	nano		= piece 'nano'
	laserflare	= piece 'laserflare'
	cod			= piece 'pelvis'
	right_l		= piece 'rthigh'
	left_l		= piece 'lthigh'
	shin_l		= piece 'lleg'
	shin_r		= piece 'rleg'
	foot_r		= piece 'rfoot'
	foot_l		= piece 'lfoot'
	dish		= piece 'dish'
-- State variables
	isMoving, isAiming, isBuilding = "derpy spring", "derpy spring", "derpy spring"
-- used to restore build aiming
	buildY, buildX	= 0, 0
	firedWeapon		= false
-- Unit Speed
	speedMult		=	2.4
-- Unit animation preferences
	leftArm		=	true;
	rightArm	=	true;
	heavy		=	true;
			
-- Signal definitions
local SIG_AIM			=	2
local SIG_WALK			=	4
-- effects for emitters
local effectA = 1024
local effectB = 1025
--local SMOKEPIECE1 = base
local	inStance	= false
function walk()
	Signal(SIG_WALK)
	SetSignalMask(SIG_WALK)	
	
	Turn(right_l, z_axis, 0, math.rad(135))
	Turn(left_l, z_axis, 0, math.rad(130))
	Turn(foot_l, y_axis, 0, math.rad(130))
	Turn(foot_r, y_axis, 0, math.rad(130))
	Turn(foot_l, x_axis, 0, math.rad(130))
	Turn(foot_r, x_axis, 0, math.rad(130))
	Turn(foot_l, z_axis, 0, math.rad(130))
	Turn(foot_r, z_axis, 0, math.rad(130))
	
	Turn(right_l, y_axis, 0, math.rad(135))
	Turn(left_l, y_axis, 0, math.rad(130))
	
	while true do
		if (isAiming == false) then
			if (leftArm == true ) then
				Turn(l_arm, x_axis, math.rad(-25), math.rad(35 * speedMult))
			end
			if (rightArm == true ) then
				Turn(r_arm, x_axis, math.rad(25), math.rad(45 * speedMult)) 
			end
			Turn(base, y_axis, math.rad(-5), math.rad(25 * speedMult))
			Turn(base, z_axis, math.rad(2), math.rad(2 * speedMult))
		end
		Turn(shin_r, x_axis, math.rad(85), math.rad(137.5 * speedMult))	
		Turn(right_l, x_axis, math.rad(-60), math.rad(70 * speedMult))
		Turn(left_l, x_axis, math.rad(30), math.rad(70 * speedMult))
		Sleep(600/speedMult)
		Move(cod, y_axis, 0.8, 40)
		
		Sleep(500/speedMult)	
		
		Turn(shin_r, x_axis, math.rad(10), math.rad(185 * speedMult))
		
		Move(cod, y_axis, -3, 20)
		if (isAiming == false) then
			if (rightArm == true ) then
				Turn(r_arm, x_axis, math.rad(-25), math.rad(35 * speedMult))
			end
			if (leftArm == true ) then
				Turn(l_arm, x_axis, math.rad(25), math.rad(45 * speedMult)) 
			end
			Turn(base, y_axis, math.rad(5), math.rad(25 * speedMult))
			Turn(base, z_axis, math.rad(-2), math.rad(2 * speedMult))
		end
		Turn(shin_l, x_axis, math.rad(85), math.rad(137.5 * speedMult))
		Turn(left_l, x_axis, math.rad(-60), math.rad(70 * speedMult))
		Turn(right_l, x_axis, math.rad(30), math.rad(70 * speedMult))
		Sleep(658/speedMult)
		Move(cod, y_axis, 0.8, 40)
		
		Sleep(500/speedMult)
		Turn(shin_l, x_axis, math.rad(10), math.rad(185 * speedMult))
		
		Move(cod, y_axis, -3, 20)
	end
end
function poser()
	Signal(SIG_WALK)
	SetSignalMask(SIG_WALK)	
	if(heavy == true ) then
		SquatStance()
	else
		StandStance()
	end
end
function StandStance()
	Sleep(200)
	Move(cod, y_axis, 0, now)
	Turn(base, z_axis, 0, now)
	Signal(SIG_WALK)
	SetSignalMask(SIG_WALK)	
	
	Move(cod, y_axis, math.rad(-0.5), math.rad(8000))
	
	Turn(base, x_axis, math.rad(-2), math.rad(395))
	if (isAiming == false) then
		if (leftArm == true ) then
			Turn(l_arm, x_axis, math.rad(10), math.rad(395))
			Turn(l_arm, y_axis, math.rad(5), math.rad(395))
			Turn(l_arm, z_axis, math.rad(9), math.rad(395))
			Turn(l_forearm, x_axis, math.rad(-38), math.rad(395))
		end
		if (rightArm == true ) then
			Turn(r_arm, x_axis, math.rad(10), math.rad(395))
			Turn(r_arm, y_axis, math.rad(-5), math.rad(395))
			Turn(r_arm, z_axis, math.rad(-9), math.rad(395))
			Turn(r_forearm, x_axis, math.rad(-38), math.rad(395))
		end
	end
	
	Turn(right_l, x_axis, 0, math.rad(235))
	Turn(right_l, y_axis, math.rad(-18), math.rad(135))	
	Turn(right_l, z_axis, math.rad(-15), math.rad(135))
	
	Turn(left_l, x_axis, 0, math.rad(235))
	Turn(left_l, y_axis, math.rad(18), math.rad(135))	
	Turn(left_l, z_axis, math.rad(15), math.rad(135))
	
	Turn(shin_l, x_axis, 0, math.rad(235))
	Turn(shin_r, x_axis, 0, math.rad(230))
	Turn(foot_l, x_axis, math.rad(1), math.rad(395))
	Turn(foot_l, y_axis, math.rad(5), math.rad(130))
	Turn(foot_l, z_axis, math.rad(-15), math.rad(130))
	
	Turn(foot_r, x_axis, math.rad(1), math.rad(395))
	Turn(foot_r, y_axis, math.rad(-5), math.rad(130))
	Turn(foot_r, z_axis, math.rad(15), math.rad(130))
	Sleep(0)
end
function SquatStance ()
	Sleep(200)
	Signal(SIG_WALK)
	SetSignalMask(SIG_WALK)	
	
	Move(cod, y_axis, -3, now)
	Turn(base, z_axis, 0, now)
	
	Turn(base, x_axis, math.rad(5), math.rad(395))
	Turn(cod, x_axis, math.rad(-5), math.rad(395))
	
	if (isAiming == false) then
		if (leftArm == true ) then
			Turn(l_arm, x_axis, math.rad(15), math.rad(395))
			Turn(l_arm, y_axis, math.rad(5), math.rad(395))
			Turn(l_arm, z_axis, math.rad(10), math.rad(395))
			Turn(l_forearm, x_axis, math.rad(-50), math.rad(395))
		end
		if (rightArm == true ) then
			Turn(r_arm, x_axis, math.rad(15), math.rad(395))
			Turn(r_arm, y_axis, math.rad(-5), math.rad(395))
			Turn(r_arm, z_axis, math.rad(-10), math.rad(395))
			Turn(r_forearm, x_axis, math.rad(-50), math.rad(395))
		end
	end
	
	Turn(right_l, x_axis, math.rad(-24), math.rad(235))
	Turn(right_l, y_axis, math.rad(-10), math.rad(135))	
	Turn(right_l, z_axis, math.rad(-20), math.rad(135))
	
	Turn(left_l, x_axis, math.rad(-24), math.rad(235))
	Turn(left_l, y_axis, math.rad(10), math.rad(135))	
	Turn(left_l, z_axis, math.rad(20), math.rad(135))
	
	Turn(shin_l, x_axis, math.rad(45), math.rad(235))
	Turn(shin_r, x_axis, math.rad(45), math.rad(230))
	Turn(foot_l, x_axis, math.rad(-11), math.rad(395))
	Turn(foot_l, y_axis, math.rad(10), math.rad(130))
	Turn(foot_l, z_axis, math.rad(-20), math.rad(130))
	
	Turn(foot_r, x_axis, math.rad(-11), math.rad(395))
	Turn(foot_r, y_axis, math.rad(-10), math.rad(130))
	Turn(foot_r, z_axis, math.rad(20), math.rad(130))
	LookAround()
	Sleep(0)
end
function FixArms(leftflag, rightflag)
	Turn(l_arm, z_axis, 0, math.rad(395))
	Turn(r_arm, z_axis, 0, math.rad(395))
	
	if (leftflag == true ) then
		Turn(l_arm, x_axis, 0, math.rad(395))
		Turn(l_arm, y_axis, 0, math.rad(395))
		Turn(l_forearm, x_axis, 0, math.rad(395))
	end
	if (rightflag == true ) then
		Turn(r_arm, x_axis, 0, math.rad(395))
		Turn(r_arm, y_axis, 0, math.rad(395))
		Turn(r_forearm, x_axis, 0, math.rad(395))
	end
end
function Dash(leftflag, rightflag)
	Turn(head, x_axis, math.rad(-20), math.rad(395))
	Turn(cod, x_axis, math.rad(20), math.rad(395))
	
	if (isAiming == false) then
		Turn(l_arm, x_axis, math.rad(30), math.rad(395))
		Turn(l_arm, y_axis, math.rad(10), math.rad(395))
		Turn(l_forearm, x_axis, math.rad(-45), math.rad(395))
		Turn(r_arm, x_axis, math.rad(30), math.rad(395))
		Turn(r_arm, y_axis, math.rad(-10), math.rad(395))
		Turn(r_forearm, x_axis, math.rad(-45), math.rad(395))
	end
	
	Turn(right_l, x_axis, math.rad(-50), math.rad(235))
	
	Turn(left_l, x_axis, math.rad(40), math.rad(235))
	
	Turn(shin_l, x_axis, 0, math.rad(235))
	Turn(shin_r, x_axis, math.rad(90), math.rad(230))
	Turn(foot_l, x_axis, math.rad(20), math.rad(395))
	
	Turn(foot_r, x_axis, math.rad(20), math.rad(395))
	Sleep(50)
end
function AmIBored()
	return isAiming == false and isBuilding == false and isMoving == false
end
function LookAround()
	while true do
		if AmIBored() then
			Turn(base, y_axis, 0, 5)
			local randomRotDegrees	= math.random(10, 50)
			local randomRotRadians	= math.rad(randomRotDegrees)
			randomAnim = math.random(1, 3)	
			if randomAnim >= 2  and AmIBored() then
				Turn(base, y_axis, randomRotRadians, 0.34*randomAnim)
				Turn(head, y_axis, randomRotRadians/2, 0.18*randomAnim)
				Sleep(400)
			end
			
			if randomAnim == 2 and AmIBored() then
				if (isAiming == false and isMoving  == false) then
					Turn(r_arm, x_axis, -1.1, randomRotDegrees/10)
					Turn(l_arm, x_axis, 0.1, 2)
					Sleep(400)
				end		
			else
				Turn(r_arm, x_axis, -0.15, 0.18)
				Turn(l_arm, x_axis, 0.1, 2)
				Sleep(400)
			end
			if randomAnim <= 2 and AmIBored() then
				Turn(base, y_axis, -randomRotRadians, 0.34*randomAnim)
				Turn(head, y_axis, -randomRotRadians/2, 0.18*randomAnim)
				Sleep(400)
			end
			if AmIBored() then
				Sleep(500)
			end
				
			if randomAnim == 1 and AmIBored() then
				Turn(r_arm, x_axis, 0.1, 2)
				Turn(l_arm, x_axis, -randomRotDegrees/95, randomRotDegrees/20)
				Sleep(400)
			else
				if randomAnim == 2 then
				Turn(r_arm, x_axis, 0.1, 0.1)
				else
					Turn(r_arm, x_axis, 0.1, 0.5)
				end
				Turn(l_arm, x_axis, -0.15, 0.18)
				Sleep(500)
			end
			Sleep(600)
		else-- not aiming, not building oh lawd!
			Sleep(600)		
		end
	end
end
function MotionControl()
	idleTimer = 0
	while (1) do
		if ( isMoving and isMoving == true ) then
			inStance = false
			--StartThread(walk)
		else
		-- we only want to run the standing animation once			
		end
		Sleep(50)
	end
end 
function script.StartMoving()
	isMoving = true
	StartThread(walk)
end
function script.StopMoving()
	isMoving = false
	StartThread(poser)
end	
--------------------------------------------------------
--start ups :)
--------------------------------------------------------
function script.Create()
	-- Initial State
	
	Turn(r_forearm, x_axis, math.rad(-15),math.rad(130))
	Turn(lflare, x_axis,math.rad(90))
	Turn(nano, x_axis,math.rad(90))
	Turn(laserflare, x_axis,math.rad(90))
	Spin(dish, y_axis, 2.5)
	
	-- because DERP
	isAiming	= false	
    isBuilding	= false
	isMoving	= false
	
	if(heavy == true ) then
		SquatStance()	
	else
		StandStance()
	end
	-- should do this instead of query nano piece
	--Spring.SetUnitNanoPieces( unitID, {nano} )
end
-----------------------------------------------------------------------
--function to restore the aim if construction was interupted by combat
-----------------------------------------------------------------------	
function ResumeBuilding()
	sleep(400)
	
    if isBuilding and firedWeapon then
	   Turn(base, y_axis, buildY, 2.618)
	   Turn(r_arm, x_axis, 0.5235 - buildx, 2.618 )
    end
end
-----------------------------------------------------------------------
--gun functions;
-----------------------------------------------------------------------	
function script.AimFromWeapon(weaponID)
	if weaponID == 3 then
		return l_arm
	else
		return r_arm
	end
end
function script.QueryWeapon(weaponID)
	if weaponID == 3 then
		return lflare
	else
		return laserflare
	end
end
-----------------------------------------------------------------------
-- This coroutine is restarted with each time a unit reaims, 
-- not the most efficient and should be optimized. Possible
-- augmentation needed to lus.
-----------------------------------------------------------------------
local function RestoreAfterDelayLeft()
	Sleep(1000)
	
	Turn(base, y_axis, 0, math.rad(105))
	Turn(l_forearm, x_axis, math.rad(-38), math.rad(95))
	Turn(l_arm, x_axis, math.rad(15), math.rad(95))
	isAiming = false
end
local function RestoreAfterDelayRight()
	Sleep(1000)
	
	Turn(base, y_axis, 0, math.rad(105))
	Turn(r_forearm, x_axis, math.rad(-38), math.rad(95))
	Turn(r_arm, x_axis, math.rad(15), math.rad(95))
	
	isAiming = false
end
function script.AimWeapon(weaponID, heading, pitch)
	
	-- weapon2 is supposed to only fire underwater, check for it.
	if weaponID == 2 then
		local _, basepos, _ = Spring.GetUnitPosition(unitID) 
		if basepos > -16 then
			return false
		end
	end 
	
	--Spring.Echo("AimWeapon " .. weaponID)
	Signal(SIG_AIM)
	SetSignalMask(SIG_AIM)
	isAiming = true
		
	if weaponID == 1 or weaponID == 2 then
		FixArms(false, true)
		
		Turn(base, y_axis, heading, math.rad(105))
		Turn(r_forearm, x_axis, math.rad(-55), math.rad(390))
		Turn(r_arm,	x_axis, math.rad(-45) - pitch, math.rad(390))
		
		Sleep(200)
		WaitForTurn(base, y_axis)
		WaitForTurn(r_arm, x_axis)
		WaitForTurn(r_forearm, x_axis)
		--Spring.Echo("AimWeapon " .. weaponID .. " done turning")
		StartThread(RestoreAfterDelayRight)
				
		firedWeapon		= false
		-- if I was buidling restore my arm position
		if (isBuilding == true) then
		--	ResumeBuilding();
		end
		
		--Spring.Echo("AimWeapon " .. weaponID .. " end")
		return true
	elseif weaponID == 3 then
		FixArms(true, false)
		
		Turn(base, y_axis, heading, math.rad(105))
		Turn(l_forearm, x_axis, math.rad(-85), math.rad(390))
		Turn(l_arm,	x_axis, math.rad(-5) - pitch, math.rad(390))
		
		Sleep(200)
		WaitForTurn(base, y_axis)
		WaitForTurn(l_arm, x_axis)
		WaitForTurn(l_forearm, x_axis)
		--Spring.Echo("AimWeapon done turning")
		StartThread(RestoreAfterDelayLeft)
		
		firedWeapon		= false
		-- if I was buidling restore my arm position
		if (isBuilding == true) then
		--	ResumeBuilding();
		end
		
		--Spring.Echo("AimWeapon end")
		return true
	else
		return false	
	end	
end
function script.FireWeapon(weaponID) 	
	Sleep(500)
	firedWeapon		= true
end
-----------------------------------------------------------------------
-- I dunno, a bunch of stuff I hastily ported to lua.
-----------------------------------------------------------------------
function script.QueryNanoPiece()
	return nano
end
function script.StartBuilding(heading, pitch)
--	Spring.Echo("StartBuilding")
	IsFiringDgun	= 0;
	isBuilding		= true;
	buildY, buildX	= heading, pitch
	
	Turn(base, y_axis, heading, math.rad(105))
	Turn(r_forearm, x_axis, math.rad(-55), math.rad(390))
	Turn(r_arm,	x_axis, math.rad(-55) - pitch, math.rad(390))
	WaitForTurn(r_arm, x_axis)
	SetUnitValue(COB.INBUILDSTANCE, 1)
end
function script.StopBuilding()
	Sleep(200)
	isBuilding		= false;
	SetUnitValue(COB.INBUILDSTANCE, 0)
--	Spring.Echo("Stop Building", isAiming, isBuilding, isMoving)
end
-----------------------------------------------------------------------
-- death stuffs
-----------------------------------------------------------------------	
function script.Killed(recentDamage, maxHealth)
	-- fall over
	Turn(cod, x_axis, math.rad(270), 5)	
	-- reset parts
	Turn(base, y_axis, 0, 8)	
	Turn(r_arm, z_axis, 4, 3)
	Turn(l_arm, z_axis, -4, 3)
	-- fall
	Move(cod, y_axis, -30, 100)
	Turn(base, x_axis, 0.5, 8)
	Turn(right_l, x_axis, -0.5, 8)
	Turn(left_l, x_axis, -0.5, 8)			
	WaitForMove(cod, y_axis)
	-- land
	Turn(r_forearm, x_axis, 0, 5)
	Turn(l_forearm, x_axis, 0, 5)
	Move(cod, y_axis, -35, 200)	
	Turn(base, x_axis, 0, 10)
	Turn(right_l, x_axis, 0, 10)
	Turn(left_l, x_axis, 0, 10)
	WaitForMove(cod, y_axis)
	
	local severity = recentDamage/maxHealth
	if (severity <= 99) then
		Explode(l_arm, SFX.FALL)
		Explode(r_arm, SFX.FALL)
		Explode(l_arm, SFX.FALL)
		Explode(l_forearm, SFX.FALL)
		Explode(r_arm, SFX.FALL)
		Explode(r_forearm, SFX.FALL)
		return 3
	else
		return 0
	end
endthis stuff is not hard.
Re: Unit script have a menu button to switch between weapons
http://tvo.github.io/spring/2010/04/19/ ... the_stumpy
It says "This example makes the weapon of the stumpy fully functional. Here is the complete code:"
			
			
									
						
										
						It says "This example makes the weapon of the stumpy fully functional. Here is the complete code:"
