Home   Help Search Login Register  

Author Topic: Scripting query - Respawn script  (Read 1796 times)

0 Members and 1 Guest are viewing this topic.

Offline Viking

  • Members
  • *
  • NORSOF
Scripting query - Respawn script
« on: 24 May 2007, 01:18:47 »
Hello

I downloaded angusjm's excellent respawn script again today from the Editors Depot after a long time out of OFP..
When angusjm first made the script, I had him modify it for me, but these modifications haven't made it into the one he uploaded to OFPEC, so I was hoping some of you guys could help me.

The script works this way:
Quote
;  Call this script using the following syntax:
;
;  [1,unit to converge around,array of groups,units per group,type of unit,skill of units,radius around unit to converge around,body disapear on or off (1 on, 0 off)]
;
;  The AI will be created of a random one of the type specified and will head towards the unit to converge around
;
;Example [1,player,[east1,east2],12,["SoldierEB","SoldierEMG"],0.1,50,1] exec "ajmrespawn.sqs"

In short order, the script creates a number of soldiers randomly in a 360 degree area around the "target". Radius, number of soldiers and type of soldiers can be defined in the syntax.

Now, what I want is for me to be able to define how many degrees around the target that the soldiers are spawned/respawned. When angusjm did this for me back in the days, he made it work like this:

- An extra number was added into the syntax, a number that could be between 0 and 360 (degrees) and defined by the mission maker
- The target's heading was returned to the script (azimuth)
- The spawned units would spawn in an area relative to the heading of the target
...this meaning that if the mission maker defined the new number in the array to, say, 10, and the targets azimuth was 0, the enemy units would spawn between -5 and 5 (of the target's azimuth). You could say that the number defined in the array was split in two over the target's azimuth (so if you wrote 360 in the array, enemy units would spawn 180 degrees on either side of the target's 0 azimuth, resulting in it being surrounded).

It's hard to explain, but I hope you get it. Here is the script, I really hope you can do something with it - it's really cool for defend/chase type mission:

Quote



_wtd = _this select 0
_aUnit = _this select 1

? _wtd == 0: goto "missemall"
_agroups = _this select 2
_apg = _this select 3
_askill = _this select 5
_aradius = _this select 6
_thon = _this select 7
_list=_this select 4;
_ntotal=count _list;




_c = 0
#loop
   #gloop
      _rg = count units (_agroups select _c)
      ? _rg >= _apg : goto "misscreate"
      _rg = _apg - _rg
      #iloop
         _rnum = random ((360))
         _num = _rnum - (_rnum mod 1)
         _d1 = getpos _aunit select 0
         _d2 = getpos _aunit select 1
         _d3 = 0
         _random=random(_ntotal);
         _result=_random - ((_random) mod (1));
         if (_result==_ntotal) then {_result=_result-1};
         _utype = (_list select _result);

         _d1 = _d1 + _aradius * sin(_rnum)
         _d2 = _d2 + _aradius * cos(_rnum)
         _utype createunit [[_d1,_d2,_d3],_agroups select _c,"",_askill,"PRIVATE"]
        ? _thon == 1 : {_x addeventhandler [{killed},{[0,_this] exec {AJMRespawn.sqs}}]} foreach units (_agroups select _c)
         _agroups select _c move getpos _aunit
         leader (_agroups select _c) move getpos _aunit
         _rg = _rg - 1
         ? _rg == 0 : goto "misscreate"
      goto "iloop"
      #misscreate
      _c = _c + 1
      ? _c == count _agroups : _c = 0; goto "eloop"
   goto "gloop"
   #eloop
   ~0.5
goto "loop"

#missemall
~5
deletevehicle (_aunit select 0)

Cheers,
Viking
VIKING
Modeller/Skinner/Coder
NORFOR

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Scripting query - Respawn script
« Reply #1 on: 24 May 2007, 19:40:33 »
Add one more parameter to the script:
Code: [Select]
_spang = _this select 8
And replace some of the code:
Code: [Select]
_rnum = _spang - (random (2*_spang))
_d1 = getpos _aunit select 0
_d2 = getpos _aunit select 1
_d3 = 0
_random=random(_ntotal);
_result=_random - ((_random) mod (1));
if (_result==_ntotal) then {_result=_result-1};
_utype = (_list select _result);
_rnum = ((getDir _aUnit) + _rnum) mod 360
_d1 = _d1 + _aradius * sin(_rnum)
_d2 = _d2 + _aradius * cos(_rnum)

urp!

Offline Viking

  • Members
  • *
  • NORSOF
Re: Scripting query - Respawn script
« Reply #2 on: 25 May 2007, 02:12:49 »
Excellent! :) Tested and working!

Thanks alot, Mr. Peanut - I owe you one! :)

Cheers! :good:
VIKING
Modeller/Skinner/Coder
NORFOR

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Scripting query - Respawn script
« Reply #3 on: 25 May 2007, 02:44:28 »
Glad it works. I suppose one other improvement would to be able to specify the angular range from an arbitrary angle relative to the player's direction. Then you could specify that the units are only spawned behind the player. But then, I suppose, they might never catch up.
urp!

Offline Viking

  • Members
  • *
  • NORSOF
Re: Scripting query - Respawn script
« Reply #4 on: 26 May 2007, 15:02:38 »
You mean make them "chase" the player? If so, could you explain it a little closer - I'm not familiar with those expressions? :)Maybe post a bit of code and an array parameter that one could use to "switch" between spawning enemies from behind the player or in front of the player? I.e. _direction = (either) 0 (= in front of player) or 1 (= behind player)

For example:
OBJECTIVE 1: Hold the area
- script starts, parameter set to 0
- enemies are spawned through the normal script in front of the players position (they move towards a static object in the area)
- script stops after so and so many minutes/seconds
- enemies are killed
- Objective complete

OBJECTIVE 2: Retreat from the area
- new script starts (identical with the above one, only this one has parameter set to 1)
- player flees in the opposite direction of where he was defending
- enemies now spawn behind him and follow
- player arrives at LZ for extraction, has to fend off the pursuing enemies

#EDIT-removed the unnecessary quote, no need to quote the whole previous post you're replying to..  h-
« Last Edit: 28 May 2007, 09:55:59 by h- »
VIKING
Modeller/Skinner/Coder
NORFOR

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Scripting query - Respawn script
« Reply #5 on: 27 May 2007, 02:24:59 »
Add two last optional parameters. Change near beginning to:
Code: [Select]
_spang = _this select 8
_dirflag = FALSE
_offset = 0
if (count _this > 9) then {_dirflag = _this select 9}
if (count _this > 10) then {_offset = _this select 10}
if _dirflag then {_dirflag = 0} else {_dirflag = 1}

1)If _dirflag is FALSE then the direction from which the enemy come will be calculated relative to the player, if TRUE the direction it will be absolute compass direction.
2)_offset is the angle relative to the direction the player is facing. That is, -180 or +180 would mean the enemy is spawned behind the player, 90 would be to the right and -90 or 270 from the left.
3)If _dirflag is TRUE then _offset specifies the compass direction from which the enemies come i.e. 0 = North, 90 = East, 180 = South, 270 = West.

Last small code change:
Code: [Select]
_rnum = ((getDir _aUnit)*_dirflag + _rnum + _offset) mod 360
This variation probably offers the most flexibility. You can now specify the compass direction, or the direction relative to the player. If you do not provide the last two options then the scripts behaves as normal: enemies are spawned in angular range in front of player.

All of the above code is, of course, untested  :shhh:

 
urp!

Offline Viking

  • Members
  • *
  • NORSOF
Re: Scripting query - Respawn script
« Reply #6 on: 28 May 2007, 01:59:32 »
OK, tested it now and found the following

1) _offset works fine - for the COMPASS direction.

2) Error:
Quote
'if _dirflag then|#| {_dirflag = 0} else {_dirflag = 1}': Error if: Type Number, expected Bool

Which means the player direction relative spawning doesn't work, as far as I can fathom.
It spawns the soldiers from all thinkable directions at all thinkable angles relative to compass, but not target/player direction.

But I can't seem to find what is wrong with that line of code...
VIKING
Modeller/Skinner/Coder
NORFOR

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Scripting query - Respawn script
« Reply #7 on: 28 May 2007, 16:28:29 »
To use _offest you have to specify _dirflag as well, and _dirflag must be either TRUE or FALSE. The error seems to be saying that you specified _dirflag as a numerical value instead. Is this the case?
urp!

Offline Viking

  • Members
  • *
  • NORSOF
Re: Scripting query - Respawn script
« Reply #8 on: 28 May 2007, 16:47:50 »
Yes, that is the case.
I thought 0 and 1 could be used instead of TRUE/FALSE, but it obviously can't... :-[

I tested it again with TRUE and FALSE, now with the following error:

Code: [Select]
'_thon == 1 |#|': Error ==: Type Bool, expected Number,String,Object,Side,Group
That part of the script is an original part, as you can see, regarding the restarting of the script (as far as I can see?)
Any suggestions?

Thanks for helping out!
VIKING
Modeller/Skinner/Coder
NORFOR

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Scripting query - Respawn script
« Reply #9 on: 28 May 2007, 22:28:43 »
Lol, same error in reverse! You have specified TRUE/FALSE for the the eighth parameter of the script instead of 0/1?

I guess I should change my code to be consistent with the 0/1 type selection that the original author used:
Code: [Select]
_spang = _this select 8
_dirflag = 1
_offset = 0
if (count _this > 9) then {_dirflag = _this select 9}
if (count _this > 10) then {_offset = _this select 10}
if (_dirflag != 0) then {_dirflag = 1}

Now for the second last(ninth!) parameter just specify 0 or 1: 1 if you want direction relative to the player, 0 if you want absolute compass direction. So now all the flags are 0 or 1, for consistency. Hope this finally works. :scratch:
urp!

Offline Viking

  • Members
  • *
  • NORSOF
Re: Scripting query - Respawn script
« Reply #10 on: 29 May 2007, 16:43:26 »
OK, now it works tip top! Only thing is (not really an error) that the script acts the opposite of this:
Quote
1)If _dirflag is FALSE then the direction from which the enemy come will be calculated relative to the player, if TRUE the direction it will be absolute compass direction.

I.e.  FALSE means compass and TRUE means player direction, but like I said, not an error ;)

Now, I know you have helped me out really much here, but one last thing:
Per now, the script spawns lone units which is good for riot- or "BHD"- type missions.. How would I go about spawning full groups, so that I get groups of people that act together.

Preferably they would have allowfleeing = FALSE, and a new group would spawn when an entire group has been taken out.

But please don't feel you have to answer this - I owe you lots already :)

Cheers
VIKING
Modeller/Skinner/Coder
NORFOR

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Scripting query - Respawn script
« Reply #11 on: 29 May 2007, 17:32:05 »
Instead of reinventing the wheel, I would be tempted to look at the other AI spawn scripts in the Ed Depot(ED). The ED is still under recontruction but you can find a temporary full list of the scripts here. I would recommend one of the spawn manager scripts or adapting snYpir's spawn and random patrol script. The Utility Spawn Scripts by neo inc also look like they would fit your needs.

If you are feeling brave google Silola mapfact DAC and download DAC. It is the most complete AI spawn control package ever made for OFP. There are a lot of parameters but it is very powerful and has a good manual.
« Last Edit: 29 May 2007, 17:35:38 by Mr.Peanut »
urp!

Offline Viking

  • Members
  • *
  • NORSOF
Re: Scripting query - Respawn script
« Reply #12 on: 29 May 2007, 21:05:12 »
Good point ;)

I'll check it out! Thanks again!
VIKING
Modeller/Skinner/Coder
NORFOR