
; Create new unit


	_item = _this
	_property = _item call findProperty
	_class = (_property select 3) + "_" + MYSIDE
	
	_i=0
	#FindBuilding
	? typeOf (BUILT select _i) == "STGNdunebarracks" : goto "Place"
	? _i < count BUILT - 1 : _i=_i+1; goto "FindBuilding"
	player groupchat "error: no barracks"
	exit
	
	
	#Place
	_building = BUILT select _i
	
	_dir = random 360
	? (_property select 3) == "WW4dune_hinf" : _dir=180
	_x = 8 * (sin (_dir)) + (getpos _building select 0)
	_y = 8 * (cos (_dir)) + (getpos _building select 1)
	_z = 0
	
	_group = REDspawn
	? MYSIDEVAR == West : _group = BLUEspawn
	
	_class createUnit [[_x,_y,_z],  _group, "TRAINED=TRAINED+[this]", 1, "PRIVATE"]
	_newGuy = TRAINED select (count TRAINED - 1)
	[_newGuy] join grpnull
	
	? "dune_M16" in weapons _newGuy : _newGuy exec "Unit\Guard.sqs"
	
	_newGuy setUnitPos "UP"
	_newGuy setSpeedMode "FULL"
	_newGuy setSkill 1
	_newGuy setCombatMode "BLUE"
	_newGuy setBehaviour "AWARE"
	_newGuy addeventhandler ["killed", {playSound "scream"}]
	_newGuy exec "Unit\Blood.sqs"
	_newGuy exec "Unit\Magazines.sqs"
	
	COMMANDS = COMMANDS + [0]
	
	_logic = "logic" camCreate [0,0,0]
	WAYPOINTS = WAYPOINTS + [_logic]
	
	
	@!alive _newGuy
	_id = _newGuy call findID
	COMMANDS set [_id, "null"]
	COMMANDS = COMMANDS - ["null"]
	WAYPOINTS set [_id, "null"]
	WAYPOINTS = WAYPOINTS - ["null"]	
	TRAINED = TRAINED - [_newGuy]
	
	
	
	

	
	
