Forcing a Weapon to Fire

Forcing a Weapon to Fire

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

Moderator: Moderators

Post Reply
User avatar
REVENGE
Posts: 2382
Joined: 24 Aug 2006, 06:13

Forcing a Weapon to Fire

Post by REVENGE »

Can I use either COB or LUA script, to force a particular weapon to fire as is (no aiming necessary, just fire)?

The effect I'm trying to get at here is basically have the unit drop a bomb from one of its pieces in place, or emit an explosion (not cosmetic).

I believe a workaround would be emit-sfx'ing the explosion, then doing the damage using lua, but if I can, say, force a projectile or bomb to spawn, that would be nicer.

EDIT: I also just thought of a possible workaround using a unit, can someone tell me how to spawn a unit using lua? (not nearly as nice, but could be used temporarily)
User avatar
Evil4Zerggin
Posts: 557
Joined: 16 May 2007, 06:34

Re: Forcing a Weapon to Fire

Post by Evil4Zerggin »

COB does what you want.

emit-sfx 2048 + weapon number (first weapon is 0) will fire the weapon from that piece using the piece's position and orientation. This should include projectile, etc.

emit-sfx 4096 + weapon number detonates a weapon at the piece.

For an example, spawn armthund2 in CA, or use the laser bombers modoption.

This is moot, but to create a unit using Lua, you'll need to use Spring.CreateUnit(
string "defName",
number x, number y, number z,
(number facing | string "facing"),
number teamID ) -> number unitID

This is taken from Lua SyncedCtrl.
User avatar
REVENGE
Posts: 2382
Joined: 24 Aug 2006, 06:13

Re: Forcing a Weapon to Fire

Post by REVENGE »

Thanks so much, this will make things very easy.

Weird, must have just not read SyncedCtrl carefully enough...totally missed createunit.
User avatar
REVENGE
Posts: 2382
Joined: 24 Aug 2006, 06:13

Re: Forcing a Weapon to Fire

Post by REVENGE »

Hmm, I just noticed, however, that if you emit-sfx 4096 an explosion, the explosion will not follow noselfdamage=1 rules. Hmm...
User avatar
Evil4Zerggin
Posts: 557
Joined: 16 May 2007, 06:34

Re: Forcing a Weapon to Fire

Post by Evil4Zerggin »

noselfdamage is pretty broken anyways >_>. You could try gadgeting something like this. Not sure how to get it to work with an emit-sfx explosion though.
User avatar
REVENGE
Posts: 2382
Joined: 24 Aug 2006, 06:13

Re: Forcing a Weapon to Fire

Post by REVENGE »

Hmm, well noselfdamage doesnt work with 4096, but it works with 2048 fine. A little hax makes it all ok.
Post Reply

Return to “Lua Scripts”