Getting Allies to man an MG42 and SHOOT

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
ShadowX
Lance Corporal
Posts: 16
Joined: Sun Mar 09, 2003 9:10 am
Location: Ohio

Getting Allies to man an MG42 and SHOOT

Post by ShadowX »

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
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

$<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.
Image
ShadowX
Lance Corporal
Posts: 16
Joined: Sun Mar 09, 2003 9:10 am
Location: Ohio

Let Me Explain Better

Post by ShadowX »

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
User avatar
Butch
Lieutenant Colonel
Posts: 398
Joined: Fri Jan 24, 2003 11:30 am

Post by Butch »

well, mg42s are german weapons so that's probably why they don't like manning mg42s
PFC.Butch
B Company, 2nd Ranger Battalion
US Army
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

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 :roll:
Image
ShadowX
Lance Corporal
Posts: 16
Joined: Sun Mar 09, 2003 9:10 am
Location: Ohio

How Do I Cueue

Post by ShadowX »

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
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

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'.

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
}
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.
Image
ShadowX
Lance Corporal
Posts: 16
Joined: Sun Mar 09, 2003 9:10 am
Location: Ohio

Still shooting at me

Post by ShadowX »

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
Angex
Major
Posts: 293
Joined: Mon Dec 30, 2002 1:23 pm
Contact:

Post by Angex »

Shouldn't there be a line at the end saying

Code: Select all

local.guy waittill death
Otherwise he might still be alive when the script loops around and assigns another target. Unless this is controlled by the mg42_active script ??
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

It'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:

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
}
I'll answer the other questions in a bit. Have to go now :(.
Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Answers

Post by jv_map »

// SHOULD I DISABLE THEIR AI?
Yes. Otherwise they'll try to attack enemies with their sidearm :?.
end
Why didn't I see this before? Because of this all the code I posted is never run :cry:.
// 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?
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.
// break out of IF statement
Na it breaks out of the 'for' statement, as a target was found and we don't need to find another target ;).
// WHAT'S THIS DO (BESIDES WAIT)? WHAT I MEAN IS WHY IS HE WAITING?
The gunner fires at the target for 2 seconds, waits another 0.5 seconds and then starts searching for targets again.
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.
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.

Hope this info is useful in some way or maybe another.
Image
Post Reply