Home   Help Search Login Register  

Author Topic: Could Viking, M21mans, Hater_Kint or anyone explain this script plz  (Read 573 times)

0 Members and 1 Guest are viewing this topic.

RAWR

  • Guest
Hiya I found this script after searching through older topics and im just wondering how to make it work in a mission, im no scripting genius :)
Here is the script :
respawn.sqs
Code: [Select]
_aUnit = _this select 0
_agroups = _this select 1
_apg = _this select 2
_utype = _this select 3
_askill = _this select 4
_aradius = _this select 5


_c = 0
#loop
  #gloop
      _rg = count units (_agroups select _c)
      ? _rg >= _apg : goto "misscreate"
      _rg = _apg - _rg
      #iloop
        _rnum = random ((_aradius * 2))
        _num = _rnum - (_rnum mod 1)
        _num = _num - _aradius
        _d1 = getpos _aunit select 0
        _d2 = getpos _aunit select 1
        _d3 = 0
        _qs = (_aradius * _aradius) - (_num * _num)
        _qs = sqrt _qs
        _num2 = random (2)
        _num2 = _num2 - (_num2 mod 1)
        ? _num2 == 0 : _qs = _qs - (2 * _qs)
        _num2 = random (2)
        _num2 = _num2 - (_num2 mod 1)


        ? _num2 == 0 : _d1 = _d1 + _num; _d2 = _d2 + _qs
        ? _num2 == 1 : _d1 = _d1 + _qs; _d2 = _d2 + _num
        _utype createunit [_d1,_d2,_d3],_agroups select _c,"",_askill,"PRIVATE"];
        _agroups select _c move getpos _aunit
        "_x addeventhandler [{killed},{_this exec {killdelete.sqs}}]" foreach units (_agroups select _c)
        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
  ~5
goto "loop"

and

killdelete.sqs
Code: [Select]
_guy = _this select 0
~40
deletevehicle _guy

Any help would be appreciated as this is pretty much the only script on here that I can find thats useful for what im trying to do - which is a defend the chopper mission same as Viking was doing.

Cheers.

Kammak

  • Guest
I'm an "or anyone" so I'll give it a try! :)

First the params:

_aUnit - I'm guessing this is the unit under attack - its where everyone created gets moved to, and around which they are created

_agroups - Is an array of groups that the script will populate and monitor

_apg - Is the number of units that are to be in each group

_utype - Is the type of unit that should be in the groups

_askill - Is the skill level of any newly created unit

_aradius - Is how far away (maximum) new units will be created from the guy passed as _aunit, which I'm guessing is the target object/guy.


The script then runs every five seconds, sees if each group has the correct number of units; if not, it creates a new unit for the group and figures out where to place him.  If adds an event handler to each created guy that will remove him from the map 40 seconds after death.

Each new guy is created as a "Private" in rank, of the type _utype, with skill level _askill.


If I'm wrong on any part please correct me!







RAWR

  • Guest
Ah well that definately sheds some light on things.  Thankyou.  So would I execute this script on every unit that needs to be respawned or just on a group leader?

Cheers  8)

Kammak

  • Guest
The second parameter is an array of groups, so you can pass any number of groups in one call - so no you don't need to call it for every member or even every group!  Just call it once and pass every group that you want to respawn (in the second param).

An example call:

[hPlayer,[groupA,groupB,groupC,groupD],12,"SuchRrifle",0.5,100] exec *scriptname*


This would keep four groups at 12 guys each, with Russian Rifleman from Digital Grenades Marine Assault Pack, with a skill of 0.5, creating replacements within 100 meters of the guy hPlayer.

Every five seconds it would create as many new Russian Riflemen as needed to keep all 4 groups at 12 men each, and send them moving towards wherever hPlayer is located.  You can include as many group as necessary in the second parameter.

RAWR

  • Guest
Ah thankyou kindly sir, you rock!  ;D

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Ah..

Me so late... :P
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.