; some definitions have to been made:
; [number of zombies, random factor added to the number, place to spawn, radius, type of zombies, repeats of spawning, time of repetaion, object that is important for the respawn] 
; 
; the number of zombies spawned will be (_this select 0) + random (_this select 1)
; place is an array, i.e. given by getpos...
; radius is a random number that will be added to the location
; type of zombies is listed here: zombietypes=[slowcivs,slowsoldiersW,slowsoldiersE,slowsoldiersR,mummies,fastcivs,fastsoldiersW,fastsoldiersE,fastsoldiersR,mutants,mixedcivs,mixedsoldiersW,mixedsoldiersE,mixedsoldiersR]
; repeats: 1 = one spawn only; 0 = unlimited.... number = number ;)
; time between respawns
; object which if it is defined is the "source" of zombiespawn, so no zombies will respawn anymore, if it is destroyed...)
;
;	exapmle:
; 	[playunitscount,playunitscount,townflag1,50] exec "spawnzombies.sqs" 
; with playunitscount as the number of players you can adjust the difficulty to the number of players 
;
;

; runs only on server:
? !(local server): exit

; ----- define zombietype-arrays: (all on RES-Side) ------------------------------------------------

mixedcivs=["pep_Zfast_man1g","pep_Zfast_man2g","pep_Zfast_man3g","pep_Zfast_man4g","pep_Zfast_man5g","pep_Zfast_man6g","pep_Zfast_man7g","pep_Zfast_copg","pep_Zfast_man8g","pep_Zfast_man9g","pep_Zfast_copg","pep_Zfast_woman1g","pep_Zfast_woman2g","pep_Zfast_woman3g","pep_Zfast_woman4g","pep_Zfast_woman5g","pep_Zfast_Prosituteg","pep_zdogg","pep_Skullheadg","pep_Zslow_man1g","pep_Zslow_man2g","pep_Zslow_man3g","pep_Zslow_man4g","pep_Zslow_man5g","pep_Zslow_man6g","pep_Zslow_man7g","pep_Zslow_copg","pep_Zslow_man8g","pep_Zslow_man9g","pep_Zslow_copg","pep_Zslow_woman1g","pep_Zslow_woman2g","pep_Zslow_woman3g","pep_Zslow_woman4g","pep_Zslow_woman5g","pep_Zslow_Prosituteg","pep_Skullheadg","pep_drtongueg","pep_headlessg","pep_crawlerg"]

mixedsoldiersW=["pep_Zslow_soldierwg","pep_Zslow_soldierwg","pep_Zslow_soldierwg","pep_Zslow_soldierwg","pep_Zslow_soldierwg","pep_Zslow_medicwg","pep_Zslow_medicwg","pep_Zslow_officerwg","pep_Zslow_officerwg","pep_Zslow_crewwg","pep_Zslow_Sniperwg","pep_Zslow_blackopg","pep_Zslow_blackopDg","pep_Zslow_pilotwg","pep_Zfast_soldierwg","pep_Zfast_soldierwg","pep_Zfast_soldierwg","pep_Zfast_soldierwg","pep_Zfast_soldierwg","pep_Zfast_medicwg","pep_Zfast_medicwg","pep_Zfast_officerwg","pep_Zfast_officerwg","pep_Zfast_crewwg","pep_Zfast_Sniperwg","pep_Zfast_blackopg","pep_Zfast_blackopDg","pep_Zfast_pilotwg"]

mixedsoldiersE=["pep_Zslow_soldiereg","pep_Zslow_soldiereg","pep_Zslow_soldiereg","pep_Zslow_soldiereg","pep_Zslow_soldiereg","pep_Zslow_mediceg","pep_Zslow_mediceg","pep_Zslow_officereg","pep_Zslow_officereg","pep_Zslow_crewwg","pep_Zslow_Snipereg","pep_Zslow_piloteg","pep_Zslow_Speznazg","pep_Zfast_soldiereg","pep_Zfast_soldiereg","pep_Zfast_soldiereg","pep_Zfast_soldiereg","pep_Zfast_soldiereg","pep_Zfast_mediceg","pep_Zfast_mediceg","pep_Zfast_officereg","pep_Zfast_officereg","pep_Zfast_crewwg","pep_Zfast_Snipereg","pep_Zfast_piloteg","pep_Zfast_Speznazg"]

mixedsoldiersR=["pep_Zslow_soldiergg","pep_Zslow_soldiergg","pep_Zslow_soldiergg","pep_Zslow_soldiergg","pep_Zslow_soldiergg","pep_Zslow_mediceg","pep_Zslow_mediceg","pep_Zslow_officergg","pep_Zslow_officergg","pep_Zslow_crewgg","pep_Zslow_Snipergg","pep_Zslow_pilotgg","pep_Zfast_soldiergg","pep_Zfast_soldiergg","pep_Zfast_soldiergg","pep_Zfast_soldiergg","pep_Zfast_soldiergg","pep_Zfast_mediceg","pep_Zfast_mediceg","pep_Zfast_officergg","pep_Zfast_officergg","pep_Zfast_crewgg","pep_Zfast_Snipergg","pep_Zfast_pilotgg"]

mummies=["pep_Zstrong1g","pep_Zstrong2g","pep_Zstrong3g","pep_Zstrong4g","pep_Zstrong5g","pep_Zstrong6g","pep_Zstrongfg"]

mutants=["pep_mut1g","pep_mut2g","pep_mut3g","pep_mut4g"]

slowcivs=["pep_Skullheadg","pep_Zslow_man1g","pep_Zslow_man2g","pep_Zslow_man3g","pep_Zslow_man4g","pep_Zslow_man5g","pep_Zslow_man6g","pep_Zslow_man7g","pep_Zslow_copg","pep_Zslow_man8g","pep_Zslow_man9g","pep_Zslow_copg","pep_Zslow_woman1g","pep_Zslow_woman2g","pep_Zslow_woman3g","pep_Zslow_woman4g","pep_Zslow_woman5g","pep_Zslow_Prosituteg","pep_Skullheadg","pep_drtongueg","pep_headlessg","pep_crawlerg"]

slowsoldiersW=["pep_Zslow_soldierwg","pep_Zslow_soldierwg","pep_Zslow_soldierwg","pep_Zslow_soldierwg","pep_Zslow_soldierwg","pep_Zslow_soldierwg","pep_Zslow_medicwg","pep_Zslow_medicwg","pep_Zslow_officerwg","pep_Zslow_officerwg","pep_Zslow_crewwg","pep_Zslow_Sniperwg","pep_Zslow_blackopg","pep_Zslow_blackopDg","pep_Zslow_pilotwg"]

slowsoldiersE=["pep_Zslow_soldiereg","pep_Zslow_soldiereg","pep_Zslow_soldiereg","pep_Zslow_soldiereg","pep_Zslow_soldiereg","pep_Zslow_soldiereg","pep_Zslow_mediceg","pep_Zslow_mediceg","pep_Zslow_officereg","pep_Zslow_officereg","pep_Zslow_crewwg","pep_Zslow_Snipereg","pep_Zslow_piloteg","pep_Zslow_Speznazg"]

slowsoldiersR=["pep_Zslow_soldiergg","pep_Zslow_soldiergg","pep_Zslow_soldiergg","pep_Zslow_soldiergg","pep_Zslow_soldiergg","pep_Zslow_soldiergg","pep_Zslow_mediceg","pep_Zslow_mediceg","pep_Zslow_officergg","pep_Zslow_officergg","pep_Zslow_crewgg","pep_Zslow_Snipergg","pep_Zslow_pilotgg"]

fastcivs=["pep_Zfast_man1g","pep_Zfast_man2g","pep_Zfast_man3g","pep_Zfast_man4g","pep_Zfast_man5g","pep_Zfast_man6g","pep_Zfast_man7g","pep_Zfast_copg","pep_Zfast_man8g","pep_Zfast_man9g","pep_Zfast_copg","pep_Zfast_woman1g","pep_Zfast_woman2g","pep_Zfast_woman3g","pep_Zfast_woman4g","pep_Zfast_woman5g","pep_Zfast_Prosituteg","pep_zdogg"]

fastsoldiersW=["pep_Zfast_soldierwg","pep_Zfast_soldierwg","pep_Zfast_soldierwg","pep_Zfast_soldierwg","pep_Zfast_soldierwg","pep_Zfast_soldierwg","pep_Zfast_medicwg","pep_Zfast_medicwg","pep_Zfast_officerwg","pep_Zfast_officerwg","pep_Zfast_crewwg","pep_Zfast_Sniperwg","pep_Zfast_blackopg","pep_Zfast_blackopDg","pep_Zfast_pilotwg"]

fastsoldiersE=["pep_Zfast_soldiereg","pep_Zfast_soldiereg","pep_Zfast_soldiereg","pep_Zfast_soldiereg","pep_Zfast_soldiereg","pep_Zfast_soldiereg","pep_Zfast_mediceg","pep_Zfast_mediceg","pep_Zfast_officereg","pep_Zfast_officereg","pep_Zfast_crewwg","pep_Zfast_Snipereg","pep_Zfast_piloteg","pep_Zfast_Speznazg"]

fastsoldiersR=["pep_Zfast_soldiergg","pep_Zfast_soldiergg","pep_Zfast_soldiergg","pep_Zfast_soldiergg","pep_Zfast_soldiergg","pep_Zfast_soldiergg","pep_Zfast_mediceg","pep_Zfast_mediceg","pep_Zfast_officergg","pep_Zfast_officergg","pep_Zfast_crewgg","pep_Zfast_Snipergg","pep_Zfast_pilotgg"]


zombietypes=[mixedcivs,mixedsoldiersW,mixedsoldiersE,mixedsoldiersR,mummies,mutants,slowcivs,slowsoldiersW,slowsoldiersE,slowsoldiersR,fastcivs,fastsoldiersW,fastsoldiersE,fastsoldiersR]


@ gblInitDone == 1

; ------------------------------------------------------------------------------------

_number = _this select 0
_factor = _this select 1
_place = _this select 2
_radius = _this select 3
_type = _this select 4
_spawncount = _this select 5
_periode = _this select 6
_object = _this select 7

;hint format ["array=\nnumer: %1\nfactor: %2\nplace: %3\nradius: %4\ntype: %5\nspawncount: %6\nperiode: %7\nobject: %8",_number,_factor,_place,_radius,_type,_spawncount,_periode,_object]

~2

;? (_radius == "scalar bool array string 0xfcffffef"): _radius = 0;
;? (_type == "scalar bool array string 0xfcffffef"): _type = mixedcivs;
;? (_spawncount == "scalar bool array string 0xfcffffef"): _spawncount = 0;
;? (_periode == "scalar bool array string 0xfcffffef"): _periode = 0;
;? (_object == "scalar bool array string 0xfcffffef"): _object = objNull;

;~5

;hint format ["array=\n0: %1\n1: %2\n2: %3\n3: %4\n4: %5\n5: %6\n6: %7\n7: %8",_number,_factor,_place,_radius,_type,_spawncount,_periode,_object]


_xplus = 0
_yplus = 0
_plusminusx = 0


#newspawn
_zcount = (_number) + random ((_factor*2))



#spawnloop

; get spawnpos:

	? (_radius>1): _xplus = random _radius; _yplus = random _radius; _plusminusx = random 2; _plusminusy = random 2; if (_plusminusx>1) then {_xplus=-_xplus}; if (_plusminusy>1) then {_yplus=-_yplus}; 

	_spawnpos = [(getpos _place select 0)+_xplus,(getpos _place select 1)+_yplus,(getpos _place select 2)]


; Type of Zombie:
	_ztype = zombietypes select _type
	_tcount = count _ztype
	_rantype = random (_tcount-1)
	_rantype = _rantype - (_rantype) mod 1
	_zombie = _ztype select _rantype	

;hint format ["ztype=%1\ntype=%2\ntcount=%3\nrantype=%4\nzombie=%5\nzcount=%6\nspawncount=%7",_ztype,_type,_tcount,_rantype,_zombie,_zcount,_spawncount]


#reducegroup

? (count units group zdummy >10): _newgroupz=((units group zdummy) select 1); [_newgroupz] join grpNull; "[_x] join _newgroupz" foreach units group zdummy; [zdummy] join grpNull;
_zombie createUnit [_spawnpos,group zdummy];


_zcount = _zcount -1

~0.75
? ( _zcount > 0 ): goto "spawnloop"


#repetition

	? (!(isNull _object) AND !(alive _object)): exit; 
	? (_spawncount<0): goto "wait"

	_spawncount =_spawncount-1
	? (_spawncount==0): exit
	
	
#wait

~_periode

? (!(isNull _object) AND !(alive _object)): exit;  

goto "newspawn"




