Weapons Selection
Moderator: Moderators
Weapons Selection
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?
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?
Re: Weapons Selection
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.
Actual answer: You can, but you'll have to write a lua gadget for it.
Re: Weapons Selection
To have a weapon that can be chosen to be fired requires a custom command and some script-fu
Re: Weapons Selection
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)
rightclick on enemy or a-click: weapon 1
d-click: weapon 2 (weapon does not fire on its own)
Re: Weapons Selection
dgun weapons will all fire at once on the dgun command.
Re: Weapons Selection
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!
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!
Re: Weapons Selection
You'll have to use SetWeaponTarget IIRC.
Re: Weapons Selection
Spring.SetUnitTarget??
I couldn't find anything on Spring.SetWeaponTarget
How I should go about writing the script/gadget?
I couldn't find anything on Spring.SetWeaponTarget
How I should go about writing the script/gadget?
-
- Moderator
- Posts: 2464
- Joined: 12 Oct 2007, 09:24
Re: Weapons Selection
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.
Re: Weapons Selection
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.
How?I know how to create a new command and draw the box etc.
Re: Weapons Selection
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?
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?
Re: Weapons Selection
thanks.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.
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.Von66341 wrote:Hmm...so there won't be anyway to turn on/off weapons?
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.
Re: Weapons Selection
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?
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?
Re: Weapons Selection
Some quick test, instead of custom buttons I just used the the on/off button that you get with onoffable=true in the unitdef:
So "on" means weapon 1, "off" means weapon 2
Then I just return false in AimWeapon if that weapon should be blocked:
Works, but if the weapons have differant ranges it is problematic because the unit will not get close to use the short ranged weapon. 
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
And to call it from the gadget you would do
well, you probally knew to do it that way...but i just realized the weapon stuff never worked good for me so thats all.
Code: Select all
local activeWeapon = 1
----------
function script.Activate ( )
activeWeapon = 1
end
function script.Deactivate ( )
activeWeapon = 2
end
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

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
Code: Select all
env = Spring.UnitScript.GetScriptEnv(unitID)
if (env) then Spring.UnitScript.CallAsUnit(unitID, env.switchToWeapon, weaponNumber) end
Re: Weapons Selection
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?local activeWeapon = 1
----------
function script.Activate ( )
activeWeapon = 1
end
function script.Deactivate ( )
activeWeapon = 2
end
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?
Re: Weapons Selection
in the unitscript.Check with ya, where did you write this portion of the code? Script or unitdef?
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.How did you link the on/off button with the script?
yes.Say if you on the on/off button, only weapon 1 will fire when you click attack?
depends on the state of the on/off button.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?
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.
That is the full codeMind sharing your full code?

If you still need it by then I'll upload a example unit tommorrow but too tired now to clean&pack it up.
Re: Weapons Selection
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.
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.
This is for lua animation script correct?env = Spring.UnitScript.GetScriptEnv(unitID)
if (env) then Spring.UnitScript.CallAsUnit(unitID, env.switchToWeapon, weaponNumber) end
Re: Weapons Selection
yes. I am pretty sure it is possible somehow but I have no idea how to talk to cob unit scripts from gadgets.This is for lua animation script correct?
Bit offtopic but imo just use Lua for unit scripts.
Re: Weapons Selection
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?
Re: Weapons Selection
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?
But when I run it only the animation runs, no bullet is fire and no damage done.
Yours work perfectly?