Getting Allies to man an MG42 and SHOOT
Moderator: Moderators
Getting Allies to man an MG42 and SHOOT
Ok, I have an SP map that has allies manning MG42s. The only problem is I spent all day trying to get them to shoot and they wouldn't. NOW I have them shooting, but they shoot at me. Below is my script. I know what the problem is, but don't know how to fix it. I have the mg42 gunner aiming and shooting at $player...which is me. Is there a universal $name for axis ai?? I have axis rushing a hill and allies shooting them from a few mg42s. I need them to shoot the axis, not me (LOL). Anyone know how to fix this? Here's what I have so far:
exec global/loadout.scr maps/m1l1_aiPractice.scr
exec global/ai.scr
exec global/enable_ai.scr
exec global/turret.scr
exec global/auto.scr
exec global/weather.scr
exec global/ambient.scr m5l1b
level waitTill prespawn
level waitTill spawn
$mg42a thread global/mg42_active.scr::mg42 6000
$mg42b thread global/mg42b_active.scr::mg42b 6000
$mg42c thread global/mg42c_active.scr::mg42c 6000
thread global/ai.scr::spawngroup #1 #1
$player item weapons/colt45.tik
$player item weapons/m1_garand.tik
$player item weapons/mp40.tik
$mg42a_gunner holster
$mg42a_gunner exec global/disable_ai.scr
thread mg_targeting $mg42a
end
mg_targeting local.machinegun:
waitframe
local.loopwaittime = 0.5 // prevents loop
while (!($mg42a_gunner cansee $player)) // can't see player
{
wait 1
}
while ((isalive $mg42a_gunner) && ($mg42a_gunner cansee $player)
{
local.machinegun burstFireSettings 0.25 0.5 1 .25
local.machinegun maxYawOffset 55
local.machinegun bulletdamage 20
local.machinegun setaimtarget $player
local.machinegun startfiring
wait local.loopwaittime
}
end
>>>>>>>>>>>>>>>>>>>>>>> END SCRIPT >>>>>>>>>>>>>>>
That line above isn't in the script, it's just so you know that's the end. Anyway, I've only been messing with scripting for a few days now so I'm sure some stuff I have doesn't belong and some stuff I have does. I'm testing for mg42a....the others I have not adjusted yet. That's why there isn't a thread for them. Anyway, any help is highly appreciated! Thanks.
ShadowX
exec global/loadout.scr maps/m1l1_aiPractice.scr
exec global/ai.scr
exec global/enable_ai.scr
exec global/turret.scr
exec global/auto.scr
exec global/weather.scr
exec global/ambient.scr m5l1b
level waitTill prespawn
level waitTill spawn
$mg42a thread global/mg42_active.scr::mg42 6000
$mg42b thread global/mg42b_active.scr::mg42b 6000
$mg42c thread global/mg42c_active.scr::mg42c 6000
thread global/ai.scr::spawngroup #1 #1
$player item weapons/colt45.tik
$player item weapons/m1_garand.tik
$player item weapons/mp40.tik
$mg42a_gunner holster
$mg42a_gunner exec global/disable_ai.scr
thread mg_targeting $mg42a
end
mg_targeting local.machinegun:
waitframe
local.loopwaittime = 0.5 // prevents loop
while (!($mg42a_gunner cansee $player)) // can't see player
{
wait 1
}
while ((isalive $mg42a_gunner) && ($mg42a_gunner cansee $player)
{
local.machinegun burstFireSettings 0.25 0.5 1 .25
local.machinegun maxYawOffset 55
local.machinegun bulletdamage 20
local.machinegun setaimtarget $player
local.machinegun startfiring
wait local.loopwaittime
}
end
>>>>>>>>>>>>>>>>>>>>>>> END SCRIPT >>>>>>>>>>>>>>>
That line above isn't in the script, it's just so you know that's the end. Anyway, I've only been messing with scripting for a few days now so I'm sure some stuff I have doesn't belong and some stuff I have does. I'm testing for mg42a....the others I have not adjusted yet. That's why there isn't a thread for them. Anyway, any help is highly appreciated! Thanks.
ShadowX
$<name> means no more than 'the entity with this targetname'. So if you want your gunners to engage enemy troops, it's a good idea to assign a targetname to these guys.
More comments:
$mg42b thread global/mg42b_active.scr::mg42b 6000
$mg42c thread global/mg42c_active.scr::mg42c 6000
should be:
$mg42b thread global/mg42b_active.scr::mg42 6000
$mg42c thread global/mg42c_active.scr::mg42 6000
local.machinegun setaimtarget $player
You might want to try local.machinegun.setaimtarget = $<enemyname> so that it may work with the global mg42 script.
More comments:
$mg42b thread global/mg42b_active.scr::mg42b 6000
$mg42c thread global/mg42c_active.scr::mg42c 6000
should be:
$mg42b thread global/mg42b_active.scr::mg42 6000
$mg42c thread global/mg42c_active.scr::mg42 6000
local.machinegun setaimtarget $player
You might want to try local.machinegun.setaimtarget = $<enemyname> so that it may work with the global mg42 script.
Let Me Explain Better
What I'm trying to get them to do is shoot at any axis that comes along. Kind of like in D-Day, with the Germans tearing up the US on the beach. Is it possible for even just "random aiming and firing"? Noone seems to be able to answer this question, so I'm assuming allies usually don't man the mg42s. But there's gotta be a way. What I meant by $name was simply "$name" not literally what I put. Like an object or something that refers to ANY axis soldiers on the map. Perhaps an array of all the axis soldiers names would work? or even a multiple-trigger? How do I set up a multiple-trigger or an array? Thanks.
ShadowX
ShadowX
Allies can perfectly handle a mg-42 turret. You can work with a scripted array, but easiest is to use a targetname array. Just assign the same targetname to a group of German soldiers and your array is ready 8).
For example, if you choose targetname 'german', you can access individual soldiers this way:
$german[1]
$german[2]
etc.
Then make the gun shoot these targets in cueue
For example, if you choose targetname 'german', you can access individual soldiers this way:
$german[1]
$german[2]
etc.
Then make the gun shoot these targets in cueue
How Do I Cueue
jv_map,
I'm familiar with c/c++ and java, but I don't understand some of the syntax of this scripting language. Do I need to use a for loop to loop through the targetname array? What exactly do you mean by cueue? You are the ONLY person on nearly 10 forums that has been able to confirm you can man an mg42 with allies! How do I cueue through the targetname? by cueue do you mean "loop"? or something else? Can you show me an example of what a cueue would look like? ANY example or point me to where I can find one? Thanks.
ShadowX
I'm familiar with c/c++ and java, but I don't understand some of the syntax of this scripting language. Do I need to use a for loop to loop through the targetname array? What exactly do you mean by cueue? You are the ONLY person on nearly 10 forums that has been able to confirm you can man an mg42 with allies! How do I cueue through the targetname? by cueue do you mean "loop"? or something else? Can you show me an example of what a cueue would look like? ANY example or point me to where I can find one? Thanks.
ShadowX
Uh well the easiest way of targeting is probably by looping as long as the gunner is alive. Hence, I think some code like the following would work fine. I assume all enemies have targetname 'german'.
Well I hope this is of some help. You'll need some modifications to stop the thread when all hostiles have been killed. Personally I hate the global mg_active script, so I always write my own scripts.
Code: Select all
// shorthands
local.gunner = $mg42a_gunner
local.gun = $mg42a
while(isAlive local.gunner)
{
// clear local.target
local.target = NULL
// find a target from the array
for(local.i = 1; local.i <= $german.size; local.i++)
{
local.guy = $german[local.i] // shorthand
// don't fire at death guys ;).
if(isAlive local.guy)
{
// make sure we can shoot the boy
// syntaxis: cansee <entity> <fov> <maxrange>
// NOTE: set both a maxyawoffset and a #maxyawoffset key for the turret
if(local.gunner cansee local.guy (2 * local.gun.maxyawoffset) 6000)
{
// attack this target!
local.target = local.guy
break
}
}
}
if(local.target != NULL)
{
// we've found a suitable target, attack!
local.gun setaimtarget local.target
// relying on mg_active script for shooting (not recommended though)
// just wait a while
wait 5
}
wait 0.5
}
Still shooting at me
jv_map,
Man, I know we are on the right track. But for some reason my guys are still shooting at me. I have ONE german spawn, his targetname is enemyspawner[1]. I stay hidden and see if the guys will shoot him. They don't. I have it setup only for mg42a_gunner right now, but ALL the three mg42 gunners start shooting me when I come into view. Here is what I have so far. From top to bottom. Btw, I appreciate all the time you've spent on this. Here it is: (I've highlighted questionable parts in BLUE)
// BEGIN SCRIPT
exec global/loadout.scr maps/m1l1_aiPractice.scr
exec global/ai.scr
// These three were giving me erros so I commented them out
// exec global/enable_ai.scr
// exec global/turret.scr
// exec global/auto.scr
exec global/weather.scr
exec global/ambient.scr m5l1b
level waitTill prespawn
level waitTill spawn
$mg42a thread global/mg42_active.scr::mg42 2000
$mg42b thread global/mg42_active.scr::mg42 2000
$mg42c thread global/mg42_active.scr::mg42 2000
thread global/ai.scr::spawngroup #1 #1
$player item weapons/colt45.tik
$player item weapons/m1_garand.tik
$player item weapons/mp40.tik
$mg42a_gunner holster
$mg42b_gunner holster
$mg42c_gunner holster
// SHOULD I DISABLE THEIR AI?
$mg42a_gunner exec global/disable_ai.scr
$mg42b_gunner exec global/disable_ai.scr
$mg42c_gunner exec global/disable_ai.scr
end
// BEGIN PORTION YOU HELPED ME WITH
local.gunner = $mg42a_gunner // assign gunner to local.gunner
local.gun = $mg42a // assign weapon as local.gun
while (isAlive local.gunner) // while gunner is alive
{
local.target = NULL // clear out target
// YOU'LL NOTICE I DIDN'T INITIALIZE A TARGETNAME ARRAY. COULD THAT BE THE PROBLEM? DOES $BLAHBLAH.SIZE HOLD THE INFORMATION OF HOW MANY THERE ARE IN THE ARRAY? HOW DO I INITIALIZE AN ARRAY? IS LIKE C++ OR JAVA?
for (local.i = 1; local.i <= $enemyspawner.size; local.i++)
{
local.guy = $enemyspawner[local.i] // assigns first enemy to local.guy
if (isAlive local.guy) // if enemy is alive still
{
if (local.gunner cansee local.guy (2 * local.gun.maxYawOffset)
2000) // and can be seen by the gunner
{
local.target = local.guy // assign local.guy as target
break // break out of IF statement
}
}
}
if (local.target != NULL) // as long as there is a target
{
local.gun setaimtarget local.target // aim at the target
// YOU SAID mg42_active.scr WILL DO THE SHOOTING, BUT SAID IT WASN'T A GOOD IDEA. HOW WOULD I CHANGE IT? OVER MY HEAD?
// WHAT'S THIS DO (BESIDES WAIT)? WHAT I MEAN IS WHY IS HE WAITING?
wait 2
}
wait 0.5
}
end
// END SCRIPT
Ok, sorry for being such a bother, but like I said you have a wealth of knowledge. Thanks for any help in advance.
ShadowX
Man, I know we are on the right track. But for some reason my guys are still shooting at me. I have ONE german spawn, his targetname is enemyspawner[1]. I stay hidden and see if the guys will shoot him. They don't. I have it setup only for mg42a_gunner right now, but ALL the three mg42 gunners start shooting me when I come into view. Here is what I have so far. From top to bottom. Btw, I appreciate all the time you've spent on this. Here it is: (I've highlighted questionable parts in BLUE)
// BEGIN SCRIPT
exec global/loadout.scr maps/m1l1_aiPractice.scr
exec global/ai.scr
// These three were giving me erros so I commented them out
// exec global/enable_ai.scr
// exec global/turret.scr
// exec global/auto.scr
exec global/weather.scr
exec global/ambient.scr m5l1b
level waitTill prespawn
level waitTill spawn
$mg42a thread global/mg42_active.scr::mg42 2000
$mg42b thread global/mg42_active.scr::mg42 2000
$mg42c thread global/mg42_active.scr::mg42 2000
thread global/ai.scr::spawngroup #1 #1
$player item weapons/colt45.tik
$player item weapons/m1_garand.tik
$player item weapons/mp40.tik
$mg42a_gunner holster
$mg42b_gunner holster
$mg42c_gunner holster
// SHOULD I DISABLE THEIR AI?
$mg42a_gunner exec global/disable_ai.scr
$mg42b_gunner exec global/disable_ai.scr
$mg42c_gunner exec global/disable_ai.scr
end
// BEGIN PORTION YOU HELPED ME WITH
local.gunner = $mg42a_gunner // assign gunner to local.gunner
local.gun = $mg42a // assign weapon as local.gun
while (isAlive local.gunner) // while gunner is alive
{
local.target = NULL // clear out target
// YOU'LL NOTICE I DIDN'T INITIALIZE A TARGETNAME ARRAY. COULD THAT BE THE PROBLEM? DOES $BLAHBLAH.SIZE HOLD THE INFORMATION OF HOW MANY THERE ARE IN THE ARRAY? HOW DO I INITIALIZE AN ARRAY? IS LIKE C++ OR JAVA?
for (local.i = 1; local.i <= $enemyspawner.size; local.i++)
{
local.guy = $enemyspawner[local.i] // assigns first enemy to local.guy
if (isAlive local.guy) // if enemy is alive still
{
if (local.gunner cansee local.guy (2 * local.gun.maxYawOffset)
2000) // and can be seen by the gunner
{
local.target = local.guy // assign local.guy as target
break // break out of IF statement
}
}
}
if (local.target != NULL) // as long as there is a target
{
local.gun setaimtarget local.target // aim at the target
// YOU SAID mg42_active.scr WILL DO THE SHOOTING, BUT SAID IT WASN'T A GOOD IDEA. HOW WOULD I CHANGE IT? OVER MY HEAD?
// WHAT'S THIS DO (BESIDES WAIT)? WHAT I MEAN IS WHY IS HE WAITING?
wait 2
}
wait 0.5
}
end
// END SCRIPT
Ok, sorry for being such a bother, but like I said you have a wealth of knowledge. Thanks for any help in advance.
ShadowX
Shouldn't there be a line at the end saying
Otherwise he might still be alive when the script loops around and assigns another target. Unless this is controlled by the mg42_active script ??
Code: Select all
local.guy waittill deathIt's very likely the targeting of the player is caused by the global/mg42_active.scr file. I suggest you don't use this script, but use something like this:
I'll answer the other questions in a bit. Have to go now
.
Code: Select all
local.gunner = $mg42a_gunner // assign gunner to local.gunner
local.gun = $mg42a // assign weapon as local.gun
local.bursts = 0 // for reloading
while (isAlive local.gunner) // while gunner is alive
{
local.target = NULL // clear out target
for (local.i = 1; local.i <= $enemyspawner.size; local.i++)
{
local.guy = $enemyspawner[local.i] // assigns first enemy to local.guy
if (isAlive local.guy) // if enemy is alive still
{
if (local.gunner cansee local.guy (2 * local.gun.maxYawOffset) 2000)
// and can be seen by the gunner
{
local.target = local.guy // assign local.guy as target
break // break out of IF statement
}
}
}
if (local.target != NULL) // as long as there is a target
{
local.gun setaimtarget local.target // aim at the target
// wait a while
wait 1
// shoot
local.gun startfiring
wait 2
local.gun stopfiring
local.bursts++ // for reloading code
if(local.bursts >= 4)
{
// reload
if(isAlive local.gunner)
{
local.gunner reload_mg42
local.gunner waittill animdone
local.bursts = 0
}
}
}
wait 0.5
}
Answers
Yes. Otherwise they'll try to attack enemies with their sidearm// SHOULD I DISABLE THEIR AI?
Why didn't I see this before? Because of this all the code I posted is never runend
You don't need to initialize an array. Targetname arrays work automatically. The array.size variable contains the number of elements of the array. Regular arrays start their indexing at 1.// YOU'LL NOTICE I DIDN'T INITIALIZE A TARGETNAME ARRAY. COULD THAT BE THE PROBLEM? DOES $BLAHBLAH.SIZE HOLD THE INFORMATION OF HOW MANY THERE ARE IN THE ARRAY? HOW DO I INITIALIZE AN ARRAY? IS LIKE C++ OR JAVA?
Na it breaks out of the 'for' statement, as a target was found and we don't need to find another target// break out of IF statement
The gunner fires at the target for 2 seconds, waits another 0.5 seconds and then starts searching for targets again.// WHAT'S THIS DO (BESIDES WAIT)? WHAT I MEAN IS WHY IS HE WAITING?
No. It was my intention that the gunner did a targetcheck every 2.5 seconds. This way, he won't attack a target that was initially visible but found cover in the meanwhile.Shouldn't there be a line at the end saying
local.guy waittill death
Otherwise he might still be alive when the script loops around and assigns another target.
Hope this info is useful in some way or maybe another.
