Weapons Selection

Weapons Selection

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

Weapons Selection

Post by Von66341 »

Hi,

I was wondering if it is possible to like create a button for each specific weapon of a unit so the user could choose which weapon and select which enemy to attack?

For e.g.
If I have a tank, and have weapon 1 and weapon 2
Is it possible for the user to select weapon 1 then the enemy 1 to use weapon 1 on the enemy?
User avatar
MidKnight
Posts: 2652
Joined: 10 Sep 2008, 03:11

Re: Weapons Selection

Post by MidKnight »

use weapon 1 then the user to like create a tank, and have a tank, and select weapon 2 Is it possible for each specific weapon and select which enemy to attack?


Actual answer: You can, but you'll have to write a lua gadget for it.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Weapons Selection

Post by smoth »

To have a weapon that can be chosen to be fired requires a custom command and some script-fu
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Weapons Selection

Post by knorke »

without much scripting, dgun weapons (i think the tag is commandFire=1 or something) might work.
rightclick on enemy or a-click: weapon 1
d-click: weapon 2 (weapon does not fire on its own)
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Weapons Selection

Post by smoth »

dgun weapons will all fire at once on the dgun command.
Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

Re: Weapons Selection

Post by Von66341 »

Dgun doesn't seem to work as well as it meant to.
Sometimes I can fire the weapon from my ship sometimes I couldn't.

Anyway, I was thinking of creating a button that fires weapon 1 to where the cursor is.
I know how to create a new command and draw the box etc.

But how do I call the command attack for that specific weapon only?
Spring.GiveOrderToUnit?

Thanks!
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Weapons Selection

Post by KDR_11k »

You'll have to use SetWeaponTarget IIRC.
Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

Re: Weapons Selection

Post by Von66341 »

Spring.SetUnitTarget??

I couldn't find anything on Spring.SetWeaponTarget

How I should go about writing the script/gadget?
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Weapons Selection

Post by Google_Frog »

Forgoing a gadget and writing something in the unit script seems more appropriate. Only a small link in gadget would be needed to add the command to the unit.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Weapons Selection

Post by knorke »

ITT: trivial thing can not be done because knowledge about unit weapons or adding buttons to units is only passed trough complex rituals that shall not be written down.
I know how to create a new command and draw the box etc.
How?
Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

Re: Weapons Selection

Post by Von66341 »

An example for the command is here: http://pastebin.com/fY6YRsqk
I create a command to on/off radar function in certain units.

Hmm...so there won't be anyway to turn on/off weapons?
Something like the radar I did. For e.g. if I click weapon A button, the rest of the button will off and the unit will attack only with that specific weapon?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Weapons Selection

Post by knorke »

Von66341 wrote:An example for the command is here: http://pastebin.com/fY6YRsqk
I create a command to on/off radar function in certain units.
thanks.
Von66341 wrote:Hmm...so there won't be anyway to turn on/off weapons?
I think something like turning a weapon on and off is not hard, I'll try that later. Or toggling between gun and rocket launcher.

But if the player should be able to select unique targets for each weapon (ie like laser & dgun do for TA commanders or all the abilities of WC3 units) I would not know how to do that except with "dgun" (commandfire=1) But I think it is possibly too, ie the mine launcher of the Byte or the flame thing of the Pointer in KP let you click a button on the unit and then select a location.
Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

Re: Weapons Selection

Post by Von66341 »

Thanks for the help knorke! If you manage to turn on/off weapons do share the inspirations =)
Oh ya, what is WC3?

Check with you for the dgun command if want it to work we have to key the following:

canDGun = 1; --in the .fb file (unitdef file)

commandfire = 1; -- in the .tdf file (weapondef file)

So any weapon with the commandfire tag will fire when the Dgun button is press?


Toggling weapon is done in Gundam RTS. But am not quite sure how I should implement it into say a tank/ship. Any suggestiosn anyone?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Weapons Selection

Post by knorke »

Some quick test, instead of custom buttons I just used the the on/off button that you get with onoffable=true in the unitdef:

Code: Select all

local activeWeapon = 1
----------
function script.Activate ( )
	activeWeapon = 1
end
function script.Deactivate ( )
	activeWeapon = 2
end
So "on" means weapon 1, "off" means weapon 2

Then I just return false in AimWeapon if that weapon should be blocked:

Code: Select all

----SHOOT rocket launcher
function script.QueryWeapon1() return flare end

function script.AimFromWeapon1() return head end

function script.AimWeapon1( heading, pitch )
	if (activeWeapon ~=1) then return false end
	Signal(SIG_AIM)
	SetSignalMask(SIG_AIM)
--aiming animation bla
	return true
end

-----SHOOT grenade
function script.QueryWeapon2() return grenade end

function script.AimFromWeapon2() return head end --base

function script.AimWeapon2( heading, pitch )
	if (activeWeapon ~=2) then return false end
--aiming animation bla
	return true
end
Works, but if the weapons have differant ranges it is problematic because the unit will not get close to use the short ranged weapon. :roll:
Sadly http://answers.springlobby.info/questio ... ent-ranges has no answer yet.

To use that with the custom buttons you would have a function like

Code: Select all

function switchToWeapon (weaponNumber)
  activeWeapon = weaponNumber
end
And to call it from the gadget you would do

Code: Select all

env = Spring.UnitScript.GetScriptEnv(unitID)
if (env) then Spring.UnitScript.CallAsUnit(unitID, env.switchToWeapon, weaponNumber) end
well, you probally knew to do it that way...but i just realized the weapon stuff never worked good for me so thats all.
Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

Re: Weapons Selection

Post by Von66341 »

local activeWeapon = 1
----------
function script.Activate ( )
activeWeapon = 1
end
function script.Deactivate ( )
activeWeapon = 2
end
Check with ya, where did you write this portion of the code? Script or unitdef? How did you link the on/off button with the script?

Mind sharing your full code?
Cause would like to see how it works.
Say if you on the on/off button, only weapon 1 will fire when you click attack?
What happens when we do nothing but the unit sight an enemy? weapon 1 or 2 will be use? or it depends on the state of the on/off button?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Weapons Selection

Post by knorke »

Check with ya, where did you write this portion of the code? Script or unitdef?
in the unitscript.
How did you link the on/off button with the script?
The engine does that. If the unit is switched on, function script.Activate ( ) is called, if it is switched off, function script.Deactivate ( ) is called.
Say if you on the on/off button, only weapon 1 will fire when you click attack?
yes.
What happens when we do nothing but the unit sight an enemy? weapon 1 or 2 will be use? or it depends on the state of the on/off button?
depends on the state of the on/off button.

Basic idea is that "Only if AimWeapon returns true, the weapon is actually fired."
http://springrts.com/wiki/Animation-LuaCallins#Weapons
But it only "plugs up" the barrel so to speak, the unit will not chose a unit target, it simply will not fire.
So you could use that for other things too, for example
if (Spring.GetUnitHealth (unitID) < 400) then return false end
to prevent the weapon from working if the unit has less then 400 hitpoints.
Mind sharing your full code?
That is the full code ;) Well, there is other stuff like walk animation but those are the relevant parts.
If you still need it by then I'll upload a example unit tommorrow but too tired now to clean&pack it up.
Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

Re: Weapons Selection

Post by Von66341 »

knorke thanks for the great help!

What if my animation scripts are in bos/cob instead of lua?
What should my call in be?
I look through the animation wiki page but could not find something useful.
env = Spring.UnitScript.GetScriptEnv(unitID)
if (env) then Spring.UnitScript.CallAsUnit(unitID, env.switchToWeapon, weaponNumber) end
This is for lua animation script correct?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Weapons Selection

Post by knorke »

This is for lua animation script correct?
yes. I am pretty sure it is possible somehow but I have no idea how to talk to cob unit scripts from gadgets.
Bit offtopic but imo just use Lua for unit scripts.
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Re: Weapons Selection

Post by SinbadEV »

this is probably a bad idea but couldn't you just have the "pick weapon" button actually morph the unit to an identical unit that uses the selected weapon as it's force fire weapon?
Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

Re: Weapons Selection

Post by Von66341 »

I manage to find it. Spring.CallCOBScript
But when I run it only the animation runs, no bullet is fire and no damage done.

Yours work perfectly?
Post Reply

Return to “Game Development”