Automatic Weapon Firing

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
lucasfart
Sith
Sith
Posts: 1440
Joined: Tue Feb 24, 2009 5:32 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Australia

Automatic Weapon Firing

Post by lucasfart »

Just a couple of questions:

1. Is it possible to make a weapon fire automatically and constantly without the user pressing a button?
2. Is it possible to make said weapon not interfere with the primary fire? I've noticed that when you're using a secondary weapon you can't use the primary one at the same time. Is there a way to change that?
3. How would I go about making a weapon not use any animations when firing? I've tried leaving SoldierAnimationBank blank for the weapon, but that wasn't a good idea. :D

If it helps you understand what I'd like, the concept for my weapon is this. I've got a flaming torch in the units offhand, and I'd like it to generate its own light. I've got the basic concept in action, but there's a few hiccups with firing the weapon. I'd like it to always be generating light without the users input, and without the rifle fire animation being shown (my weapon uses the rifle animationbank because I don't really know what better one to give it).
THEWULFMAN
Space Ranger
Posts: 5557
Joined: Tue Aug 17, 2010 3:30 pm
Projects :: Evolved 2
Location: Columbus, Ohio
Contact:

Re: Automatic Weapon Firing

Post by THEWULFMAN »

Not that I know of, I'm afraid not. I do have an idea though.

This idea works better with a gas lamp or magical lamp, but the idea is thus. It's always in an "off" state, when fired it goes "on" and uses a salvo with a large number. Not infinite, just large. I like the idea if the lamp needing relit.

I do not know if this would interfere with a secondary unit firing.

As for the animation, you'll need to make a custom animation bank. I'd use pistol, I feel it would fit better. In the custom animation, firing and reloading would be replaced by the idle stance.
User avatar
lucasfart
Sith
Sith
Posts: 1440
Joined: Tue Feb 24, 2009 5:32 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Australia

Re: Automatic Weapon Firing

Post by lucasfart »

Does the salvo count reflect how many times the weapon is fired with one click? Because that would definitely work for "infinite" firing. :D Only catch is the weapon would have to be fired at least once to get going right? Any way to force the ai to fire a weapon? I know you can do that with autoturrets, but the line doesn't seem to work for other weapon types (at least it doesn't work for "cannon" type weapons).

With that custom animation bank - what if you're running though? It would look weird to play an idle animation while you're moving... You can set run_fire and walk_fire animations seperately right? Just set the walk_fire to use the walk anim, and the run_fire to use the standard run anim?

EDIT: Oh, and one more thing. :D I'm setting up an offhand mesh for my weapon and I'm not sure about what hp's I should be directing the odf to, or where they should be located. I'm assuming the first one is the hp on the weapon, while the second is one on the unit? Here's what I have so far:

Code: Select all

OffhandFirePointName = "DummyRoot hp_weapons"
So basically, in a concise list:
1. What do salvocount & salvotime do?
2. How do force the ai to fire a weapon?
3. What hardpoints do I need to refer to to add an offhand weapon?

EDIT2:
So I got the salvo working properly after accidentally setting it to shoot 10000000 bullets at once. :D My computer didn't really like that, haha. But the animation is really stuffing it up. :( You can't fire any other weapons while its firing, and it takes another animation to break it (rolling, jumping etc.). Is it possible for a weapon to just not use an animation at all? Because that would make my life easier...
User avatar
Nedarb7
Lieutenant General
Lieutenant General
Posts: 676
Joined: Sat Sep 22, 2012 3:41 pm

Re: Automatic Weapon Firing

Post by Nedarb7 »

Adding: AutoFire = 1 under a selected weaponsection will make you use it automatically, example:

Code: Select all

WeaponName           	= "cool_weapon"
WeaponAmmo          	= "1"
AutoFire = 1
User avatar
lucasfart
Sith
Sith
Posts: 1440
Joined: Tue Feb 24, 2009 5:32 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Australia

Re: Automatic Weapon Firing

Post by lucasfart »

Yeah, but doesn't that only work for turrets?
THEWULFMAN
Space Ranger
Posts: 5557
Joined: Tue Aug 17, 2010 3:30 pm
Projects :: Evolved 2
Location: Columbus, Ohio
Contact:

Re: Automatic Weapon Firing

Post by THEWULFMAN »

Okay time for a REAL classic modder's workaround. it should be possible to create an invisible, autofiring turret and constantly teleport it to your location. I'm way too rusty with Lua to make the code for you, someone else will need to help with that.
User avatar
lucasfart
Sith
Sith
Posts: 1440
Joined: Tue Feb 24, 2009 5:32 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Australia

Re: Automatic Weapon Firing

Post by lucasfart »

That sounds awesome. :D Would it be pretty intense on the engine to have that happening 12x per second for 32 units? I might be able to have a look at it, but yeah, I'll probably need help with the details. :D Just checking though - could the one script do that for every unit on the field, or would it only work for the player?
THEWULFMAN
Space Ranger
Posts: 5557
Joined: Tue Aug 17, 2010 3:30 pm
Projects :: Evolved 2
Location: Columbus, Ohio
Contact:

Re: Automatic Weapon Firing

Post by THEWULFMAN »

I'm pretty confident it would only work for the player.
User avatar
lucasfart
Sith
Sith
Posts: 1440
Joined: Tue Feb 24, 2009 5:32 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Australia

Re: Automatic Weapon Firing

Post by lucasfart »

:cry: No offence, but I really hope you're wrong! It's not as cool when only you do it....So there's absolutely no chance of a blank animation/no animation being played when a weapon is fired? And you can't just get the matrix of whoever fires the weapon and send the turret after them? Why wouldn't that work for AI?

EDIT: Oh, and another question. :mrgreen: I know you can attach effects to units, but is it possible to also attach an omni light? That might be another possibility (then it just wouldn't need to be a weapon at all.
Last edited by lucasfart on Tue Aug 27, 2013 6:42 am, edited 1 time in total.
THEWULFMAN
Space Ranger
Posts: 5557
Joined: Tue Aug 17, 2010 3:30 pm
Projects :: Evolved 2
Location: Columbus, Ohio
Contact:

Re: Automatic Weapon Firing

Post by THEWULFMAN »

I'd explain it in code, but I'm not capable of writing Lua anymore. Someone who is smarter than me can explain it.

No you can't attach lights to units. I tried that once, in different ways.
User avatar
lucasfart
Sith
Sith
Posts: 1440
Joined: Tue Feb 24, 2009 5:32 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Australia

Re: Automatic Weapon Firing

Post by lucasfart »

If I was to do the auto-turret method, would it be possible to activate/auto-spawn it from the moment the unit spawns (if it is one of several select classes?). If that were possible I could just remove it from being a weapon altogether and add the torch model as an addon mesh (I don't mind having it permanently on). Is it possible to attach effects to addon meshes if I take that route?

EDIT: So I've started making a lua script to do the job. It doesn't do anything, but then, I didn't really expect to get it right first go. Any assistance is appreciated. :) Oh, and it should be all inside scriptpostload, right? Cause thats where I put it...

Code: Select all

	Teleport = CreateTimer("Teleport")
	SetTimerValue(Teleport, 1)
    
	TeleportLight = OnCharacterDispenseControllable(
		function (player, controllable)
			if GetEntityClassName(controllable) == "mdv_invisible_turret" then
				StartTimer(Teleport)
					OnTimerElapse(
						function(timer)
							SetEntityMatrix( controllable, GetEntityMatrix( GetCharacterUnit(character) ) )
						end,
					Teleport
					)  
			end
		end
	)
Also, how would I reset the timer? I feel like its a really obvious thing, but I couldn't find anything about it on GT...And I'm not sure how to keep teleporting it after its dispensed? Because wouldn't this only run once when you first dispense the turret?
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: Automatic Weapon Firing

Post by Locutus »

Not sure if you can pass on the parameters from the dispense function like this...
Just wrote what came into my head:

Code: Select all

--this goes in ScriptPostLoad() after Conquest:Start()
OnCharacterDispenseControllable(
      function (player, controllable)
         if GetEntityClassName(controllable) == "mdv_invisible_turret" then
            doTeleport(player, controllable)     
         end
      end
   )

--this comes after ScriptPostLoad() but before SciptInit()
function doTeleport(player, controllable)
   while true do
       if IsObjectAlive(controllable) then
         MoveEntityToNode(player, "TeleportNode") --see http://www.gametoast.com/forums/viewtopic.php?p=195602#p195602
      else
         return
      end
      --add a short timer here
   end
end
User avatar
lucasfart
Sith
Sith
Posts: 1440
Joined: Tue Feb 24, 2009 5:32 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Australia

Re: Automatic Weapon Firing

Post by lucasfart »

Hidden/Spoiler:
Ahh, so you just perform the check in the scriptpostload and then link to a separate function? Is that necessary, or just a lot cleaner?

I'm a bit confused about this whole section. I get that the first bit is a check to see what values have been entered, but are pathIn, entIn and nodeIn already existing calls (or whatever you call them), because I can't see them defined anywhere prior.

function MoveEntityToNode(entIn,pathIn,nodeIn)
if not entIn then
print("Warning!: Entity not specified for move")
return false
elseif not pathIn then
print("Warning!: Path not specified for Entity " .. entIn .. " move")
return false
end

local node
if nodeIn then
node = nodeIn
else
node = 0
end

local locDest = GetPathPoint(pathIn,node)
local charUnit = GetCharacterUnit(entIn)
if charUnit then
SetEntityMatrix(charUnit,locDest)
return true
end
return false
end

And of course, with what you're describing, its all about moving the player to a node. I want something slightly different (the node moved to the player). Would it be that hard to change? I guess its just a matter of first making a function called MoveNodeToPlayer or something like that and THEN moving the controllable to the node. Can you skip the whole concept of a node and just send the controllable straight to the player's matrix?

So that whole "while true" section will just loop until something becomes false? What is that "true" based on? The IsObjectAlive statement?

Forgive all the questions. :D I've never really done any serious coding before...
So I've just been fiddling a bit more and came up with this: the problem is, it doesn't even get triggered. None of the printed lines are returned. :(
Hidden/Spoiler:
function ScriptPostLoad()

Teleport = CreateTimer("lightmove")
SetTimerValue(Teleport, 1)

OnCharacterDispenseControllable(
function (player, controllable)
if GetEntityClassName(controllable) == "mdv_invisible_turret" then
print("Found controllable light source!")
doTeleport(player, controllable)
end
end
)
...
end

function doTeleport(player, controllable)

local player_loc = GetEntityMatrix( GetCharacterUnit(character) )

while true do

print("It's True!")
if IsObjectAlive(controllable) then
SetEntityMatrix(controllable, player_loc) --see http://www.gametoast.com/forums/viewtop ... 02#p195602
print("Controllable moved!")
else
return
end
StartTimer(Teleport)
OnTimerElapse(
function(timer)
print("Timer Completed")
end,
Teleport
) end
end
Why would it not be triggered? I'm guessing I haven't set the proper odf to be checked for? Should it be the dispenser weapon, or the actual turret that is spawned from that?

EDIT: Just removed the controllable type check, so it now gets past that. :) (If anyone knows why it wasn't working, I'd still appreciate help with that. :)

Code: Select all

function doTeleport(player, controllable)
 
local player_loc = GetEntityMatrix( GetCharacterUnit(player) )

	while true do
	
		print("It's True!")
		if IsObjectAlive(controllable) then
			
			StartTimer(Teleport)
			OnTimerElapse(
					function(timer)
						SetEntityMatrix(controllable, player_loc) --see http://www.gametoast.com/forums/viewtopic.php?p=195602#p195602
						print("Controllable moved!")
						
					end,
				Teleport
			)     
			print("Timer Completed")
			
		else
			return
		end
end	
end
My new problem is that it loops even when the timer isn't complete. :( How would I prevent it from looping while the timer is still going?
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: Automatic Weapon Firing

Post by Locutus »

You can't just leave that function out.
Try this:

Code: Select all

OnCharacterDispenseControllable(
   function(player, controllable)
      print("lucasfart: OnCharacterDispenseControllable triggered")
      if GetEntityClass(controllable) == FindEntityClass("mdv_invisible_turret") then
         print("lucasfart: mdv_invisible_turret found")
         --do stuff 
      end
   end
)
User avatar
lucasfart
Sith
Sith
Posts: 1440
Joined: Tue Feb 24, 2009 5:32 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: Australia

Re: Automatic Weapon Firing

Post by lucasfart »

Sorry, I should have added it in. I still have it inside scriptpostload, but I don't think that's where the problem is, so I didn't bother posting it. I basically left it how you put it, except without the classtype check. So I get the feeling my problem lies in the timer loop. (Because really, that top function should only be triggered once when you drop the turret.) Any ideas about how to make a nice simple loop on a timer? Because at this point, the teleport function works (with a timer of one second for testing purposes). The problem is, after 10 seconds it really starts to lag, before finally crashing BF. The loop just isn't working properly. I don't think its waiting for the timer to complete before starting again. Any ideas?
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: Automatic Weapon Firing

Post by Locutus »

Kick the "while true" and call the function again on timer elapse.
Post Reply